Results 1 to 12 of 12

Thread: Using the IF and THEN statement. {RESOLVED}

  1. #1

    Thread Starter
    Hyperactive Member stilekid007's Avatar
    Join Date
    Apr 2005
    Location
    DUDE! I'm your neighbor! HELLO!!!
    Posts
    388

    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. Does anyone see what I am doing wrong?

    VB Code:
    1. Private Sub cmdCalc4_Click()
    2. Dim X3 As Long
    3. Dim y3 As Long
    4.  
    5. If [B]OptUp.Value [/B] = True Then
    6. If lnHigh.Y1 > lnLow.Y1 Then
    7. ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 + (lnLow.Y1)
    8. ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 + (lnLow.Y2)
    9. lbl146.Caption = frmMain.Text1.Text
    10. Else
    11. ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 + (lnLow.Y1)
    12. ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 + (lnLow.Y2)
    13. lbl146.Caption = frmMain.Text1.Text
    14. End If
    15. ln146.X1 = Picture1.Left
    16. ln146.X2 = Picture1.Width
    17. ln146.Visible = True
    18. X3 = (Picture1.ScaleWidth - Picture1.ScaleLeft) / 2
    19. y3 = ln146.Y2 + 0.8
    20. lbl146.Move X3, y3
    21. lbl146.Visible = True
    22. End If
    23.  
    24. If [B]Optdown.Value[/B] = True Then
    25. If lnHigh.Y1 > lnLow.Y1 Then
    26. ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y1)
    27. ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y2)
    28. lbl146.Caption = frmMain.Text1.Text
    29.  
    30. Else
    31. ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y1)
    32. ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y2)
    33. lbl146.Caption = frmMain.Text1.Text
    34. End If
    35. ln146.X1 = Picture1.Left
    36. ln146.X2 = Picture1.Width
    37. ln146.Visible = True
    38. X3 = (Picture1.ScaleWidth - Picture1.ScaleLeft) / 2
    39. y3 = ln146.Y2 + 0.8
    40. lbl146.Move X3, y3
    41. lbl146.Visible = True
    42.  
    43. End If
    44. End Sub

    Thank you and have a great day!
    Stilekid007
    Last edited by stilekid007; Jun 21st, 2005 at 07:28 PM.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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.

  3. #3

    Thread Starter
    Hyperactive Member stilekid007's Avatar
    Join Date
    Apr 2005
    Location
    DUDE! I'm your neighbor! HELLO!!!
    Posts
    388

    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

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    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
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Using the IF and THEN statement.

    It skipped it because OptUp.Value was not equal True...

  6. #6

    Thread Starter
    Hyperactive Member stilekid007's Avatar
    Join Date
    Apr 2005
    Location
    DUDE! I'm your neighbor! HELLO!!!
    Posts
    388

    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:
    1. If Optdown.Value = True Then
    2. If lnHigh.Y1 > lnLow.Y1 Then
    3. ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y1)
    4. ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y2)
    5. lbl146.Caption = frmMain.Text1.Text
    6.  
    7. Else
    8. ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y1)
    9. ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y2)
    10. lbl146.Caption = frmMain.Text1.Text
    11. End If
    12. ln146.X1 = Picture1.Left
    13. ln146.X2 = Picture1.Width
    14. ln146.Visible = True
    15. X3 = (Picture1.ScaleWidth - Picture1.ScaleLeft) / 2
    16. y3 = ln146.Y2 + 0.8
    17. lbl146.Move X3, y3
    18. lbl146.Visible = True
    19.  
    20. End If

  7. #7

    Thread Starter
    Hyperactive Member stilekid007's Avatar
    Join Date
    Apr 2005
    Location
    DUDE! I'm your neighbor! HELLO!!!
    Posts
    388

    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:
    1. Dim X3 As Long
    2. Dim y3 As Long
    3.  
    4. If Optdown.Value = True Then
    5. If lnHigh.Y1 > lnLow.Y1 Then
    6. ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y1)
    7. ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y2)
    8. lbl146.Caption = frmMain.Text1.Text
    9.  
    10. Else
    11. ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y1)
    12. ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y2)
    13. lbl146.Caption = frmMain.Text1.Text
    14. End If
    15. ln146.X1 = Picture1.Left
    16. ln146.X2 = Picture1.Width
    17. ln146.Visible = True
    18. X3 = (Picture1.ScaleWidth - Picture1.ScaleLeft) / 2
    19. y3 = ln146.Y2 + 0.8
    20. lbl146.Move X3, y3
    21. lbl146.Visible = True
    22.  
    23. End If

  8. #8
    Lively Member
    Join Date
    Apr 2005
    Posts
    91

    Re: Using the IF and THEN statement.

    VB Code:
    1. Dim X3 As Long
    2. Dim y3 As Long
    3.  
    4. If Optdown.Value = True Then
    5. If lnHigh.Y1 > lnLow.Y1 Then
    6. ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y1)
    7. ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y2)
    8. lbl146.Caption = frmMain.Text1.Text
    9.  
    10. Else
    11. ln146.Y1 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y1)
    12. ln146.Y2 = (lnHigh.Y1 - lnLow.Y1) * 0.146 - (lnHigh.Y2)
    13. lbl146.Caption = frmMain.Text1.Text
    14. End If
    15. ln146.X1 = Picture1.Left
    16. ln146.X2 = Picture1.Width
    17. ln146.Visible = True
    18. X3 = (Picture1.ScaleWidth - Picture1.ScaleLeft) / 2
    19. y3 = ln146.Y2 + 0.8
    20. lbl146.Move X3, y3
    21. lbl146.Visible = True
    22.  
    23. 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

  9. #9

    Thread Starter
    Hyperactive Member stilekid007's Avatar
    Join Date
    Apr 2005
    Location
    DUDE! I'm your neighbor! HELLO!!!
    Posts
    388

    Re: Using the IF and THEN statement.

    Nothing! ARRGG!

  10. #10
    Lively Member
    Join Date
    Apr 2005
    Posts
    91

    Re: Using the IF and THEN statement.

    Did you De-Bug?

  11. #11
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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.

  12. #12

    Thread Starter
    Hyperactive Member stilekid007's Avatar
    Join Date
    Apr 2005
    Location
    DUDE! I'm your neighbor! HELLO!!!
    Posts
    388

    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!

    Stilekid007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width