If + ElseIf

You can talk about VB programming here

If + ElseIf

Postby jekar » Sat Nov 04, 2006 12:38 pm


GUYZ , I GOT A CODE SAYING :

If Operator = "+" Then

Result = Operand1 + Operand2

ElseIf Operator = "-" Then

Result = Operand1 - Operand2

End If

SO MY QUESTION IZ CAN I SAY :

If Operator = "+" Then

Result = Operand1 + Operand2

If Operator = "-" Then

Result = Operand1 - Operand2

End If
jekar
imFiles Newbie
imFiles Newbie
 
Posts: 33
Joined: Sat May 28, 2005 8:22 pm

Postby Ghost » Sat Nov 04, 2006 2:35 pm

no, but you could make it say
Code: Select all
If Operator = "+" Then

Result = Operand1 + Operand2

End If 'note how you closed this If tag first

If Operator = "-" Then 'and then this one starts a new If tag

Result = Operand1 - Operand2

End If
Ghost
 

Postby BattleStar-Galactica » Sun Nov 05, 2006 11:05 am

ofcause you can do that but nobody codes like that.


the elseif exist for the reason if the first if is true the elseif will not be validated

when there are alot of if and elseif we use select case
Big math problem
2 - 1 = 0 = without you I'm nothing
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby Departure » Tue Nov 07, 2006 2:02 am

assuming that - and + are the only two variables you could do it like this


If Operator = "+" Then
Result = Operand1 + Operand2
Else
Result = Operand1 - Operand2
End If
User avatar
Departure
Global Moderator
Global Moderator
 
Posts: 996
Joined: Thu Mar 17, 2005 11:26 am
Location: Australia


Return to Visual Basic Programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron