ok this sounds dumb but i just wanted to do something simple
doesn't work, is there a way to do this in vb?Code:dim this, that, alll, duno, etc, anddd, more as integer
this = that = etc = more = 6
Printable View
ok this sounds dumb but i just wanted to do something simple
doesn't work, is there a way to do this in vb?Code:dim this, that, alll, duno, etc, anddd, more as integer
this = that = etc = more = 6
Nope. Plus, in the DIM statement, only more is an Integer. Everything in RED is actually a VARIANT, and slower to use.
Declare each variable's type. You can include multiple per statement.
Assigning a value to more than one item isn't allowed.
Code:Dim this as Integer, that as Integer, etc as Integer
this = 6 : that = 6 : etc = 6 : more = 6
Doing this :
Would give me 5Code:Dim this As Integer, that As Integer, alll As Integer, duno As Integer, etc As Integer, anddd As Integer, more As Integer
more = 6
etc = 7
that = 5
this = that = etc = more
MsgBox that
Doing this :
Would give 0Code:Private Sub Form_Load()
Dim this As Integer, that As Integer, alll As Integer, duno As Integer, etc As Integer, anddd As Integer, more As Integer
more = 6
etc = 7
that = 5
that = etc = more
MsgBox this
End Sub
An expression A=B=C will evaluate like this:
A is assigned the result of B=C, which is a boolean expression like in the if statement.
If B equals C then A will become True, if B is different to C, A becomes False.
If A however is not a boolean, but an integer, it becomes -1 for true and 0 for false.
A multi assignment statement will likewise evaluate:
A=B=C=D=6.
If all variables are assumed 0, then D=6 will be false, so we have
A=B=C=0
C is 0 will be true, being -1 in an integer representation, so we have
A=B=-1
So B=-1 becomes 0 (false) for B being 0. This reduces the evaluation to
A=0
That's what the result should turn out.
The whole point I'm still trying to figure out as well, is why is this even allowed in the compiler. Surely it should be ¿
[Moved to VB.NET]
Sorry about bumping the thread, but OP is actually asking a question related to VB.NET. I have moved few of the threads to VB.NET forum earlier that were posted by the same member.
So in vb.net dim this, that, alll, duno, etc, anddd, more as integer would declare all of them as integers.
hey sry what exactly is the difference between vb and vb.net?
im using microsoft visual basic 2008, is that vb.net?
Yes, that is VB.NET, in this case
This :
http://www.codeguru.com/forum/forumdisplay.php?f=12
Is the VB.NET Forum.
Where you posted was for VB 6, mainly :)
Hannes, the thread is already moved to VB.NET :) (Post #6)
The reason it is allowed is because it is correct syntax.
As WoF explains, VB.NET (possible VB as well?) treat the = after the first assignment as boolean comparisons and not as assignments.
It is a syntax silliness in my book doing nothing but add confusion, but it is perfectly legal VB.NET syntax.
what's the difference between vb 6 and vb.net? is vb.net a new version of vb6?
There are a lot of articles in internet about the difference between vb6 and vb.net.
Check this link
http://www.thescarms.com/vbasic/vb6vsvbnet.aspx
To explain why is the syntax A=B=C is logically allowed:
It is simply to store the result of a comparison.
B=C, when used as a term, is a boolean expression which evaluates to true or false. (Or will be treated as-1 and 0, if the other terms are numerical).
A=B=C replaces the statement If B=C Then A=True Else A=False
Likewise you can do A=B>C or A=B<=C to keep results of comparisons in A.
A=B=C=D must therefore be syntactically correct, although it does not make much sense.
I use this kind of conditional often when having to switch an array of controls on and off.
Say you have an array of 10 checkboxes and you want box 0 to 4 enabled, box 5 to 9 disabled, not knowing what their current state is.
Code:For i=0 to 9
chkBox(i).Enabled = i<5
Next