Using the IF and THEN statement. {RESOLVED}
Hello,
How do I get this code to work. What it is supposed to do is if the Option button "Down" is pressed it will do the correct code for that but if the Option button "Up" is pressed it will do what was selected for that. However the code below only works if the Option "UP" is selected. :eek2: Does anyone see what I am doing wrong?
VB Code:
Private Sub cmdCalc4_Click()
Dim X3 As Long
Dim y3 As Long
If [B]OptUp.Value [/B] = True Then
If lnHigh.Y1 > lnLow.Y1 Then
ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 + (lnLow.Y1)
ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 + (lnLow.Y2)
lbl146.Caption = frmMain.Text1.Text
Else
ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 + (lnLow.Y1)
ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 + (lnLow.Y2)
lbl146.Caption = frmMain.Text1.Text
End If
ln146.X1 = Picture1.Left
ln146.X2 = Picture1.Width
ln146.Visible = True
X3 = (Picture1.ScaleWidth - Picture1.ScaleLeft) / 2
y3 = ln146.Y2 + 0.8
lbl146.Move X3, y3
lbl146.Visible = True
End If
If [B]Optdown.Value[/B] = True Then
If lnHigh.Y1 > lnLow.Y1 Then
ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y1)
ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y2)
lbl146.Caption = frmMain.Text1.Text
Else
ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y1)
ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y2)
lbl146.Caption = frmMain.Text1.Text
End If
ln146.X1 = Picture1.Left
ln146.X2 = Picture1.Width
ln146.Visible = True
X3 = (Picture1.ScaleWidth - Picture1.ScaleLeft) / 2
y3 = ln146.Y2 + 0.8
lbl146.Move X3, y3
lbl146.Visible = True
End If
End Sub
Thank you and have a great day! :thumb:
Stilekid007 :wave:
Re: Using the IF and THEN statement.
Do you know anything about debugging? In any case put a breakpoint of the If Optdown.Value = True Then line and step through the code (using F8) and see what happens.
Re: Using the IF and THEN statement.
Hello Marty,
Thank you for your reply!
I did the debuging and it went to the line "If OptUp.Value = True Then"
And then skipped over everything under it till this line "If OptDown.Value = True Then"
Then it went through all the code in that sub that was under "If OptDown.Value = True Then"
And it all looked like it would have worked right but no lines or labels that were supposed to become visible showed up on the picture box.
Any Ideas?
Stilekid007
Re: Using the IF and THEN statement.
make sure your values are getting set correctly..
follow the same steps to debug...
but at each line where something is supposed to happen..
put your mouse over each variable.. the "value" will appear
make sure they look good
Re: Using the IF and THEN statement.
It skipped it because OptUp.Value was not equal True...
Re: Using the IF and THEN statement.
All the Values are right as far as I can tell.
See the code works if I take this code off of the code above it all works and the only thing different on this code then the UP code is it has a minus from High instead of + from Low.
VB Code:
If Optdown.Value = True Then
If lnHigh.Y1 > lnLow.Y1 Then
ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y1)
ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y2)
lbl146.Caption = frmMain.Text1.Text
Else
ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y1)
ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y2)
lbl146.Caption = frmMain.Text1.Text
End If
ln146.X1 = Picture1.Left
ln146.X2 = Picture1.Width
ln146.Visible = True
X3 = (Picture1.ScaleWidth - Picture1.ScaleLeft) / 2
y3 = ln146.Y2 + 0.8
lbl146.Move X3, y3
lbl146.Visible = True
End If
Re: Using the IF and THEN statement.
Ok, Now I just made a command button with JUST this code in it. and it still doesn't work! So it is something to do with this code>????????
VB Code:
Dim X3 As Long
Dim y3 As Long
If Optdown.Value = True Then
If lnHigh.Y1 > lnLow.Y1 Then
ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y1)
ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y2)
lbl146.Caption = frmMain.Text1.Text
Else
ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y1)
ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y2)
lbl146.Caption = frmMain.Text1.Text
End If
ln146.X1 = Picture1.Left
ln146.X2 = Picture1.Width
ln146.Visible = True
X3 = (Picture1.ScaleWidth - Picture1.ScaleLeft) / 2
y3 = ln146.Y2 + 0.8
lbl146.Move X3, y3
lbl146.Visible = True
End If
Re: Using the IF and THEN statement.
VB Code:
Dim X3 As Long
Dim y3 As Long
If Optdown.Value = True Then
If lnHigh.Y1 > lnLow.Y1 Then
ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y1)
ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y2)
lbl146.Caption = frmMain.Text1.Text
Else
ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y1)
ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y2)
lbl146.Caption = frmMain.Text1.Text
End If
ln146.X1 = Picture1.Left
ln146.X2 = Picture1.Width
ln146.Visible = True
X3 = (Picture1.ScaleWidth - Picture1.ScaleLeft) / 2
y3 = ln146.Y2 + 0.8
lbl146.Move X3, y3
lbl146.Visible = True
End If
Hi try this,
Code:
Dim X3 As Long
Dim y3 As Long
If Optdown.Value = True Then
If lnHigh.Y1 > lnLow.Y1 Then
ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y1)
ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y2)
lbl146.Caption = frmMain.Text1.Text
Else
ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y1)
ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y2)
lbl146.Caption = frmMain.Text1.Text
End If
End If
ln146.X1 = Picture1.Left
ln146.X2 = Picture1.Width
ln146.Visible = True
X3 = (Picture1.ScaleWidth - Picture1.ScaleLeft) / 2
y3 = ln146.Y2 + 0.8
lbl146.Move X3, y3
lbl146.Visible = True
Fishy
Re: Using the IF and THEN statement.
Re: Using the IF and THEN statement.
Re: Using the IF and THEN statement.
[LGS]Static's suggestion (post #4) is what you should do. Look at every variable and the results of all calculations. You can also at any time look at the form and see if anything has moved.
Re: Using the IF and THEN statement.
Ok, I got it.
I had to change this calcualtion >
ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y1)
ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y2)
TO >
ln146.Y1 = lnHigh.Y1 - (lnHigh.Y1 - lnLow.Y1) * 0.146
ln146.Y2 = lnHigh.Y1 - (lnHigh.Y1 - lnLow.Y1) * 0.146
The first calculation was making the line go off the chart because it was wrong calculations.
Thank you everyone for your replys! :thumb:
Stilekid007 :wave: