Results 1 to 4 of 4

Thread: loop pain again!!!

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Location
    Australia
    Posts
    10

    Talking loop pain again!!!

    HELP !

    how to loop back usr input if num > 6 or num= decimal point?

    my code:
    Public Sub Try()

    Dim i As Integer
    Dim sResult As String
    Dim sStore As String
    Dim sFreq(1 To 6) As String
    Dim iResponse As Integer

    For i = 1 To 6
    sFreq(i) = i
    Next


    Do

    sResult = Application.InputBox("Please Input a Frequency", "Frequency Input", _
    "Please Input an Integer Value", Type:=1)

    For i = 1 To 6
    If sResult = sFreq(i) Then
    sStore = sResult
    ChDir "C:\Workbooks.Open" Filename:="C:\Testing.xls"
    Sheets(i).Select
    Call CreateChart

    Exit Do
    End If
    Next
    iResponse = MsgBox("Invalid input. Please try again.", vbOKOnly)
    Loop Until iResponse = i
    End Sub

  2. #2
    Addicted Member rbnwares's Avatar
    Join Date
    Sep 2000
    Location
    Philippines
    Posts
    142
    How about this?

    Do
    sResult = InputBox$("Please input a frequency....)

    For i = 1 To 6
    If CInt( sResult) = sFreq( i ) Then
    'Do something here...if equal
    Exit For
    End If
    Next i

    If i > 6 Then
    Call Msgbox("Invalid Input...)
    Else
    Exit Do
    End If

    Loop Until True
    Stupidity is better than cure.

    VB6 SP5 Enterprise Ed.
    C, Pascal, VC++ 6.0


    Running Win98 SE and Win2000 Prof. Ed.


    Email me at : [email protected]

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Location
    Australia
    Posts
    10
    thanks rbnwares.

    i hv get it done.

  4. #4
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Code:
    Dim strInpBox As String
    strInpBox = InputBox("Enter A Number ...")
    
    If (StrPtr(strInpBox) = 0) Then
        MsgBox "You hit the cancel button"
    ElseIf Not (IsNumeric(strInpBox)) Then
        MsgBox "You didn't enter a numeric value"
    ElseIf (CInt(strInpBox) > 6) Then
        MsgBox "The number's above 6"
    ElseIf (InStr(strInpBox, ".")) Then
       MsgBox "The number has a decimal place in"
    Else
       MsgBox "Number's fine !"
    End If
    That should more or less cover everthing the user could do to bugger the number up If you need any of that explained, let me know.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

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