Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Array not working

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,52868
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Array not working
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Array not working - 10/21/2007 1:02:49 AM   
  stinesondre

 

Posts: 2
Score: 0
Joined: 10/21/2007
Status: offline
I have a textfile with some text in it. This textfile is sorted like this:

printername;sharename;location;description
printername;sharename;location;description
printername;sharename;location;description
printername;sharename;location;description
.
.
.
I have a vbs script where I need to read this textfile, and put the text into an array. I need to split each line in the textfile into several peaces like this;
arrServiceList = Split(strNextLine , ";").
I then need to put each of this 4 variables into an array. Then I need to give them them names. For example printers (0) = printername,
printer(1) = sharename and so on.. Then I have another array that write this info onto a htm page. I need to get this information (all of the printers array) over to this array. This textfile can get very
large, so the printers array needs to grow as the script goes on..
I have tried, but there is something wrong, and I do not get all of the information from the textfile onto the htm page..

Can someone help me with this ?

PS! If someone has got a better idea getting the information from the textfile, and onto the htm page please let me know !!

< Message edited by stinesondre -- 10/21/2007 1:18:59 AM >
 
 
Post #: 1
 
 RE: Array not working - 10/21/2007 4:11:34 AM   
  DiGiTAL.SkReAM


Posts: 1147
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
Post the code that you already have, so that we can see where you're going wrong, and get a better idea of how to help you.

_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to stinesondre)
 
 
Post #: 2
 
 RE: Array not working - 10/21/2007 4:18:50 AM   
  ehvbs

 

Posts: 2065
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi stinesondre,

you could use databinding to put your text file - as a recordset - into a HTML table
object, but the easiest way in my opinion would be something like this:


      

Using .ReadLine for each line of the text file and writing it with HTML tags instead of
separators to the the html file avoids arrays that are reluctant to grow.

Good luck!

ehvbs

(in reply to stinesondre)
 
 
Post #: 3
 
 RE: Array not working - 10/21/2007 4:22:27 PM   
  stinesondre

 

Posts: 2
Score: 0
Joined: 10/21/2007
Status: offline
Thank you for the quick reply. Here is the code where I try to read the data into the arrays :

Dim objRootDSE, objConnection, objCommand, strDomain, Printers
  Dim objRecordSet, objPrinterSet, objComputer,oArgs, objTextFile
  Dim strPrinterShareName, strRoomID, strDescription, strLocation, strNextLine
  Dim intPrintArrStart, arrServiceList, objFSO, DisplayName, printserver
  Const fileRead = 1
  
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objTextFile = objFSO.OpenTextFile ("c:\getPrinters.txt", fileRead)
  
  Do Until objTextFile.AtEndOfStream
     strNextLine = objTextFile.Readline
     arrServiceList = Split(strNextLine , ";")
     Redim Printers(0)
     
     intPrintArrStart = Ubound(Printers)
     
     For i = 0 to Ubound(arrServiceList)
         'WScript.Echo "i = "& i & " " & arrServiceList(i)
         strPrinterShareName = arrServiceList(0)
         DisplayName = arrServiceList(1)
         printserver = arrServiceList(2)
         strLocation = arrServiceList(3)         
         strDescription = arrServiceList(4)
         
        ReDim Preserve Printers(intPrintArrStart + 5)

       Printers(intPrintArrStart + 0) = DisplayName    ' "DisplayName"
       Printers(intPrintArrStart + 1) = strPrinterShareName  ' "PrinterShare"
       Printers(intPrintArrStart + 2) = printserver    ' "PrintServer"
       Printers(intPrintArrStart + 3) = strRoomID     ' "RoomID"
      Printers(intPrintArrStart + 4) = strDescription    ' "Comment"
      intPrintArrStart = intPrintArrStart + 1
     Next
     
     Loop
     
     'MsgBox IsArray(Printers)
           
     
  i = 0
  
  ReDim printerArray(i)
  For Each tmpArr in Printers
    'MsgBox printerArray(i)
    MsgBox tmpArr
    'printerArray(i) = tmpArr
    i = i + 1
  Next

Can you guys see what I am doing wrong ?

Thank you for the help..

(in reply to stinesondre)
 
 
Post #: 4
 
 RE: Array not working - 10/22/2007 7:58:12 AM   
  ehvbs

 

Posts: 2065
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi stinesondre,

I think you are doing three things wrong:

  (1) you forgot about PrinterShareName when you described your input file

  (2) you zapped Printers for each line in your input file

          Do Until objTextFile.AtEndOfStream
              strNextLine = objTextFile.Readline
              arrServiceList = Split(strNextLine , ";")
              Redim Printers(0)

   (3) you didn't not follow the rule "keep it simple"

If you want your text file in an one dimensional array, use code like this:


      

As you can see - still no growing arrays.

Good luck!

ehvbs

(in reply to stinesondre)
 
 
Post #: 5
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Array not working Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts