Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For Loop Exit Vbscript Question

Status
Not open for further replies.

DannyTekTipUser

Technical User
Oct 24, 2013
1
US
thread329-1692441

Hi,

i am a newbie with vbscript and would apppreciate if you can help me. I have a

for loop below and i am having problem on how the loop will exit whenever the

inputbox is blank or the loop will exit if Cancel is click..below is my for loop

vbscript....Thanks in Advance.

Dim fso, tf
'Dim Msg As Variant
Dim loopIndex
Set fso = CreateObject("Scripting.FileSystemObject")
Set tf = fso.CreateTextFile("c:\Test\pcname.txt", True)
For loopIndex = 0 To 5
Msg = InputBox("Input PC Name in FQDN Format (e.g. PC1.domain.com) Then click
OK button to proceed Or Click Cancel to Terminate.", "Input Window")
tf.WriteLine(Msg)
Next
tf.Close

 
I suggest a search on this site. I seem to remember a FAQ on this subject.

Never knock on Death's door: ring the bell and run away! Death really hates that!
 
A starting point:
Code:
Dim fso, tf
Dim Msg
Dim loopIndex
Set fso = CreateObject("Scripting.FileSystemObject")
Set tf = fso.CreateTextFile("c:\Test\pcname.txt", True)
For loopIndex = 0 To 5
    Msg = InputBox("Input PC Name in FQDN Format (e.g. PC1.domain.com) Then click OK" _
                 & " button to proceed Or Click Cancel to Terminate.", "Input Window")
    [!]If Trim(Msg) = "" Then Exit For[/!]
    tf.WriteLine Msg
Next
tf.Close

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top