Charles Robinson
asked on
Converting batch code to VB!
Hello all,
I apologize upfront for the length of this question!
I have a batch file that I use to run some equations for a database dump.
Batch code starts here>
CMD /C
Net Use P: \\10.1.206.36\e$ /USER:"username"
P:
CD\Temp2\Temp3\cgi-bin
..\util\dumpdb userstat -trim -header -search tag psqdone -delim , -time -o "%date:/=-%"QA_REPORT.csv
..\util\dumpdb userstat -trim -header -search TAG PSQDONE -delim , -time -o "%date:/=-%"UsersDone.csv
R:
cd\Temp4\Temp Reports
MD "%date:/=-%"
copy p:\P-Synch\PS_SYNCH_USERS\ cgi-bin\"% date:/=-%" QA_REPORT. csv r:\"P-Synch\P-Synch Reports"\"%date:/=-%"\ /Y
copy p:\P-Synch\PS_SYNCH_USERS\ cgi-bin\"% date:/=-%" UsersDone. csv r:\"P-Synch\P-Synch Reports"\"%date:/=-%"\ /y
del p:\P-Synch\PS_SYNCH_USERS\ cgi-bin\"% date:/=-%" QA_REPORT. csv
del P:\P-Synch\PS_SYNCH_USERS\ cgi-bin\"% date:/=-%" UsersDone. csv
CMD /C NET USE P: /D /y
Exit
< Batch code ends here>
The ("%date:/=-%") makes a folder or file name with the system date as the name and this is where I am having the issue!
In my VBScript I have the following code that opens Excel and imports the "%date:/=-%"QA_REPORT.csv trims the columns that are not needed. The code looks like this:
>VB code Starts here >
' Option Explict
' Dim WkBkName as String
Dim oXL
Set oXL = CreateObject("Excel.Applic ation")
oXL.Visible = True
'Open the CSV
WkBkName = "C:\Reports\"%date:/=-%"\ "%date:/=-%"QA_REPORT.csv"
oXL.Workbooks.Open(WkBkNam e)
' Select the undesired columns working from right to left
' then delete them one at a time
oXL.Columns("E:E").Select
oXL.Selection.Delete
oXL.Columns("D:D").Select
oXL.Selection.Delete
oXL.Columns("C:C").Select
oXL.Selection.Delete
oXL.Columns("B:B").Select
oXL.Selection.Delete
<VB code Stops Here>
As I indicated before the folder and file dates are the issue, I can not open the folder. If I could do all of this in VBscript it would be better. Any suggestions would be appreciated!
Hello-all.doc
I apologize upfront for the length of this question!
I have a batch file that I use to run some equations for a database dump.
Batch code starts here>
CMD /C
Net Use P: \\10.1.206.36\e$ /USER:"username"
P:
CD\Temp2\Temp3\cgi-bin
..\util\dumpdb userstat -trim -header -search tag psqdone -delim , -time -o "%date:/=-%"QA_REPORT.csv
..\util\dumpdb userstat -trim -header -search TAG PSQDONE -delim , -time -o "%date:/=-%"UsersDone.csv
R:
cd\Temp4\Temp Reports
MD "%date:/=-%"
copy p:\P-Synch\PS_SYNCH_USERS\
copy p:\P-Synch\PS_SYNCH_USERS\
del p:\P-Synch\PS_SYNCH_USERS\
del P:\P-Synch\PS_SYNCH_USERS\
CMD /C NET USE P: /D /y
Exit
< Batch code ends here>
The ("%date:/=-%") makes a folder or file name with the system date as the name and this is where I am having the issue!
In my VBScript I have the following code that opens Excel and imports the "%date:/=-%"QA_REPORT.csv trims the columns that are not needed. The code looks like this:
>VB code Starts here >
' Option Explict
' Dim WkBkName as String
Dim oXL
Set oXL = CreateObject("Excel.Applic
oXL.Visible = True
'Open the CSV
WkBkName = "C:\Reports\"%date:/=-%"\ "%date:/=-%"QA_REPORT.csv"
oXL.Workbooks.Open(WkBkNam
' Select the undesired columns working from right to left
' then delete them one at a time
oXL.Columns("E:E").Select
oXL.Selection.Delete
oXL.Columns("D:D").Select
oXL.Selection.Delete
oXL.Columns("C:C").Select
oXL.Selection.Delete
oXL.Columns("B:B").Select
oXL.Selection.Delete
<VB code Stops Here>
As I indicated before the folder and file dates are the issue, I can not open the folder. If I could do all of this in VBscript it would be better. Any suggestions would be appreciated!
Hello-all.doc
ASKER
Okay that is fine and I am assuming that you are saying I could do the whole thing in VBscript. How would I run these two (2) lines in VB?
..\util\dumpdb userstat -trim -header -search tag psqdone -delim , -time -o "%date:/=-%"QA_REPORT.csv
&
..\util\dumpdb userstat -trim -header -search TAG PSQDONE -delim , -time -o "%date:/=-%"UsersDone.csv
Which are done from the command line
..\util\dumpdb userstat -trim -header -search tag psqdone -delim , -time -o "%date:/=-%"QA_REPORT.csv
&
..\util\dumpdb userstat -trim -header -search TAG PSQDONE -delim , -time -o "%date:/=-%"UsersDone.csv
Which are done from the command line
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Rob!
WkBkName = "C:\Reports\"%date:/=-%"\ "%date:/=-%"QA_REPORT.csv"
to this
WkBkName = "C:\Reports\" & Day(Now) & "-" & Month(Now) & "_QA_REPORT.csv"
This would make a file called 31-01_QA_REPORT.csv
Regards,
Rob.