tags:

views:

28

answers:

2

The following VB script check the valid IP by Test function

if we get OK from the test function then We break from loop ValidIP=OK If not the inputBox ask the question until ValidIP=OK

But sometimes I want to exit from loop by cancel button

How to break loop by the cancel button (in order to set the ValidIP as OK)

Do Until ValidIP=OK
    IPrange=InputBox("Enter IP address range",,"172.17.202.1-10,192.9.200.1-100")
    Test IPrange, strPattern 
Loop
A: 

Put something like the code below before the Test... row (code written from old memories of how vbscript works):

If Len(IPrange) = 0 Then
    Exit Do
End 

When the user clicks Cancel the InputBox returns a 0 length string.

ho1
THXand if I want to exit program (not exit loop)
yael
@yael: `WScript.Quit [number]` change `[number]` to the value the script should return.
ho1
A: 

I do not know VB script but I would solve this problem as follows.

Your IP by Test function would have run in a separate thread, the thread in which the GUI runs must be able to communicate with your other thread and set a variable.

For readability I would introduce a new variable lets say AbortedByUser this variable can be set by your other thread (event handler or something like that to not make it public..)

Then your code would be looking something like this:

Do Until ValidIP=OK AND !AbortedByUser
   IPrange=InputBox("Enter IP address range",,"172.17.202.1-10,192.9.200.1-100")
   Test IPrange, strPattern
Loop

Note that the AbortedByUser will has to be set to false when your function gets started.

As I don't know VB script I don't now how to write this AND NOT thing properly.. ;-)

Mark
THX the first answer is OK for me and its solved my problemyael
yael