Results 1 to 10 of 10
  1. #1
    4 Star Lounger
    Join Date
    May 2003
    Location
    Austin
    Posts
    401
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBS script-needs error trap (VBS-custom script)

    I need help with creating an error trap for this script.
    It's legacy code but it has created unbelieveble hardship in my workplace so I need a patch or I'll have to create a new app.

    The script takes user input (2 separate text boxes) first value and 2nd value then creates a directory and fills it with a Word doc named after and array based on the 2 input values.
    See attached text file (Where the code ends on this file just repeats for every value in the address at the top (e.g. CaseFolderA,B,C,D,E,F) The main body is all you need.

    The problem is, there is no error trap, so the wrong user input can have disasterous results.
    (e.g. I had to delete 3900 dirs and files from last week's catastrophe when someone put a hyphen in 1 of the inputs.)

    Ideally I would like to limit the array to 50 as well as sniff out the hyphens, but a readback via MsgBox on the total before file creation would do fine.
    Thanks for any <img src=/S/help.gif border=0 alt=help width=23 height=15> rendered.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: VBS script-needs error trap (VBS-custom script)

    Ummm, there are no InputBox instructions in the code snippet you posted, and nothing is being created. The code fragment tries to open all Word documents in a folder.

  3. #3
    4 Star Lounger
    Join Date
    May 2003
    Location
    Austin
    Posts
    401
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBS script-needs error trap (VBS-custom script)

    Heres the entire script.
    Hope its a little more illuminating.
    Thanks

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: VBS script-needs error trap (VBS-custom script)

    Same difference, I'm afraid. The code you posted lets the user enter a code, then tries to open all Word documents in each of 6 folders derived from the code, if they exist. No files or folders are being created.
    You could check for x being numeric:

    If Not IsNumeric(x) Then
    MsgBox "You were supposed to enter a number, you ..."
    Exit Sub
    End If

    or you could check for the presence of a hyphen:

    If InStr(x, "-") > 0 Then
    MsgBox "You were supposed to enter a number without hyphens, you ..."
    Exit Sub
    End If

  5. #5
    4 Star Lounger
    Join Date
    May 2003
    Location
    Austin
    Posts
    401
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBS script-needs error trap (VBS-custom script)

    So where would you suggest it be input?
    I hate to seem daft, but this code is funky to say the least.
    It appears to me that the actual create object line of code is at the top, with the definition below.

    Also, your code suggestion seems simple enough, how could I output the array value to the user, post validation?

    Thanks loads for your assistance

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: VBS script-needs error trap (VBS-custom script)

    Either a piece of the puzzle is missing, or we are talking at cross purposes. Array value? <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>

  7. #7
    4 Star Lounger
    Join Date
    May 2003
    Location
    Austin
    Posts
    401
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBS script-needs error trap (VBS-custom script)

    I am an idiot!
    This is the script I should've been looking at.
    It already traps hyphens, but I'd like to display an array count.
    Thanks, you saved me a few more days of angst.

  8. #8
    4 Star Lounger
    Join Date
    May 2003
    Location
    Austin
    Posts
    401
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBS script-needs error trap (VBS-custom script)

    Ok, it seems simple enough to capture the value of z and throw a message box if >50,
    but how do I get out of it when an exit sub wont work in the body of the code?

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: VBS script-needs error trap (VBS-custom script)

    (Why won't an Exit Sub work?)

    You could add a condition on z:

    If z < 50 Then
    For i = 0 to z
    ...
    Next i
    End If

  10. #10
    4 Star Lounger
    Join Date
    May 2003
    Location
    Austin
    Posts
    401
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBS script-needs error trap (VBS-custom script)

    Sorry, I've got it fixed but then decided to just recreate it in VB.
    Thanks for all your help Hans <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

Posting Permissions

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