#175140 - 2007-04-01 08:02 PM
Including variables in a text string
|
jeremyschubert
Getting the hang of it
Registered: 2005-09-17
Posts: 89
|
Sorry, just want to quickly confirm something. If I have the following code MapDrives()
$Label.Text = "Please wait while the computer sets up your network drives and printers."+@CRLF
+"Your desktop will appear after this setup is complete."+@CRLF
+"The H drive has been successfully mapped to your Home Drive."
PrinterSetup()
$Label.Text = "Please wait while the computer sets up your network drives and printers."+@CRLF
+"Your desktop will appear after this setup is complete."+@CRLF
+"The H drive has been successfully mapped to your Home Drive."+@CRLF
+"Your printer has been set to [what ever printer the script designates] "
ExitButton()
While $Form.Visible
$ = Execute($Form.DoEvents())
Loop
Exit 1
Function MapDrives()
;Home Share Mapping
Use h: /delete
Use H: @HOMESHR and I want the text line to note the actuall @homeshr name (e.g. \\server\smithj) rather then the text "your home drive.", then I need to make the following modification? +"The H drive has been successfully mapped to " + @HOMESHR +"." +@CRLF
_________________________
--- Bishop Grandin Technology Department 'Either we're on time, or we're late'
|
|
Top
|
|
|
|
#175142 - 2007-04-01 08:27 PM
Re: Including variables in a text string
[Re: Mart]
|
jeremyschubert
Getting the hang of it
Registered: 2005-09-17
Posts: 89
|
Thank you. Also in my script is printer() with (a sample line): Case InStr (@wksta,"047-C111")=1
$nothing = AddPrinterConnection ($s1 + "\Epson")
$nothing = AddPrinterConnection ($s1 + "\c111")
$nothing = AddPrinterConnection ($s1 + "\Xerox")
$nothing = SetDefaultPrinter ($s1 + "\c111") I honestly can't remember where I got the '$nothing' from. It works. But in this case there are three printers listed (my other case statements only have one printer listed), so can I change the $nothing to $printer1,$printer2,$printer3,$printerdefault (assuming I declare those variables at the beginning of my script). Then I'll be able to add the actual printer names in my text rather then having to write a generic line. Is that how I should be going about this? Thanks,
_________________________
--- Bishop Grandin Technology Department 'Either we're on time, or we're late'
|
|
Top
|
|
|
|
#175145 - 2007-04-01 11:22 PM
Re: Including variables in a text string
[Re: Sealeopard]
|
jeremyschubert
Getting the hang of it
Registered: 2005-09-17
Posts: 89
|
Ok, thanks for the link. So then, the following code should be correct providing I've got Dim $printer1,$printer2,$printer3,$printerdefault at the begining of the script?
Case InStr (@wksta,"047-C111")=1
$nothing = AddPrinterConnection ($s1 + "\Epson")
$nothing=$printer1
?"Your first printer is " +$printer1
$nothing = AddPrinterConnection ($s1 + "\c111")
$nothing=$printer2
?"Your second printer is " +$printer2
$nothing = AddPrinterConnection ($s1 + "\Xerox")
$nothing=$printer3
?"Your third printer is " +$printer3
$nothing = SetDefaultPrinter ($s1 + "\c111")
$nothing=$printerdefault
? $printerdefault +" has been set as your default printer."
_________________________
--- Bishop Grandin Technology Department 'Either we're on time, or we're late'
|
|
Top
|
|
|
|
#175146 - 2007-04-01 11:44 PM
Re: Including variables in a text string
[Re: jeremyschubert]
|
jeremyschubert
Getting the hang of it
Registered: 2005-09-17
Posts: 89
|
Oh, I think I just realized. $nothing=$printer1 would only return a return code (0, 1 or 2). Instead, I need to use $printer1=($s1 + "\Xerox"). Then I could add the line ? "Your printer is " +$printer1 Is that better?
_________________________
--- Bishop Grandin Technology Department 'Either we're on time, or we're late'
|
|
Top
|
|
|
|
#175151 - 2007-04-02 05:06 AM
Re: Including variables in a text string
[Re: Sealeopard]
|
jeremyschubert
Getting the hang of it
Registered: 2005-09-17
Posts: 89
|
Sealeopard, I believe the UDF I created (see below) does basically the same thing as what you're suggesting, right? (Except for adding the error statement. When the UDF is put into action in my script, I simply added the line $Label.Text = "The printer that has been setup for you is " +$printer +@CRLF
Function PrinterSetup()
;Cases to determine available printers And which printer is default
Select
Case InStr (@wksta,"047-KandE")=1
$nothing = AddPrinterConnection ($s1 + "\KandE")
$nothing = SetDefaultPrinter ($s1 + "\KandE")
$printer = "S047-S0371-01\KandE"
Case InStr (@wksta,"047lib-")=1
$nothing = AddPrinterConnection ($s1 + "\library")
$nothing = SetDefaultPrinter ($s1 + "\library")
$printer = "S047-S0371-01\Library"
Case InStr (@wksta,"047-lib")=1
$nothing = AddPrinterConnection ($s1 + "\library")
$nothing = SetDefaultPrinter ($s1 + "\library")
$printer = "S047-S0371-01\Library"
;When extra computers set up in library For diplomas
Case InStr (@wksta,"047-lib2")=1
$nothing = AddPrinterConnection ($s1 + "\library2")
$nothing = SetDefaultPrinter ($s1 + "\library2")
$printer = "S047-S0371-01\Library2"
Case InStr (@wksta,"047C303")=1
$nothing = AddPrinterConnection ($s1 + "\c303")
$nothing = SetDefaultPrinter ($s1 + "\c303")
$printer = "S047-S0371-01\C309"
Case InStr (@wksta,"047-C303")=1
$nothing = AddPrinterConnection ($s1 + "\c303")
$nothing = SetDefaultPrinter ($s1 + "\c303")
$printer = "S047-S0371-01\C303"
Case InStr (@wksta,"047-C309")=1
$nothing = AddPrinterConnection ($s1 + "\C309")
$nothing = SetDefaultPrinter ($s1 + "\c309")
$printer = "S047-S0371-01\C309"
Case InStr (@wksta,"047-C310")=1
$nothing = AddPrinterConnection ($s1 + "\C310")
$nothing = SetDefaultPrinter ($s1 + "\c310")
$printer = "S047-S0371-01\C310"
Case InStr (@wksta,"047-careerstu")=1
$nothing = AddPrinterConnection ($s1 + "\CAREER")
$nothing = SetDefaultPrinter ($s1 + "\CAREER")
$printer = "S047-S0371-01\Career"
Case InStr (@wksta,"047-C312")=1
$nothing = AddPrinterConnection ($s1 + "\C312")
$nothing = SetDefaultPrinter ($s1 + "\c312")
$printer = "S047-S0371-01\C312"
Case InStr (@wksta,"047-C111")=1
$nothing = AddPrinterConnection ($s1 + "\Epson")
$nothing = AddPrinterConnection ($s1 + "\c111")
$nothing = AddPrinterConnection ($s1 + "\Xerox")
$nothing = SetDefaultPrinter ($s1 + "\c111")
$printer = "S047-S0371-01\C111"
Case InStr (@wksta,"047-YEAR")=1
$nothing = AddPrinterConnection ("\\047-YEARBOOK-2\Yearbook")
$nothing = SetDefaultPrinter ("\\047-yearbook-2\yearbook")
$printer = "S047-S0371-01\yearbook"
Case InStr (@wksta,"047-DRAF")=1
$nothing = AddPrinterConnection ($s1 + "\HP-GL/2 Plotter")
$nothing = SetDefaultPrinter ($s1 + "\plotter")
$printer = "S047-S0371-01\plotter"
Case InStr ("@wksta","047-REACH")=1
$nothing = AddPrinterConnection ($s1 + "\GOLDIE")
$nothing = SetDefaultPrinter ($s1 + "\goldie")
$printer = "S047-S0371-01\goldie"
Case InStr (@wksta,"047-C206")=1
$nothing = AddPrinterConnection ($s1 + "\C206")
$nothing = SetDefaultPrinter ($s1 + "\c206")
$printer = "S047-S0371-01\C206"
EndSelect
EndFunction
_________________________
--- Bishop Grandin Technology Department 'Either we're on time, or we're late'
|
|
Top
|
|
|
|
#175156 - 2007-04-02 02:09 PM
Re: Including variables in a text string
[Re: jeremyschubert]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
|
"Lookups are your friend"...
Basically, things change, printers get replaced, have new names, etc.. Your monolithic coding method will require a rewrite every time something changes. Also, using a Select statement prevents a workstation from using more than one printer. Here's some pseudo-code for an alternative method - the entire block of code is listed below:
$Config = '\\DOMAIN\netlogon\printerconfig.ini' ; put in central place
; local copy for testing, remove this when done testing !!
$Config = 'c:\mytestconfig.ini'
$StationID = Left(@WKSTA, 8) ; assumes first 8 chars define the location
; get the list of printer(s) for this station's ID
$Printers = Split(ReadProfileString($Config, 'Printers', $StationID), ';')
; Add 1 or more printer connections
For Each $Printer in $Printers
$Nothing = AddPrinterConnection($Printer)
Next
; first listed printer is the default printer
$Nothing = SetDefaultPrinter($Printers[0])
printerconfig.ini might look like this (one entry shown):
[printers]
047-DRAF=\\server\HP-GL/2 Plotter;\\server\LaserJet 4
Thus, any workstation that started with "047-draf" would have two printers mapped - a plotter and a laser printer, with the plotter set to the default. The code never changes, you update the config file, it replicates to all DCs, and any copy of your code picks up the new settings. Simple.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#175184 - 2007-04-03 07:48 AM
Re: Including variables in a text string
[Re: Glenn Barnas]
|
jeremyschubert
Getting the hang of it
Registered: 2005-09-17
Posts: 89
|
Thanks Glenn. Monolithic code? I like that term. Sounds like I might end up suffering from the gods of programming :-)))))))))))))))
Why do you say a select statement limits a workstation to one printer? Case InStr (@wksta,"047-C111")=1 $nothing = AddPrinterConnection ($s1 + "\Epson") $nothing = AddPrinterConnection ($s1 + "\c111") $nothing = AddPrinterConnection ($s1 + "\Xerox") $nothing = SetDefaultPrinter ($s1 + "\c111")
I'll take a closer look at your script tomorrow. But off the top of my head, I think your code would be more appropriate if I was the downtown tech in charge of setting up printers for all schools in the district. But as I'm only responsible for one school with only six student labs with printers and twelve or so staff printers, I don't think maintaining the select list I have is that hard (especially since there's one script for the staff side and another for the student side). And (LOL) we're talking a school here. A school that only changes printers every five or six years due to lack of money. So we don't see a lot of changes in hardware.
Jeremy
_________________________
--- Bishop Grandin Technology Department 'Either we're on time, or we're late'
|
|
Top
|
|
|
|
#175197 - 2007-04-04 02:05 AM
Re: Including variables in a text string
[Re: Glenn Barnas]
|
jeremyschubert
Getting the hang of it
Registered: 2005-09-17
Posts: 89
|
LOL
_________________________
--- Bishop Grandin Technology Department 'Either we're on time, or we're late'
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 565 anonymous users online.
|
|
|