Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set printer default randomly

Status
Not open for further replies.

5jgibbs

IS-IT--Management
Mar 8, 2005
151
US
Code:
intHighNumber = 2
intLowNumber = 1

For i = 1 to 1
    Randomize
    intNumber = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
    
Next
Randomize
intNumber = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)

Wscript.Echo intNumber

Dim objNetwork, strLocal, strUNCPrinter1, strUNCPrinter2
strLocal = "HPLaserJet2420"
strUNCPrinter1 = "\\print-server\LAB350-HP4350-2"
strUNCPrinter2 = "\\print-server\Reg-HP4250"
Set objNetwork = CreateObject("WScript.Network") 
objNetwork.AddWindowsPrinterConnection strUNCPrinter1
objNetwork.AddWindowsPrinterConnection strUNCPrinter2
objNetwork.SetDefaultPrinter strUNCPrinter&intNumber

WScript.Quit

This does not work. It says 2 does not exist. The only line I am having trouble with is that last line. I thought & was suppose to cat together those 2. So it would technically be strUNCPrinter2 or whatever number was in intNumber.
 
[1] >strUNCPrinter&intNumber

You cannot expect a variable name be understood by this operation, can you? This is how if you want to do that kind of thing.

[tt]objNetwork.SetDefaultPrinter [red]eval("[/red]strUNCPrinter[red]"[/red] & intNumber[red])[/red][/tt]

[2] Or go for more deterministic and it is much more preferred.
[tt]
dim a
a=array("\\print-server\LAB350-HP4350-2", "\\print-server\Reg-HP4250")
[/tt]
and call it like this.
[tt]
objNetwork.SetDefaultPrinter a(intNumber - 1)
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top