Jump to content

need Script to ask user if they want to begin again


Recommended Posts

Posted

I have a script that creates a file and writes lines of text based on the users input one line at a time but I have to run the script each time by clicking on it. I need to eliminate as many steps as possible to help cut down the time it takes us because our SLA is getting reduced. So, I need the script to ask me if I want to continue and then if not I need the script to close. This is what I have so far. I am also having trouble getting the Cancel button to work. I've tried several things and no matter what I add to the below script its just not working. many thanks for the assistance.

 

Option Explicit

dim login, groupname, touname, x, startover, strfile, objFSO, objFile

strFile = "C:\Documents and Settings\username\Desktop\output.txt"

Sub GetInput()

Do While X = 0

login = InputBox ("Please enter the user's ID.","Step 1")

If login = "" Then

Wscript.Echo "You must enter the user's ID."

Else

Exit Do

End If

Loop

Do While X = 0

groupname = InputBox ("Please enter the groupname.","Step 2")

If groupname = "" Then

Wscript.Echo "You must enter the groupname."

Else

Exit Do

End If

Loop

Do While X = 0

startover = InputBox ("Type y and hit enter to run again","Step 3")

If startover = "y" Then

Else

Exit Do

End If

Loop

End Sub

Call GetInput

set objFSO = CreateObject("Scripting.FileSystemObject")

set objFile = objFSO.OpenTextFile(strFile, 8, True)

objFile.WriteLine(login & ":AD User:Active Directory:CN=" & groupname)

objFile.Close

Posted

So you want to populate a file with multiple lines containing multiple user details?

 

Look at where you are writing to the file as I think you've got a fundamental problem.

 

Ben

Posted (edited)
What's up Ben? No its cool i just changed a few thing s so nothing would be exactly like our network. im just concerned with the last part. I tried writing you but it said your Pm's were full. No I took what you helped me with before and made it do another function that will have a lot more use. I couldn't really find another site that provided me with an idea of what I'm looking for. I'd like to make it all possible with excel but the way our net apps work it's not quite there yet. They need certain files we use to not have macros. So from what I looked up tho, please correct me if I'm wrong but I would need to create a variable to serve as a function that reopened the script file itself or loops back to the top. I looked up the message cancel thing too and I tried puttin it in but all it did was produce message box saying cancel was pressed and stopped the script. It didn't restart it when I created the variable for the file and tried to run it in the last if then portions. It just erred and said the obj I created was undefined. It went thru the questions and stopped there. Cancel doesn't have to work tho. That's no big deal but it would be cool. Edited by techadmin32
Posted

Try this

 

Option Explicit
dim login, groupname, touname, x, startover, strFile, objFSO, objFile, intAnswer
strFile = "C:\Users\username\Documents\output.txt"
set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile = objFSO.OpenTextFile(strFile, 8, True)

Sub GetInput()
Do While X = 0
login = InputBox ("Please enter the user's ID.","Step 1")
If login = "" Then
Wscript.Echo "You must enter the user's ID."
Else
Exit Do
End If
Loop
Do While X = 0
groupname = InputBox ("Please enter the groupname.","Step 2")
If groupname = "" Then
Wscript.Echo "You must enter the groupname."
Else
Exit Do
End If
Loop

intAnswer =  Msgbox("Do you want to run again?", vbYesNo, "Delete Files")

If intAnswer = vbYes Then
objFile.WriteLine(login & ":AD User:Active Directory:CN=" & groupname)
call GetInput
Else
objFile.WriteLine(login & ":AD User:Active Directory:CN=" & groupname)
End If

End Sub


Call GetInput

objFile.Close 

 

Ben

  • Thanks 1
Posted

One of the problems with what you originally posted was where you were doing the file write as if the loop worked correctly your variables would only ever be populated with the last set of entered details so would only ever write one line no matter how many times you went through the loop.

 

Ben

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...