General discussion

Locked

Need Help with VBA

By Reuroo ·
How do I get an IF function to work with several possibilities (i.e. 40)? I want to be able to do this in VB, HELP?

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

need more info..

by ARG CIO In reply to Need Help with VBA

If
a=1 or b=2...AN=40 then goto true
else goto get_input
end if

or you need 40 if statements;

If
input = 1 then goto answer_1
end if
If
input =2 then goto answer_2
end if
...
if
input = 40 then goto answer_40
ELSE goto incorrect_input
end if

otherwise, If may not be the route to go..

getit:
get input$(input_value)

If
input$ <> "" then goto input$
else goto getit
end if

1:
do this
exit
2:
do that
exit
....
40:
do the other thing
exit
I am not an expert VB programmer, but am familiar with it. If there is another way, I'd like to hear it.. hope this helps, good luck, and let me know.

Collapse -

Nested If

by chris.bianchi In reply to need more info..

You could use any of these examples or the nested if (if you would like to test against multiple arguments). Here's an example:

If x = 4 Then
y = y + x
ElseIf x = 5 Then
y = y - x + 1
ElseIf x = 6 Then
y = y - x
:
:
End If
-- or --

If x = 4 Then
x = x + 1
Else
If x = 5 Then
x = x - 1
Else
x = x - 2
End If
End If

Collapse -

Select Case

by ryan In reply to Nested If

You can use the select case statement. An example is bellow. The first Line just tells the program what it is testing, in relation to an ?if statement? it would be the ?If X=? part. The second line would be the value x should equal. The third line would be the code to run if that statement was true. Your next line being another case or value for x to equal... Hope that helps some.

Select Case X
Case "John"
' Code to run goes here
Case "Ryan"
' Code to run goes here
End Select

Back to IT Employment Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums