Visual Basic HELP

IceT

Senior member
Aug 14, 2000
320
0
0
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.
 

Train

Lifer
Jun 22, 2000
13,587
82
91
www.bing.com
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
 

IceT

Senior member
Aug 14, 2000
320
0
0
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.
 

jmcoreymv

Diamond Member
Oct 9, 1999
4,264
0
0
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.
 

IceT

Senior member
Aug 14, 2000
320
0
0
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?
 

anton

Banned
Sep 15, 2000
746
0
0
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 ...
 

IceT

Senior member
Aug 14, 2000
320
0
0
Oh good, I think I get it......I am gonna get a VB book too this weekend....Thanks guys.
 

IceT

Senior member
Aug 14, 2000
320
0
0
I tried to indent my work but the forum took out tab and spaces as what Train said earlier.