Results 1 to 19 of 19

Thread: one line assignment [solved]

  1. #1

    Thread Starter
    Lively Member ayan's Avatar
    Join Date
    Jan 2004
    Posts
    112

    one line assignment [solved]

    halu,

    i'm kinda confuse about one line initialization... this gives me a "not i want" output...
    VB Code:
    1. cmbCategoryStatus.Text = cmbMakersStatus.Text = String.Empty
    is there a bug? i really don't know... it doesn't clear at all. it just clears the cmbMakersStatus and put "True" to cmbCategoryStatus.Text. is this supported in VB.NET -- the one line initialization?

    it also has no effect with integers either... like
    VB Code:
    1. i=j=0
    just want to clarify if VB supports this kind of initialization...

    thanx
    Last edited by ayan; Feb 4th, 2004 at 12:54 AM.

  2. #2

    Thread Starter
    Lively Member ayan's Avatar
    Join Date
    Jan 2004
    Posts
    112
    halu,

    i guess VB.net doesn't support what i want. i queried this on msdn abot operators
    Used to assign a value to a variable or property.

    variable = value
    Parts
    variable
    Any variable or any writable property.
    value
    Any literal, constant, or expression.
    Remarks
    The name on the left side of the equal sign can be a simple scalar variable, a property, or an element of an array. Properties on the left side of the equal sign can only be those properties that are writable at run time. When used, the value on the right side of the equation is assigned to the variable on the left side of the equation.

    Example
    This example demonstrates use of the assignment operator. The value on the right side of the expression is assigned to the variable on the left side of the expression.

    Dim myInt as Integer
    Dim myString as String
    Dim myButton as System.Windows.Forms.Button
    Dim myObject as Object
    myInt = 42
    myString = "This is an example of a string literal"
    myButton = New System.Windows.Forms.Button()
    myObject = myInt
    myObject = myString
    myObject = myButton
    examples only categorize about one variable to be assigned to one variable... i don't know... some ideas are still welcome...

    thanx

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Neither of those lines initialize anything they just assign things. An example of one line initializing would be:
    VB Code:
    1. Dim str As String="I'm Initialized!"
    2.  
    3. 'instead of
    4. Dim str As String
    5. str="I'm Initialized!"

    What is it you are trying to do?

  4. #4

    Thread Starter
    Lively Member ayan's Avatar
    Join Date
    Jan 2004
    Posts
    112
    ooops, sorry wrong word used... what i meant is assignment. is there any way of one assignment...

    like the one i post earlier... i=j=0

    sorry... is this supported in VB? like the ones in java or c...

    thanx very much...

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    No I'm afraid it's not. What is the purpose of that in Java? OR is it just a handy shortcut?

  6. #6

    Thread Starter
    Lively Member ayan's Avatar
    Join Date
    Jan 2004
    Posts
    112
    sort of... i'm a newbie though. hehe. but i encounter this in java or c. like assignment of i and j on a single line. we would normally do that. like i=j=0. just wondering if it's possible in vb but thanx for the information. i even search msdn and no luck at all. i would like to assign two combo boxes' text a string empty.

    i guess i found the answer right now. thanx Edneeis...

    thanx times ten to the power of forever...

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    C# perfectly accept this kind of assignment .

    But if you want to set any property for similar controls on your form , then use this code for example to clear the text in all the comboboxes on your form .
    VB Code:
    1. Dim CBox As Control
    2.         For Each CBox In Me.Controls
    3.             If TypeOf CBox Is ComboBox Then
    4.               CBox.Text = String.Empty
    5.    End If
    6. Next

  8. #8

    Thread Starter
    Lively Member ayan's Avatar
    Join Date
    Jan 2004
    Posts
    112
    halu,

    thanx, so much... i tried that... that works man. very well...

    thanx times ten to the power of forever...

    --ayan

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I don't think you can do that in C#. He means:
    VB Code:
    1. TextBox1.Text=TextBox2.Text=String.Empty

  10. #10
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Edneeis
    I don't think you can do that in C#. He means:
    VB Code:
    1. TextBox1.Text=TextBox2.Text=String.Empty
    Did you try it Ed ?

  11. #11
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    See here :
    Attached Images Attached Images  

  12. #12
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    And that assigns String.Empty to both textboxes? If so that's cool I didn't realize you could do that in C#. Right on Pirate!

  13. #13
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I love C#.

  14. #14
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    It compiles but doesn't work as expected in VB. It is interepted as textBox1.Text=(TextBox2.Text=String.Empty) and makes the text for textbox1 =False.

  15. #15

    Thread Starter
    Lively Member ayan's Avatar
    Join Date
    Jan 2004
    Posts
    112
    i tried doing C# the first time of my life. gosh.... i'm kinda newbie though... it works with me
    Code:
    		private void button1_Click(object sender, System.EventArgs e)
    		{
    			textBox1.Text=textBox2.Text=string.Empty;
    		}
    thanx to all... hehehe..

  16. #16
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by ayan
    i tried doing C# the first time of my life. gosh.... i'm kinda newbie though... it works with me
    This proves C# isn't VB , It's the little son of C/C++ . .....

  17. #17
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I read that C# was really intended to help people adapt from Java to .NET so really I guess it makes sense that it can be done there since it can be dnoe in Java.

    Just my 2 cents.

  18. #18
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Could be true but I'd stop at this point and agrue no more since this topic would drive this thread crazy lol .

  19. #19

    Thread Starter
    Lively Member ayan's Avatar
    Join Date
    Jan 2004
    Posts
    112
    yezzz. kinda wondering that before but just asking if it's in VB. so now, i learn something... i tried C, Java before but just basics. anywayz, thanx to all of you guys... thank you thank you...

    that's times ten to the power of forever...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width