• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Visual Basic HELP

IceT

Senior member
OK, I am a newbie in VB and I am so confused on the "CASE" statments! How exactly do I use it?

BTW, a few easy examples would be appreciated🙂

Thank you.
 
case is like an IF except you have a lot more options, its kind of like a list of options



<<
Select Case TextBox1.Text
Case &quot;Joe&quot;
'do something here
Case &quot;Bob&quot;
'do something else here
Case &quot;Ann&quot;
'other stuff
Case Else
'this one called when no options left
End Select
>>



sorry it doesnt look good, the forums take out tabs and spaces
 
OK, Train, I need more explaination:

&quot;Select Case TextBox1.Text&quot;

Why do u put the TextBox1.Text there? What am I suppose to put to start a new case statement?

Thanks.
 
I believe (although i havent used vb in a few years), as Trains code shows
Select Case <expression>
End Select
Are the lines to start and stop a case.
TextBox1.Text is just there as an example, what it does is take the text that is in the object called TextBox1 and see if it matches any of the case statements, if it does, it will execute that case statement.
 
OK, so let me ask u guys this:


Dim r as String
r=InputBox (&quot;Please enter a number&quot;, &quot;Enter a number.&quot😉
Select Case r
Case val(1)
End
Case val(2)
Unload Form1
Form1.Show
End Select


So for the above program, does it mean that I am taking the value inputed by the user (r) and then ask the program to convert the string into number so that the program can check what to do?
 
first I don't get why you have VAL(1) ... it can be just 1 ...

ok .. now I see .... it must be VAL(r) ... and not just r ...


And for your question ... yes , it converts it to the number , and to see , what it needs to do ...
 
Back
Top