Results 1 to 7 of 7

Thread: Loop Inputbox

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Loop Inputbox

    I have problem I used inputbox, How to loop the Xcor and Ycor inputbox untill the number of the input station

    Code:
    Dim stnNumber As Integer
    Dim Xcor As Double
    Dim Ycor As Double
    stnNumber = Val(InputBox("Enter a number of station(zero to quit):", "Input station"))
    Xcor = Val(InputBox("Enter a X coordinate (zero to quit): =", "Input X coordinate"))
    Ycor = Val(InputBox("Enter a Y coordinate (zero to quit): =", "Input Y coordinate"))

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Loop Inputbox

    How about a straightforward For / Next Loop ?
    Code:
    For I = 1 To stnNumber
    
    <put your Inputbox statements etc here>
    
    Next I

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: Loop Inputbox

    How to terminated the program from continuing looping the program
    Last edited by matrik02; Feb 5th, 2012 at 01:30 AM.

  4. #4
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Loop Inputbox

    Well, if the user puts in, for example, 2 as the station number, the loop will only execute 2 times.
    What code have you tried?

  5. #5
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Loop Inputbox

    Matrik

    Your requirements are a little vague, but Doogle
    has nonetheless presented a possible approach.

    Building on his loop, you possibly already have an "out" ..
    namely, your "Enter a number of station(zero to quit):" .

    So, one logical extension might be ...
    Code:
    For I = 1 To stnNumber
        stnNumber = Val(InputBox("Enter a number of station(zero to quit):", "Input station"))
        Xcor = Val(InputBox("Enter a X coordinate (zero to quit): =", "Input X coordinate"))
        Ycor = Val(InputBox("Enter a Y coordinate (zero to quit): =", "Input Y coordinate"))Next I
        If strNumber = 0 Or Xcor = 0 Or Ycor = 0 Then
            Exit For
        End If
    Hope that gives you some ideas

    Spoo

  6. #6
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Loop Inputbox

    You need to read stnNumber in before you can control a loop using it !
    Code:
    stnNumber = Val(InputBox("Enter a number of station(zero to quit):", "Input station"))
    For I = 1 To stnNumber
        Xcor = Val(InputBox("Enter a X coordinate (zero to quit): =", "Input X coordinate"))
        Ycor = Val(InputBox("Enter a Y coordinate (zero to quit): =", "Input Y coordinate"))
    '
    ' do something with Xcor and Ycor
    ' Then go back and ask for the next values
    '
    Next I
    '
    ' All Xcor and Ycor values have been read and processed
    ' If stnNumber was zero then the loop will not have been executed
    ' (no need for an If statement, although you'll need to determine
    ' whether any Xcor and Ycor data have been input)
    '

  7. #7
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Loop Inputbox

    Doogle

    My bad ..
    Thank you for the catch

    Spoo

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