Trying to find the MSDN Qnnnn article for this question 
Author Message
 Trying to find the MSDN Qnnnn article for this question

Why looking for a KB article?
From the help-file (VB5):

Syntax:
    Dim [WithEvents] varname[([subscripts])] [As [New] type] [, [WithEvents]
varname[([subscripts])] [As [New] type]] . . .

which shows that you can declare more than one variable with one Dim
statement. You have to separate each declaration with a , (comma) and each
declaration has the syntax:
    [WithEvents] varname[([subscripts])] [As [New] type]

In your example
    Dim a, b, c, d As Integer
you declare the first three variables (a, b and c), leaving all the optional
parts, you define the variables with the default values: no events, not an
array and the default type: Variant.

Look at one of the remarks:
If you don't specify a data type or object type, and there is no Deftype
statement in the module, the variable is Variant by default.

So:
    Dim a, b, c, d As Integer
is the same as:
    Dim a As Variant, b As Variant, c As Variant, d As Integer
but I prefer:
    Dim a As Variant
    Dim b As Variant
    Dim c As Variant
    Dim d As Integer

Hope it makes sense,
Johan.



Quote:
> I know this question has been asked before. I did try a Google search
> for it, maybe using the wrong key words.

> The question is simple enough.

>      Dim a, b, c, d As Integer

> It is wrong, but why?

> What does (a) become, (b) become, (c) become and (d) become?

> I know it has something to do the first is not the same as the second
> and so forth - (a, b, c, and d will not all be Integers)

> The way it should be done is something like this:

>    Dim a As Integer, b As Integer, c As Integer, d As Integer

> I'm looking for a KB article for an explanation, or one from you guys,
> so that I can try and drum some sort of understanding into my thick
> skull.

> Cheers
> Roders

> Warning: Only the brave of heart should go here.
> http://www.*-*-*.com/



Wed, 18 Feb 2004 05:08:01 GMT  
 Trying to find the MSDN Qnnnn article for this question
If Johan's explanation was confusing, maybe this one won't be:

When you declare multiple variables in a single Dim statement, each one must
have it's own "As ... " clause to be declared of a specific type.  If any one
or more variables DO NOT have their own "As ..." clause, they are declared as
Variant by default.

Lee Weiner
lee DOT weiner AT home DOT com
http://members.home.net/lee.weiner


Quote:

>On Fri, 31 Aug 2001 23:08:01 +0200, "Johan Bechthum"

>Many thanks for your reply Johan.

>Your explanation is - sort of confusing - and by no means unworthy!

>>Why looking for a KB article?
>>From the help-file (VB5):

>>Syntax:
>>    Dim [WithEvents] varname[([subscripts])] [As [New] type] [, [WithEvents]
>>varname[([subscripts])] [As [New] type]] . . .

>>which shows that you can declare more than one variable with one Dim
>>statement. You have to separate each declaration with a , (comma) and each
>>declaration has the syntax:
>>    [WithEvents] varname[([subscripts])] [As [New] type]

>Here I have hit many a problem when the author has not used Option
>Explicit and then used my (wrong) example.

>>In your example
>>    Dim a, b, c, d As Integer
>>you declare the first three variables (a, b and c), leaving all the optional
>>parts, you define the variables with the default values: no events, not an
>>array and the default type: Variant.

>Ah! Okay, this rings a bell. - So the first three are variables and
>the last would be an Integer, is that correct?

>>Look at one of the remarks:
>>If you don't specify a data type or object type, and there is no Deftype
>>statement in the module, the variable is Variant by default.

>VB5, VB6 help [MSDN] files should be very much the same Johan. Would
>you mind posting a few pointers as how you found and explained your
>answer to my posting? I'm sure there are many more like me who would
>benefit from your response.

>>Hope it makes sense,

>In a sense, it did - Thanks Johan.

>Cheers
>Roders

>Warning: Only the brave of heart should go here.
>http://www.mjvn.co.za/rodcom



Wed, 18 Feb 2004 07:23:30 GMT  
 Trying to find the MSDN Qnnnn article for this question
Roders, what Lee wrote is the bottom line of the story. :-)



Quote:
> On Fri, 31 Aug 2001 23:08:01 +0200, "Johan Bechthum"

> Many thanks for your reply Johan.

> Your explanation is - sort of confusing - and by no means unworthy!

> >Why looking for a KB article?
> >From the help-file (VB5):

> >Syntax:
> >    Dim [WithEvents] varname[([subscripts])] [As [New] type] [,
[WithEvents]
> >varname[([subscripts])] [As [New] type]] . . .

> >which shows that you can declare more than one variable with one Dim
> >statement. You have to separate each declaration with a , (comma) and
each
> >declaration has the syntax:
> >    [WithEvents] varname[([subscripts])] [As [New] type]

> Here I have hit many a problem when the author has not used Option
> Explicit and then used my (wrong) example.

Any author should use Option Explicit !
If it isn't there, write it there and take the time to dimention all the
variables in the right way. This may prvent you from stange problems.

Quote:
> >In your example
> >    Dim a, b, c, d As Integer
> >you declare the first three variables (a, b and c), leaving all the
optional
> >parts, you define the variables with the default values: no events, not
an
> >array and the default type: Variant.

> Ah! Okay, this rings a bell. - So the first three are variables and
> the last would be an Integer, is that correct?

Not quite. All the four are _variables_, but the first three are *Variants*
and the fourth is an Integer

Quote:
> >Look at one of the remarks:
> >If you don't specify a data type or object type, and there is no Deftype
> >statement in the module, the variable is Variant by default.

> VB5, VB6 help [MSDN] files should be very much the same Johan. Would
> you mind posting a few pointers as how you found and explained your
> answer to my posting? I'm sure there are many more like me who would
> benefit from your response.

Pointer to the VB help:
Position the cursor on the keyword you want help about and press F1.

Pointer to the MSDN files:
http://msdn.microsoft.com/library/default.asp

Quote:
> >Hope it makes sense,

> In a sense, it did - Thanks Johan.

I'm glad I'd was of some help,
Johan.

- Show quoted text -

Quote:

> Cheers
> Roders

> Warning: Only the brave of heart should go here.
> http://www.mjvn.co.za/rodcom



Thu, 19 Feb 2004 05:15:26 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Announce: Windows Media Player control article on MSDN

2. Announce: Windows Media Player control article on MSDN

3. MSDN article - Death of the Browser

4. New article on porting ASP pages to ASP .NET available on MSDN

5. Print MSDN articles exceeds printed page width

6. MSDN Articles

7. Can't read articles (MSDN) on the web

8. MSDN Articles

9. MSDN-CD article 67 - Resetting Focus after WinHelp

10. Tech Articles on (new) MSDN CD

11. Tech Articles on (new) MSDN CD - Microsoft Responds

12. Can't get into MS articles (MSDN on the web)

 

 
Powered by phpBB® Forum Software