Results 1 to 2 of 2

Cancelling an inputbox if blank input or cancel button is pressed

Threaded View

kathhying Cancelling an inputbox if... 11-01-2011, 10:45 AM
royUK Re: Cancelling an inputbox if... 11-01-2011, 12:07 PM
  1. #1
    Registered User
    Join Date
    10-28-2011
    Location
    UK
    MS-Off Ver
    Excel 2010 (mac)
    Posts
    10

    Cancelling an inputbox if blank input or cancel button is pressed

    I'm not sure where it went wrong.

    
    Sub numguesser()
    
    Dim ans As Integer
    Dim ctr As Integer
    Dim guess As Integer
    Dim deviation As Integer
    Dim msg As String
    
    Randomize
    ans = Int(Rnd() * 5000 + 1)
    
    ctr = 0
    
    Do
    guess = InputBox("guess the number (1 to 5000)", vbQuestion + vbCancel, "")
    
    If guess = "" Then
    Exit Sub
    End If
    
    ctr = ctr + 1
    
    If ans > guess Then
        deviation = ans - guess
        Else
        deviation = guess - ans
    End If
    
    Select Case deviation
        Case 0
        MsgBox "Congratulations! You have tried " & ctr & " times and get the correct answer of " & ans & ""
        Case 1 To 10
        MsgBox guess & ": very hot"
        Case 11 To 25
        MsgBox guess & ": hot"
        Case 26 To 100
        MsgBox guess & ": cool"
        Case 101 To 500
        MsgBox guess & ": cold"
        Case Is >= 501
        MsgBox guess & ": very cold"
    End Select
    
    Loop Until ans = guess
    
    
    End Sub
    Last edited by kathhying; 11-01-2011 at 11:24 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1