+ Post New Thread
Results 1 to 7 of 7
Scripts Thread, need Script to ask user if they want to begin again in Coding and Web Development; I have a script that creates a file and writes lines of text based on the users input one line ...
  1. #1

    Join Date
    Sep 2013
    Posts
    10
    Thank Post
    6
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    need Script to ask user if they want to begin again

    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

  2. #2

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,691
    Thank Post
    756
    Thanked 1,715 Times in 1,526 Posts
    Rep Power
    438
    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

  3. #3

    Join Date
    Sep 2013
    Posts
    10
    Thank Post
    6
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    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.
    Last edited by techadmin32; 21st September 2013 at 10:19 PM.

  4. #4

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,691
    Thank Post
    756
    Thanked 1,715 Times in 1,526 Posts
    Rep Power
    438
    Try this

    Code:
    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

  5. Thanks to plexer from:

    techadmin32 (21st September 2013)

  6. #5

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,691
    Thank Post
    756
    Thanked 1,715 Times in 1,526 Posts
    Rep Power
    438
    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

  7. Thanks to plexer from:

    techadmin32 (21st September 2013)

  8. #6

    Join Date
    Sep 2013
    Posts
    10
    Thank Post
    6
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Thats exactly what we need. Awesome! Thanks Ben!

  9. #7

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,691
    Thank Post
    756
    Thanked 1,715 Times in 1,526 Posts
    Rep Power
    438
    You're welcome it could probably be tidy'ed up more and perhaps some additional data and error checking but it works.

    Ben



SHARE:
+ Post New Thread

Similar Threads

  1. [SIMS] If You Want To Use Nova-T 4 Then Move To Africa
    By russdev in forum MIS Systems
    Replies: 29
    Last Post: 28th August 2012, 09:47 AM
  2. Replies: 2
    Last Post: 8th November 2011, 04:46 PM
  3. What if I wanted to Virtualize an existing room with Hyper-V
    By Disease in forum Thin Client and Virtual Machines
    Replies: 5
    Last Post: 22nd February 2011, 01:27 PM
  4. [Video] If you want to feel good about yourself!
    By Paul_L in forum Jokes/Interweb Things
    Replies: 4
    Last Post: 27th February 2010, 08:43 PM
  5. Replies: 4
    Last Post: 6th November 2008, 02:42 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •