Solved

Pass parameters to vbscript at run time

Posted on 2011-03-03
7
1,290 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 12

Expert Comment

by:prashanthd
ID: 35026574
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
ID: 35026586
This will be part of vbscript, if you post the vbscript code, I will make the necessary changes
0
 

Author Comment

by:BigBobBK
ID: 35027485
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Assisted Solution

by:TheGorby
TheGorby earned 125 total points
ID: 35027542
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
ID: 35027630
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
ID: 35029028
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
ID: 35031332
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

729 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