Solved

Pass parameters to vbscript at run time

Posted on 2011-03-03
7
1,284 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
Technology Partners: 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

738 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