•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 455,988 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,790 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 4914 | Replies: 6
![]() |
This works, so you can write a com wrapper for it.
Option Explicit
Private Declare Function SetEnvironmentVariable Lib "kernel32" Alias "SetEnvironmentVariableA" (ByVal lpName As String, ByVal lpValue As String) As Long
Private Sub Command1_Click()
SetEnvironmentVariable "xxx", "yyy"
Shell "c:\test.bat"
'// rem bat file
'// echo %xxx%
'// rem ftp wait for input so window will stay opened
'// ftp
End Sub
Last edited by VIeditorlover : Dec 6th, 2007 at 4:55 am.
•
•
Join Date: Dec 2007
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
Vieditorlover,
Thanks for that reply. I'm quite new to scripting and I was getting compilation error. Could please explain it in bit detail..
I will tell you the scenario and the example code i'm taking here..
My .vbs file has the following code :
dim a
dim WshShell
a=inputbox("Server Name:")
if (a= "" )then
Msgbox "Please give correct input"
Else
set WshShell=Wscript.Createobject("Wscript.shell")
wshshell.run """C:\qat.bat""" ' Here I want to pass variable a
End if
My .bat file code can as simple as
@echo off
copy ss.txt + tt.txt "%1".txt
How to use your answer in this scenario??
Thanks for that reply. I'm quite new to scripting and I was getting compilation error. Could please explain it in bit detail..
I will tell you the scenario and the example code i'm taking here..
My .vbs file has the following code :
dim a
dim WshShell
a=inputbox("Server Name:")
if (a= "" )then
Msgbox "Please give correct input"
Else
set WshShell=Wscript.Createobject("Wscript.shell")
wshshell.run """C:\qat.bat""" ' Here I want to pass variable a
End if
My .bat file code can as simple as
@echo off
copy ss.txt + tt.txt "%1".txt
How to use your answer in this scenario??
•
•
Join Date: Jun 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
SOW,
Not sure why you are double-quoting your batch file name, unless it actually resides in a directory path which has embedded spaces.
If your directory path does not have embedded spaces, this will work:
wshshell.run "C:\qat.bat " & a
(ensure a space before the last double-quote and then append the variable a.)
If your directory path DOES have embedded spaces (eg, "f dir" below) then try this:
wshshell.run """C:\temp\f dir\doit.bat"" " & a
(ensure you double-up the double-quotes around the fullpath filename to the batch file.
And this will work whether you have spaces in the path or not)
In any case, it appears that your double-quote within your batch file also needs some fixing up...the double-quotes for the target file do NOT need double-spaces, unless the actual filename will have embedded spaces.
If target file will NOT have spaces in the name, this will work:
copy ss.txt + tt.txt %1.txt
If target file WILL have spaces in the name, then there will be more than one arg to the batch, so use %* to get them all, and put double-quotes after the file extension:
copy ss.txt + tt.txt "%*.txt"
(This will work whether you have spaces in the target filename or not)
Hope this helps.
Not sure why you are double-quoting your batch file name, unless it actually resides in a directory path which has embedded spaces.
If your directory path does not have embedded spaces, this will work:
wshshell.run "C:\qat.bat " & a
(ensure a space before the last double-quote and then append the variable a.)
If your directory path DOES have embedded spaces (eg, "f dir" below) then try this:
wshshell.run """C:\temp\f dir\doit.bat"" " & a
(ensure you double-up the double-quotes around the fullpath filename to the batch file.
And this will work whether you have spaces in the path or not)
In any case, it appears that your double-quote within your batch file also needs some fixing up...the double-quotes for the target file do NOT need double-spaces, unless the actual filename will have embedded spaces.
If target file will NOT have spaces in the name, this will work:
copy ss.txt + tt.txt %1.txt
If target file WILL have spaces in the name, then there will be more than one arg to the batch, so use %* to get them all, and put double-quotes after the file extension:
copy ss.txt + tt.txt "%*.txt"
(This will work whether you have spaces in the target filename or not)
Hope this helps.
•
•
•
•
Vieditorlover,
Thanks for that reply. I'm quite new to scripting and I was getting compilation error. Could please explain it in bit detail..
I will tell you the scenario and the example code i'm taking here..
My .vbs file has the following code :
dim a
dim WshShell
a=inputbox("Server Name:")
if (a= "" )then
Msgbox "Please give correct input"
Else
set WshShell=Wscript.Createobject("Wscript.shell")
wshshell.run """C:\qat.bat""" ' Here I want to pass variable a
End if
My .bat file code can as simple as
@echo off
copy ss.txt + tt.txt "%1".txt
How to use your answer in this scenario??
•
•
Join Date: Jun 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
That Worked.!! Thanks!
What if there are more than 1 variables in batch file, i.e 2 vb variables to be passed to a batach file?
SOW, I'm late in replying. Hope you figured it out already.
It's simple really...all arguments passed to a batch file are separated by spaces.
Use %1 for first argument passed to a batch file
Use %2 for 2nd argument
Use %3 for 3rd argument
Use %* to get ALL arguments in one shot.
Of course, you could also use some IF statements to test if there really is a 1st, 2nd, 3rd, etc argument, before actually trying to use the arguments.
Good luck.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Visual Basic 4 / 5 / 6 Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Convert string variable into form object in VB6
- Next Thread: Find Record


Linear Mode