+ Reply to Thread
Results 1 to 3 of 3

Looping problem

  1. #1
    Sleeping Bear
    Guest

    Looping problem

    I have a macro that prompts for the quarter. I ask for 1, 2, 3, or 4 and go
    on from that. Even with the message box specifying the desired input, some
    users are entering alpha or something else. I'm trying to create a loop that
    will give the user 4 chances to enter correctly and then use the default,
    regardless of what the user has entered. I keep getting a type mismatch error
    but when I change the variable to integer, alpha data causes it to stop. Any
    ideas?

    Here's the code I have now:

    Dim Q As Integer
    Q = 0
    chk1 = False
    Do Until chk1 = True
    Dim z As String
    z = InputBox("Input quarter (1, 2, 3, or 4) to run. Default is 1.", , "1")

    If z = 1 Then
    qtr = Mar
    chk1 = True
    End If

    If z = 2 Then
    qtr = Jun
    chk1 = True
    End If

    If z = 3 Then
    qtr = Sep
    chk1 = True
    End If

    If z = 4 Then
    qtr = Dec
    chk1 = True
    End If

    If Q > 3 Then
    MsgBox ("You've had 4 chances. I choose the default of '1' for you.")
    qtr = Mar
    chk1 = True
    End If
    Q = Q + 1
    Loop

    Thanks.

  2. #2
    Trevor Shuttleworth
    Guest

    Re: Looping problem

    Try:

    Sub test()
    Dim Q As Integer
    Q = 0
    chk1 = False
    Do Until chk1 = True
    Dim z ' <<<<<<
    z = InputBox("Input quarter (1, 2, 3, or 4) to run. Default is 1.", ,
    "1")

    Regards

    Trevor


    "Sleeping Bear" <Sleeping Bear@discussions.microsoft.com> wrote in message
    news:CB13374A-B633-4893-8536-C7B6BBF47B9F@microsoft.com...
    >I have a macro that prompts for the quarter. I ask for 1, 2, 3, or 4 and go
    > on from that. Even with the message box specifying the desired input, some
    > users are entering alpha or something else. I'm trying to create a loop
    > that
    > will give the user 4 chances to enter correctly and then use the default,
    > regardless of what the user has entered. I keep getting a type mismatch
    > error
    > but when I change the variable to integer, alpha data causes it to stop.
    > Any
    > ideas?
    >
    > Here's the code I have now:
    >
    > Dim Q As Integer
    > Q = 0
    > chk1 = False
    > Do Until chk1 = True
    > Dim z As String
    > z = InputBox("Input quarter (1, 2, 3, or 4) to run. Default is 1.", ,
    > "1")
    >
    > If z = 1 Then
    > qtr = Mar
    > chk1 = True
    > End If
    >
    > If z = 2 Then
    > qtr = Jun
    > chk1 = True
    > End If
    >
    > If z = 3 Then
    > qtr = Sep
    > chk1 = True
    > End If
    >
    > If z = 4 Then
    > qtr = Dec
    > chk1 = True
    > End If
    >
    > If Q > 3 Then
    > MsgBox ("You've had 4 chances. I choose the default of '1' for you.")
    > qtr = Mar
    > chk1 = True
    > End If
    > Q = Q + 1
    > Loop
    >
    > Thanks.




  3. #3
    Sleeping Bear
    Guest

    Re: Looping problem

    That did it. Thanks. Sleeping Bear

    "Trevor Shuttleworth" wrote:

    > Try:
    >
    > Sub test()
    > Dim Q As Integer
    > Q = 0
    > chk1 = False
    > Do Until chk1 = True
    > Dim z ' <<<<<<
    > z = InputBox("Input quarter (1, 2, 3, or 4) to run. Default is 1.", ,
    > "1")
    >
    > Regards
    >
    > Trevor
    >
    >
    > "Sleeping Bear" <Sleeping Bear@discussions.microsoft.com> wrote in message
    > news:CB13374A-B633-4893-8536-C7B6BBF47B9F@microsoft.com...
    > >I have a macro that prompts for the quarter. I ask for 1, 2, 3, or 4 and go
    > > on from that. Even with the message box specifying the desired input, some
    > > users are entering alpha or something else. I'm trying to create a loop
    > > that
    > > will give the user 4 chances to enter correctly and then use the default,
    > > regardless of what the user has entered. I keep getting a type mismatch
    > > error
    > > but when I change the variable to integer, alpha data causes it to stop.
    > > Any
    > > ideas?
    > >
    > > Here's the code I have now:
    > >
    > > Dim Q As Integer
    > > Q = 0
    > > chk1 = False
    > > Do Until chk1 = True
    > > Dim z As String
    > > z = InputBox("Input quarter (1, 2, 3, or 4) to run. Default is 1.", ,
    > > "1")
    > >
    > > If z = 1 Then
    > > qtr = Mar
    > > chk1 = True
    > > End If
    > >
    > > If z = 2 Then
    > > qtr = Jun
    > > chk1 = True
    > > End If
    > >
    > > If z = 3 Then
    > > qtr = Sep
    > > chk1 = True
    > > End If
    > >
    > > If z = 4 Then
    > > qtr = Dec
    > > chk1 = True
    > > End If
    > >
    > > If Q > 3 Then
    > > MsgBox ("You've had 4 chances. I choose the default of '1' for you.")
    > > qtr = Mar
    > > chk1 = True
    > > End If
    > > Q = Q + 1
    > > Loop
    > >
    > > Thanks.

    >
    >
    >


+ Reply to Thread

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