Solved

Pass parameters to vbscript at run time

Posted on 2011-03-03
7
1,269 Views
Last Modified: 2012-06-27
I have a vbs that splits a large data file (with multiple days data) into to smaller files by individual dates.  My problem is now I have to edit a batch file that calls the vbs with following arguments in that batch file:  1. Name of file to split  2. Store number at beginningof file name generated by vbs & 3. finally "-DA after store number.

 Here is the command in the batch file I am manually editing (cscript FT3000Split.vbs RLG110301.E_R BK12345-DA).

Instead of having to constantly edit the batch file for every file I would like some sort of gui that I could enter the name of the file to split (RLG110301.E_R), and the store name (BK12345).  The gui code would take these 2 inputs plus add "-DA" at end of store name and then call the FT3000Split.vbs.

Can anyone help me with this?
0
Comment
Question by:BigBobBK
  • 3
  • 2
  • 2
7 Comments
 
LVL 12

Expert Comment

by:prashanthd
Comment Utility
You can use input box, this will prompt

fname=InputBox("Enter name of file to split")
sname=InputBox("Enter store name")

sname = sname & "-DA"


0
 
LVL 12

Expert Comment

by:prashanthd
Comment Utility
This will be part of vbscript, if you post the vbscript code, I will make the necessary changes
0
 

Author Comment

by:BigBobBK
Comment Utility
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 11

Assisted Solution

by:TheGorby
TheGorby earned 125 total points
Comment Utility
I noticed you put AutoIT as a tag, if the that's the only line in your batch script then this AutoIT code will work and you don't even need the batch script.

This script is nice because after running it, it will ask you if you want to run again and prompt to enter a new filename/storename.
Dim $filename,$storename

$filename=InputBox("Filename?","Enter the filename you wish to split:","","",250,140)
$storename=InputBox("Storename?","Enter the storename:","","",250,140)

_Split($filename,$storename)

Func _Split($fn,$sn)
	Run(@ComSpec & " /c cscript.exe FT3000Split.vbs " & $fn & " " & $sn & "-DA)
	$again=MsgBox(5+32+0+0+0,"Completed","The split procedure is finished." & @LF & @LF & "Select Retry to run again or Cancel to quit.")
	If $again=4 Then
		$filename=InputBox("Filename?","Enter the filename you wish to split:","","",250,140)
		$storename=InputBox("Storename?","Enter the storename:","","",250,140)
		_Split($filename,$storename)
	Else
		Exit
	EndIf
EndFunc

Open in new window

0
 
LVL 11

Expert Comment

by:TheGorby
Comment Utility
FYI on my script you may have to provide the full path to the VBS file, and if the path contains spaces you'll need to quote it as in the example below:
Run(@ComSpec & " /c cscript.exe ""C:\Program Files\Folder\FT3000Split.vbs"" " & $fn & " " & $sn & "-DA)

Open in new window

0
 
LVL 12

Accepted Solution

by:
prashanthd earned 125 total points
Comment Utility
Hi,

I had added additional functionality,where it will ask if you would like to continue, to add or run script again.

Please try...
' Define needed constants
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2

' Get input file name from command line parm
'If (WScript.Arguments.Count > 0) Then
'  sInfile = WScript.Arguments(0)
'  sOutfile = WScript.Arguments(1)
'Else
'  WScript.Echo "No filename specified."
'  WScript.Quit
'End If

status=True

Do While status=True
    
    checkval=MsgBox("Do you want to continue?",vbYesNo)
    
    If checkval = 6 Then

        sInfile = Trim(InputBox("Enter the name of file to split"))
        sOutfile =Trim(InputBox("Enter the store name"))
        
        sOutfile=sOutfile & "-DA" 
        
        ' Create file system object
        Set oFSO = CreateObject("Scripting.FileSystemObject")
        
        ' Open input file for reading
        Set oInfile = oFSO.OpenTextFile(sInfile, ForReading, False, TriStateUseDefault)
        
        ' Get path for output files
        Set oTemp = oFSO.Getfile(sInfile)
        sPath = oTemp.ParentFolder
        Set oTemp = Nothing
        
        ' Read input file, split chunks to seperate files
        dLastDate = DateValue("01/01/2000")
        dLastTime = TimeValue("03:45:00")
        sStamp = Right(Year(dLastDate), 2) & Right("0" & Month(dLastDate), 2) & Right("0" & Day(dLastDate), 2)
        Set oOutFile = oFSO.OpenTextFile(sPath & "\" & sStamp & ".E_R", ForWriting, True)
        Do While Not oInFile.AtEndOfStream
            sRead = oInFile.ReadLine
            aToken = Split(sRead, ",")
            dThisDate = DateValue(Trim(aToken(1)))
            dThisTime = TimeValue(Replace(Replace(Trim(aToken(4)), "AM", " AM"), "PM", " PM"))
            If dThisDate <> dLastDate Then
                If dThisTime > dLastTime Then
                    dLastDate = dThisDate
                    oOutFile.Close
                    sStamp = Right(Year(dThisDate), 2) & Right("0" & Month(dThisDate), 2) & Right("0" & Day(dThisDate), 2)
                    Set oOutFile = oFSO.OpenTextFile(sPath & "\" &soutfile & sStamp & ".E_R", ForWriting, True)
                End If
            End If
            oOutFile.WriteLine(sRead)
        Loop
        
        ' Cleanup and end
        oInfile.Close
        Set oInfile = Nothing
        If Not oOutFile Is Nothing Then 
            oOutFile.Close
            Set oOutFile = Nothing
        End If
        Set oFSO = Nothing
        'WScript.Quit
        
    Else
        
        Exit Do
        
    End If
        
Loop

Open in new window

0
 

Author Closing Comment

by:BigBobBK
Comment Utility
prashanthd had clean solution by editing vbs script. I like only 1 file.  TheGorby's solution did work also as well.  Both solutions were great.  Thanks to both of you.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now