|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
My third variable will not gain the value of the equation, when opt 2 or 3 is selected. Can someone help please...
It's just an example of what I want to achieve. Code ---------------------------------- Code:
Private Sub Command1_Click()
Dim g1 As Variant
Dim g2 As Variant
Dim g3 As Variant
g2 = val1.Text
g3 = val2.Text
If Opt1.Value = 1 Then
If Op4.Value = 1 Then
g1 = g2 / g3
ElseIf Op5.Value = 1 Then
g1 = g2 + g3
ElseIf Op6.Value = 1 Then
g1 = g2 - g3
ElseIf Opt2.Value = 1 Then
If Op4.Value = 1 Then
g1 = g2 / g3
ElseIf Op5.Value = 1 Then
g1 = g2 + g3
ElseIf Op6.Value = 1 Then
g1 = g2 - g3
ElseIf Opt3.Value = 1 Then
If Op4.Value = 1 Then
g1 = g2 / g3
ElseIf Op5.Value = 1 Then
g1 = g2 + g3
ElseIf Op6.Value = 1 Then
g1 = g2 - g3
Else
MsgBox "Done"
End If
End If
End If
End If
Res.Text = g1
End Sub
Last edited by Onslaught : September 27th, 2003 at 11:21 AM. |
|
#2
|
|||
|
|||
|
u can post your full code to us for help u??
|
|
#3
|
|||
|
|||
|
Mig, try using the [ code ] .. [ /code ] or [ php ] .. [ /php ] forum codes (without the spaces) to preserve spacing and indenting in your code. It's hard to follow when there are no indents.
|
|
#4
|
||||
|
||||
|
I added code tags around your code so that we can see the indentation, but seeing this makes me realize that your if statements are slightly off.
This is what vb sees: Code:
Private Sub Command1_Click() Dim g1 As Variant Dim g2 As Variant Dim g3 As Variant g2 = val1.Text g3 = val2.Text If Opt1.Value = 1 Then If Op4.Value = 1 Then g1 = g2 / g3 ElseIf Op5.Value = 1 Then g1 = g2 + g3 ElseIf Op6.Value = 1 Then g1 = g2 - g3 ElseIf Opt2.Value = 1 Then If Op4.Value = 1 Then g1 = g2 / g3 ElseIf Op5.Value = 1 Then g1 = g2 + g3 ElseIf Op6.Value = 1 Then g1 = g2 - g3 ElseIf Opt3.Value = 1 Then If Op4.Value = 1 Then g1 = g2 / g3 ElseIf Op5.Value = 1 Then g1 = g2 + g3 ElseIf Op6.Value = 1 Then g1 = g2 - g3 Else MsgBox "Done" End If End If End If End If Res.Text = g1 End Sub |
|
#5
|
|||
|
|||
|
If anyone can give me an answer I will add you as one of the coders to the program. It's for a goverment department in Australia.
|
|
#6
|
|||
|
|||
|
Hi Mig Officer! I try your code,but i find if opt1.value<>true,the follow statements are not runned!!U can tell us what your code meaning??..And then Thx Onslaught's work!..
|
|
#7
|
||||
|
||||
|
Try something along these lines:
Code:
Private Sub Command1_Click() Dim g1 As Variant Dim g2 As Variant Dim g3 As Variant g2 = val1.Text g3 = val2.Text If Opt1.Value = 1 Then If Op4.Value = 1 Then g1 = g2 / g3 ElseIf Op5.Value = 1 Then g1 = g2 + g3 ElseIf Op6.Value = 1 Then g1 = g2 - g3 End If Else If Opt2.Value = 1 Then If Op4.Value = 1 Then g1 = g2 / g3 Else If Op5.Value = 1 Then g1 = g2 + g3 Else If Op6.Value = 1 Then g1 = g2 - g3 End If Else If Opt3.Value = 1 Then If Op4.Value = 1 Then g1 = g2 / g3 Else If Op5.Value = 1 Then g1 = g2 + g3 Else If Op6.Value = 1 Then g1 = g2 - g3 End If Else MsgBox "Done" End If Res.Text = g1 End Sub |
|
#8
|
|||
|
|||
|
Yeah!Onslaught,U are cleverman!I'm cleverpig?!!haha!!THX..
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Lost value in If Statements |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|