Results 1 to 4 of 4

Thread: command button if statements

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Location
    Sheffield
    Posts
    10

    command button if statements

    ok, i've got this so far:

    VB Code:
    1. Private Sub Command1_Click()
    2. Command2.Enabled = True
    3. List1.AddItem Label1.Caption
    4. Dim number As Integer
    5. number = lable1
    6. If number <= 3 Then
    7. MsgBox "You Must Enter 3 Or More Numbers To Make A Call"
    8. End If
    9. End Sub

    basically, a msgbox is meant to pop up when you click the button and less than 3 numbers are in the label. as it stands, the message box appears no matter how many numbers are in the label when you click the button!

    can you spot anything i've missed/done wrong?

    (sorry for the continuous threads with this particular project, i'm just majorly stuck, i'll try to keep using this same thread for any questions to do with this particular project, so keep checking on it please!!!)

    x.

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: command button if statements

    typo on this line:

    VB Code:
    1. number = lable1

    Add 'Option Explicit' to the top of all your forms / modules to catch things like this.

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Location
    Sheffield
    Posts
    10

    Re: command button if statements

    i corrected the typo but it still displays the message box even if i enter more than 3 numbers!
    now my code for adding text from the lable to a list doesn't work either:
    VB Code:
    1. List1.AddItem Lable1.Caption
    grrr! .
    x.

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: command button if statements

    you need to test the length of the string
    VB Code:
    1. Private Sub Command1_Click()
    2.     Command2.Enabled = True
    3.     If Len(Label1.Caption) < 3 Then
    4.         MsgBox "You Must Enter 3 Or More Numbers To Make A Call"
    5.     Else
    6.         List1.AddItem Label1.Caption
    7.     End If
    8. End Sub

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