Hi all.
Wouldn't this code Dim strIn as a variant?Thanks.Code:Dim strIn, strOut As String
Printable View
Hi all.
Wouldn't this code Dim strIn as a variant?Thanks.Code:Dim strIn, strOut As String
Yes, it will.
NO
Simply because it is contained in the one dim statement
Dim strIn
that makes it a variant
Dim strIn,strOut as string
that makes it a string
Yes, it will :)
So,
I've received 2 yes's and 1 no! Will someone please give a definitive answer?
Thanks.
*** comment about posting incorrect replies removed by seaweed because it just seemed too harsh! ***
If you dim variables with one dim statement, you still must explicitly define the type of each variable in the list. Those that are not explicitly defined will be Variants.
Here's an easy way to test it. Dim two variables, but only declare the type of the last one. Then try to set each variable to data of another type.
Guess which variable causes the type mismatch error when you run this:
Of course it's the second variable, because the first one was automatically typed as a Variant by VB.Code:Option Explicit
Private Sub Form_Load()
Dim var1, var2 As Integer
var1 = "Hello"
var2 = "Hello"
Unload Me
End Sub
[Edited by seaweed on 07-01-2000 at 03:36 AM]
seaweed:
I actually thought I was right!!!!
If I though I was wrong I wouldn't have posted it.
I was wrong..I was mistaken... I accept that...I am sorry!
Life goes on!
I've done it before too.
HeSaidJoe, don't worry, we all do that sometimes :)
I've seen your posts lately very helpful to people, good work! You might get guru one day ;)
thank you...guru isn't the reason I play here..
I learn more by trying to help others that I did
in 8 night semesters of VB4,5,6
Actually, it was one of the teachers as night school
who said that if you wanted to declare 6 variables
as string just do Dim 1,2,3,4,5,6 as string..
obviously....she was wrong.
All the best,
Wayne
Until today I thought that putting multiple variables on one dim line meant that they were all the same also. I tested it and found out that it was not so.
One of my professors was wrong also it seems
To everyone for your input.
It seems that VB teachers can't be trusted! :D Except the "teachers" who frequent this Forum of course.
All the best.