Solved

Pass parameters to vbscript at run time

Posted on 2011-03-03
7
1,278 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
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

810 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