InputBox function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Yogesh Sharma
    New Member
    • Mar 2008
    • 40

    InputBox function

    Private Sub Command4_Click( )
    Dim i
    i = InputBox("Enter a number", "Enter")
    If i > 10 Then
    MsgBox "Number is less than" + i
    End If
    End Sub

    Hey I want that if the user enters number from 1 to 10 in the textbox(InputBo x) msgbox comes on clicking the ok Button that" number is b/w 1 to 10," & else part if the user enters greater than 10, then msgbox shows "Number is greater than 10"

    Plz help me out,I m new to the Vb.
  • ubentook
    New Member
    • Dec 2007
    • 58

    #2
    Maybe this...
    '--
    Private Sub Command4_Click( )
    Dim i as Variant
    OnTop:
    i = InputBox("Enter a number between 1 and 10 ", "Enter")
    If Len(i) = 0 Then
    Exit Sub
    ElseIf i > 10 Then
    If MsgBox("Number is greater than 10 ", vbExclamation + vbRetryCancel, "Oops") = vbRetry Then GoTo OnTop
    ElseIf i < 1 Then
    If MsgBox("Number is less than 1", vbExclamation + vbRetryCancel, "Oops") = vbRetry Then GoTo OnTop
    End If
    End Sub


    Originally posted by Yogesh Sharma
    Private Sub Command4_Click( )
    Dim i
    i = InputBox("Enter a number", "Enter")
    If i > 10 Then
    MsgBox "Number is less than" + i
    End If
    End Sub

    Hey I want that if the user enters number from 1 to 10 in the textbox(InputBo x) msgbox comes on clicking the ok Button that" number is b/w 1 to 10," & else part if the user enters greater than 10, then msgbox shows "Number is greater than 10"

    Plz help me out,I m new to the Vb.

    Comment

    • QVeen72
      Recognized Expert Top Contributor
      • Oct 2006
      • 1445

      #3
      Hi,

      Try this :

      [Code=VB]
      Private Sub Command4_Click( )
      Dim i
      i = Val(InputBox("E nter a number", "Enter"))
      If i>=1 And i <=10 Then
      MsgBox "Number " & i & " is b/w 1 to 10"
      ElseIf i > 10 Then
      MsgBox "Number " & i & " is More than 10 "
      Else
      MsgBox "Not Applicable"
      End If
      End Sub
      [/code]
      Regards
      Veena

      Comment

      • Yogesh Sharma
        New Member
        • Mar 2008
        • 40

        #4
        Thx Both of U,i have got it. hey can u pls send me the books of vb,if you have ???

        Comment

        Working...