Printers/read info from file

Author Message
Netguard3

  • Total Posts : 14
  • Scores: 0
  • Reward points : 0
  • Joined: 5/12/2005
  • Location: Denmark
  • Status: offline
Printers/read info from file Thursday, May 12, 2005 7:57 PM (permalink)
0
Hey Guys :)
searched the forum, but whitout luck.

I have this script:

dim oPort
dim oMaster
set oPort = CreateObject("Port.Port.1")
set oMaster = CreateObject("PrintMaster.PrintMaster.1")
oPort.PortName = "IP_10.10.2.14"
oPort.PortType = 1
oMaster.PortAdd oPort
if Err <> 0 then
msgbox "There was an error creating the port."
end if

i have the Ips, porttypes in a txt file. how can i make it read it from there? I have aroudn 50 printers listed in one file.

any ideas?
Power To The People! ;)
 
#1
    mbouchard

    • Total Posts : 2110
    • Scores: 29
    • Reward points : 0
    • Joined: 5/15/2003
    • Location: USA
    • Status: offline
    Re: Printers/read info from file Friday, May 13, 2005 1:46 AM (permalink)
    0
    You have several options, all depending on how the info is in the text file.

    If it is a comma delaminated, you can use readline, then use split to seperate the IP and porttypes. Or, you can use readall, split that into an array then split each line into another array.

    Here is a example on how to do the second option
    Const FORREADING = 1
    
    Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
    
    'Open text file for reading
    Set f = fso.OpenTextFile("test.txt", ForReading)
    
    'Read the file into a variable
    theFile = f.ReadAll
    
    'Split TheFile variable into an array, using vbcrlf as the delimiter
    MyArray =   split(theFile,vbcrLF)
    
    'Parse through the Array
    For I = 0 to Ubound(MyArray)
    'Create Array for each line in file
    MyArray2 = Split(MyArray(I),",")
    ipAddress = MyArray2(0)
    portType = MyArray2(1)
    'Do what you need to do here.
    msgbox "IpAddress = " & ipAddress & vbcr & "Port Type = " & portType
    Next
    
    
    
     
    #2
      Netguard3

      • Total Posts : 14
      • Scores: 0
      • Reward points : 0
      • Joined: 5/12/2005
      • Location: Denmark
      • Status: offline
      Re: Printers/read info from file Friday, May 13, 2005 2:30 AM (permalink)
      0
      Thx mate, that really helped alot :)

      is there away to clear the array after each line?
      Getting the error: Subscript out of Range: '[Number: 0]' when the script is done.
      but it completes the process :)

       
      #3
        Netguard3

        • Total Posts : 14
        • Scores: 0
        • Reward points : 0
        • Joined: 5/12/2005
        • Location: Denmark
        • Status: offline
        Re: Printers/read info from file Tuesday, May 17, 2005 1:22 AM (permalink)
        0
        Got it :)
        thx again :)
         
        #4

          Online Bookmarks Sharing: Share/Bookmark

          Jump to:

          Current active users

          There are 0 members and 1 guests.

          Icon Legend and Permission

          • 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
          • Read Message
          • Post New Thread
          • Reply to message
          • Post New Poll
          • Submit Vote
          • Post reward post
          • Delete my own posts
          • Delete my own threads
          • Rate post

          2000-2012 ASPPlayground.NET Forum Version 3.9