Passing Variable to VB Script
Moderators: JRL, Dorian (MJT support)
Passing Variable to VB Script
I'm new at the VB Script part and I need some help about passing variables to the VB Script. I want to capture info on the screen (I can do this) and send it to a label printer. I have created a VB Script that will Print what I have in the Script; however, I want to pass a variable to this part of VB Script. I have read the help files about this and it hasn't helped me. The script looks like this
COF
Let>var1=876
VBSTART
Sub PrintLabel ()
Dim DymoAddIn, DymoLabel
Set DymoAddIn = CreateObject("DYMO.DymoAddIn")
Set DymoLabel = CreateObject("DYMO.DymoLabels")
DymoAddIn.Open "C:\Program Files\Dymo Label\Label Files\Address (99010).LWL"
DymoLabel.SetAddress 1,"%var1%"
DymoLabel.SetAddress 2,"%var1%"
DymoAddIn.Print 1,TRUE
End Sub
VBEND
VBRun>PrintLabel
The present script prints %var1% instead of 876
Thanks in advance for any help
COF
Let>var1=876
VBSTART
Sub PrintLabel ()
Dim DymoAddIn, DymoLabel
Set DymoAddIn = CreateObject("DYMO.DymoAddIn")
Set DymoLabel = CreateObject("DYMO.DymoLabels")
DymoAddIn.Open "C:\Program Files\Dymo Label\Label Files\Address (99010).LWL"
DymoLabel.SetAddress 1,"%var1%"
DymoLabel.SetAddress 2,"%var1%"
DymoAddIn.Print 1,TRUE
End Sub
VBEND
VBRun>PrintLabel
The present script prints %var1% instead of 876
Thanks in advance for any help
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
Quick reponse, Changes in bold.WARNING - NOT TESTED.
Sub PrintLabel (var1)
dim var1 as String
.....
.....
.....
DymoLabel.SetAddress 1,"var1"
DymoLabel.SetAddress 2,"var1"
DymoAddIn.Print 1,TRUE
End Sub
VBEND
VBRun>PrintLabel(%var1%)
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
Printing with Dymo Labeler
I tried the above and it didn't work for what I now need.
I have tried numerous ways such as this:
Let>var1="Pablo Martini"+chr(10)+"SAMPLE Corporation"
VBSTART
Sub PrintLabel (var1)
dim var1 as String
Set DymoAddIn = CreateObject("DYMO.DymoAddIn")
Set DymoLabel = CreateObject("DYMO.DymoLabels")
DymoAddIn.Open "C:\Users\Public\Documents\DYMO Label\Label Files\Two Line.LWL"
DymoLabel.SetAddress 1,"var1"
DymoAddIn.Print 1,TRUE
End Sub
VBEND
VBRun>PrintLabel,(%var1%)
This does work:
Let>var1="Pablo Martini"+chr(10)+"SAMPLE Corporation"
VBSTART
Sub PrintLabel (var1)
Set DymoAddIn = CreateObject("DYMO.DymoAddIn")
Set DymoLabel = CreateObject("DYMO.DymoLabels")
DymoAddIn.Open "C:\Users\Public\Documents\DYMO Label\Label Files\Two Line.LWL"
DymoLabel.SetAddress 1,"Pablo Martini"+chr(10)+"SAMPLE Corporation"
DymoAddIn.Print 1,TRUE
End Sub
VBEND
VBRun>PrintLabel,(%var1%)
So, what I need is a method of passing the data to the subroutine. I know it is just a syntax thing from my various attempts. The key is the +chr(10) as I can get it to work without it. But when I do it prints all on one line and I need it to print on two lines.
I have tried numerous ways such as this:
Let>var1="Pablo Martini"+chr(10)+"SAMPLE Corporation"
VBSTART
Sub PrintLabel (var1)
dim var1 as String
Set DymoAddIn = CreateObject("DYMO.DymoAddIn")
Set DymoLabel = CreateObject("DYMO.DymoLabels")
DymoAddIn.Open "C:\Users\Public\Documents\DYMO Label\Label Files\Two Line.LWL"
DymoLabel.SetAddress 1,"var1"
DymoAddIn.Print 1,TRUE
End Sub
VBEND
VBRun>PrintLabel,(%var1%)
This does work:
Let>var1="Pablo Martini"+chr(10)+"SAMPLE Corporation"
VBSTART
Sub PrintLabel (var1)
Set DymoAddIn = CreateObject("DYMO.DymoAddIn")
Set DymoLabel = CreateObject("DYMO.DymoLabels")
DymoAddIn.Open "C:\Users\Public\Documents\DYMO Label\Label Files\Two Line.LWL"
DymoLabel.SetAddress 1,"Pablo Martini"+chr(10)+"SAMPLE Corporation"
DymoAddIn.Print 1,TRUE
End Sub
VBEND
VBRun>PrintLabel,(%var1%)
So, what I need is a method of passing the data to the subroutine. I know it is just a syntax thing from my various attempts. The key is the +chr(10) as I can get it to work without it. But when I do it prints all on one line and I need it to print on two lines.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
With VBRun you do it like this:
Let>var1=some string
VBRun>PrintLabel,var1
Or just:
VBRun>PrintLabel,some string here ....
Let>var1=some string
VBRun>PrintLabel,var1
Or just:
VBRun>PrintLabel,some string here ....
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
didn't pass the carriage return line feed.
Thats how I had as shown here:
Let>var1="Pablo Martini"+chr(10)+"SAMPLE Corporation"
VBSTART
Sub PrintLabel (var1)
Set DymoAddIn = CreateObject("DYMO.DymoAddIn")
Set DymoLabel = CreateObject("DYMO.DymoLabels")
DymoAddIn.Open "C:\Users\Public\Documents\DYMO Label\Label Files\Two Line.LWL"
DymoLabel.SetAddress 1,var1
DymoAddIn.Print 1,TRUE
End Sub
VBEND
VBRun>PrintLabel,var1
Which worked except for that it does not pass the carriage return line feed so that it is always on the same line. I need it to print on two lines. So the issue is how to pass the chr(10) to it.
Let>var1="Pablo Martini"+chr(10)+"SAMPLE Corporation"
VBSTART
Sub PrintLabel (var1)
Set DymoAddIn = CreateObject("DYMO.DymoAddIn")
Set DymoLabel = CreateObject("DYMO.DymoLabels")
DymoAddIn.Open "C:\Users\Public\Documents\DYMO Label\Label Files\Two Line.LWL"
DymoLabel.SetAddress 1,var1
DymoAddIn.Print 1,TRUE
End Sub
VBEND
VBRun>PrintLabel,var1
Which worked except for that it does not pass the carriage return line feed so that it is always on the same line. I need it to print on two lines. So the issue is how to pass the chr(10) to it.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Like so:
Let>var1=Pablo Martini%LF%SAMPLE Corporation
VBRun>PrintLabel,var1
Let>var1=Pablo Martini%LF%SAMPLE Corporation
VBRun>PrintLabel,var1
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Works now
Thanks, that did the trick. I had just figured it out, well sort of as I did it like this:
Let>var1=Pablo Martini%CRLF%SAMPLE Corporation
VBSTART
Sub PrintLabel (var1)
Set DymoAddIn = CreateObject("DYMO.DymoAddIn")
Set DymoLabel = CreateObject("DYMO.DymoLabels")
DymoAddIn.Open "C:\Users\Public\Documents\DYMO Label\Label Files\Two Line.LWL"
DymoLabel.SetAddress 1,var1
DymoAddIn.Print 1,TRUE
End Sub
VBEND
Let>VAREXPLICIT=1
VBRun>PrintLabel,%var1%
Your way is much better.
Let>var1=Pablo Martini%CRLF%SAMPLE Corporation
VBSTART
Sub PrintLabel (var1)
Set DymoAddIn = CreateObject("DYMO.DymoAddIn")
Set DymoLabel = CreateObject("DYMO.DymoLabels")
DymoAddIn.Open "C:\Users\Public\Documents\DYMO Label\Label Files\Two Line.LWL"
DymoLabel.SetAddress 1,var1
DymoAddIn.Print 1,TRUE
End Sub
VBEND
Let>VAREXPLICIT=1
VBRun>PrintLabel,%var1%
Your way is much better.
Need more vbscript help
I am still having difficulty in passing variables to vbscript
For instance this does not work (I have tried numerous variations of it)
This does work:
Let>var1=78971
Let>var2="C:\Users\Public\Documents\DYMO Label\Label Files\Small (30330, 30578).LWL"
//>var2="C:\Users\Public\Documents\DYMO Label\Label Files\Small Barcode.LWL"
VBSTART
Dim var1
Dim var2
Sub PrintLabel (var1,var2)
Set DymoAddIn = CreateObject("DYMO.DymoAddIn")
Set DymoLabel = CreateObject("DYMO.DymoLabels")
Set myLabel = CreateObject("DYMO.DymoLabels")
DymoAddIn.Open var2
myLabel.SetField "BARCODE", "var1"
DymoAddIn.Print 1,TRUE
End Sub
VBEND
VBRun>PrintLabel,(%var1%,%var2%)
It is not the script as when I put the values directly in the scrip they work. I would ideally like to send three values to it. Where it says "BARCODE" in the script I would like that to be a varialbe as well, but if I cannot get two to work I know three is out of the question.
For instance this does not work (I have tried numerous variations of it)
This does work:
Let>var1=78971
Let>var2="C:\Users\Public\Documents\DYMO Label\Label Files\Small (30330, 30578).LWL"
//>var2="C:\Users\Public\Documents\DYMO Label\Label Files\Small Barcode.LWL"
VBSTART
Dim var1
Dim var2
Sub PrintLabel (var1,var2)
Set DymoAddIn = CreateObject("DYMO.DymoAddIn")
Set DymoLabel = CreateObject("DYMO.DymoLabels")
Set myLabel = CreateObject("DYMO.DymoLabels")
DymoAddIn.Open var2
myLabel.SetField "BARCODE", "var1"
DymoAddIn.Print 1,TRUE
End Sub
VBEND
VBRun>PrintLabel,(%var1%,%var2%)
It is not the script as when I put the values directly in the scrip they work. I would ideally like to send three values to it. Where it says "BARCODE" in the script I would like that to be a varialbe as well, but if I cannot get two to work I know three is out of the question.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
VBRun takes this format:
VBRun>SubName,parm1,parm2,parm3,....,parmn
Where parm1 to parmn are NATIVE format values separated by commas.
E.g.:
Let>somestring=This is a native string
VBRun>MySub,somestring
VBRun runs a VBscript subroutine and passes in a native MacroScript value or variable.
VBEval on the other hand is subtly different - as it's name suggests it *evaluates* a VBScript expression. As such ALL of the expression must be VBScript syntax. As such strings passed into the function need to be quoted as VBScript strings. So you would need to do:
Let>somestring=This is a native string
VBEval>MyFunc("%somestring%"),result
So cutting to the chase the syntax you need to run your PrintLabel subroutine needs to be just:
VBRun>PrintLabel,var1,var2
Where var1 and var2 can be defined just as regular Macro Scheduler values:
Let>var1=78971
Let>var2=C:\Users\Public\Documents\DYMO Label\Label Files\Small (30330, 30578).LWL
So:
Let>var1=78971
Let>var2=C:\Users\Public\Documents\DYMO Label\Label Files\Small (30330, 30578).LWL
VBRun>PrintLabel,var1,var2
With VBRun, just specify the parms after commas and do nothing special with them as you are giving VBRun regular Macro Scheduler format values.
With VBEval remember that you must provide a VBScript expression so passing Macro Scheduler values in needs some extra work (e.g. to quote them). In short you do NOT need to quote strings in VBRun.
VBRun>SubName,parm1,parm2,parm3,....,parmn
Where parm1 to parmn are NATIVE format values separated by commas.
E.g.:
Let>somestring=This is a native string
VBRun>MySub,somestring
VBRun runs a VBscript subroutine and passes in a native MacroScript value or variable.
VBEval on the other hand is subtly different - as it's name suggests it *evaluates* a VBScript expression. As such ALL of the expression must be VBScript syntax. As such strings passed into the function need to be quoted as VBScript strings. So you would need to do:
Let>somestring=This is a native string
VBEval>MyFunc("%somestring%"),result
So cutting to the chase the syntax you need to run your PrintLabel subroutine needs to be just:
VBRun>PrintLabel,var1,var2
Where var1 and var2 can be defined just as regular Macro Scheduler values:
Let>var1=78971
Let>var2=C:\Users\Public\Documents\DYMO Label\Label Files\Small (30330, 30578).LWL
So:
Let>var1=78971
Let>var2=C:\Users\Public\Documents\DYMO Label\Label Files\Small (30330, 30578).LWL
VBRun>PrintLabel,var1,var2
With VBRun, just specify the parms after commas and do nothing special with them as you are giving VBRun regular Macro Scheduler format values.
With VBEval remember that you must provide a VBScript expression so passing Macro Scheduler values in needs some extra work (e.g. to quote them). In short you do NOT need to quote strings in VBRun.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Best Explanation ever
Thanks, this is the best explanation so far on this. Perhaps it could be added to the help file on the next release.
It now works and had no issues passing the other variable to it.
Perhaps it is because I usually use VBEval that I was not catching on.
It now works and had no issues passing the other variable to it.
Perhaps it is because I usually use VBEval that I was not catching on.