Talk:Visual Basic/The Language

Most of the content of this pages (all of conditionals) has been split and moved to Branching and Loops. Turn this page into an appendix linked from the Programming table.

Vandalism
66.66.38.185 vandalised this page over and over again.

Probably simplest to delete the page. --kwhitefoot 11:00, 13 October 2005 (UTC)

Multiple variables in one Dim statment defaults to variant?
The text suggests that "Dim anumber, anothernumber, yetanothernumber As Integer" would cause anumber, anothernumber to be declared as variants (something I used to believe as well). As far as a I can see from Microsoft documentation this is not so (I would have quoted it, but I guess that might not be allowed). The examples given, also demonstrate that is is a valid way of typing multiple variables. The documentation was found here: http://msdn2.microsoft.com/en-us/library/7ee5a7s1.aspx (look in Data Type Rules, last bullet before the second code block). -- Baard


 * I'm afraid you have been misled by Microsoft's obfuscatory methods of writing documentation. The document you refer to treats VB.NET not VB Classic.  Microsoft appear to be suppressing the documentation for VB Classic in the hope that it will go away.  You can demonstrate what actually happens by this little program:

Option Explicit Public Sub main Dim anumber, anothernumber, yetanothernumber As Integer Dim v As Variant Debug.Print TypeName(anumber), VarType(anumber), _ TypeName(anothernumber), VarType(anothernumber), _ TypeName(yetanothernumber), VarType(yetanothernumber) Debug.Print TypeName(anumber), VarType(v) Debug.Print "Assign a number to anumber" anumber = 1 Debug.Print TypeName(anumber), VarType(anumber) Debug.Print "Assign a string to anumber" anumber = "a string" Debug.Print TypeName(anumber), VarType(anumber) End Sub

The result is:

Empty         0            Empty          0            Integer        2 Empty         0 Assign a number to anumber Integer       2 Assign a string to anumber String        8

Notice that both VarType and TypeName return information about the variable stored inside the Variant not the Variant itself.

Thanks for the comment, it drove me to add an explanatory piece of code to the page. Don't hesitate to add more comments, questions, improvements and so on. Welcome to Wikibooks! --kwhitefoot 07:26, 22 May 2006 (UTC)


 * Thank you for the example. Most of the time I’m fairly happy with Microsoft’s documentation practices, but I have to agree with you that it didn’t come across too clearly that it was a question of VB .Net in this instance.


 * When I searched msdn for the Dim statement, I got several hits (of cource). Hit 2 and 3 had the following titles “Dim Statement (Visual Basic .NET)” and ”Dim Statement (Visual Basic)”. As I chose the latter one I felt quite confident that it was not the .Net version.
 * --Baard 17:53, 22 May 2006 (UTC)