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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading data from a csv into a array 1

Status
Not open for further replies.

kdg1986

Technical User
Jan 23, 2008
5
GB
Hi wonder if anyone can help me with this. I have a csv file which contains a list of prtinters and the corrosponding machine name. I have the script pull the text out into a string array (correct term?) and then have it assign the printers
printer 1 = arrstr(1)
printer 2 = arrstr(2)
etc etc

What i'm looking or hoping to do is to is not have to define each printer rather the script assigns Printer# to each valid array String. Hope I managed to explain that clearly enough.

thanks in advance.


 
Once you have it in an array, why do you need to assign the values to variables at all? Perhaps if you show us your code and tell us what you are trying to do we can be more helpful.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
DO Until pcname1 = masPC OR objtextfile.atendofstream
arrStr = split(objtextfile.ReadLine,",")
masPC = arrstr(0)
LOOP
IF pcname1 = masPC THEN
Printer1 = arrstr(1)
Printer2 = arrstr(2)

this method is working but i'm hoping to future proof the script so if the csv is update to say contain a third printer connected to a machine then it can just be read in without having to add another Printer#= to the script? I am i trying to fix something thats not broken here?
 
My question is why do you need to do:

Printer1 = arrstr(1)

at all. What do you use the Printer1 variable for? Again, without seeing your code we can't really help you.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Have a look at the UBound function.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Printer# one is used later on to give the name of the printer thats needs to be mapped.
see below:

DO Until pcname1 = masPC OR objtextfile.atendofstream
arrStr = split(objtextfile.ReadLine,",")
masPC = arrstr(0)
LOOP
IF pcname1 = masPC THEN
Printer1 = arrstr(1)
Printer2 = arrstr(2)
Printer1a = (servpath) & (Printer1)
Printer2a = (servpath) & (Printer2)

END if

objNet.AddWindowsPrinterConnection (Printer1a)
objNet.AddWindowsPrinterConnection (Printer2a)

hope thats a bit better in explaining what i'm trying to do.

thanks for the advice so far ill take a look at ubound
 
Think i've got it sussed now going to use ubound and add a seperate loop with a different split in it to add the printers should allow it go on add infintum in theory. Many thanks for all the help on this. I'll let you know how I get on.
 
On Error Resume Next

'Object Variables

SET objNet = CreateObject("WScript.NetWork")
SET objfso = CreateObject("Scripting.FileSystemObject")
SET objtextfile = objfso_OpenTextFile("C:\pmdata.csv")
Set clrprinters = objNet.EnumPrinterConnections
pcdomain = objNet.UserDomain
pcname1 = objNet.ComputerName
servpath = "\\server_name\"


'Function


For i = 0 to clrprinters.Count - 1 Step 2
objNet.RemovePrinterConnection clrprinters.Item(i+1)', true
Next

DO Until pcname1 = masPC OR objtextfile.atendofstream
arrstr = split(objtextfile.ReadLine,",")
masPC = arrstr(0)
LOOP

arrend = ubound(arrstr)
FOR pmap = 2 to arrend
Printer = (servpath) & (arrstr(pmap))
objNet.AddwindowsPrinterConnection (Printer)
Next

ObjNet.SetDefaultPrinter ((servpath) & arrstr(1))


Don't know if anyone was interested but thats the meat of the finished script. It works exactly as I wanted it to thanks for the help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top