Selecting Multiple Select Element Options On The Fly

Author Message
cippall

  • Total Posts : 31
  • Scores: 0
  • Reward points : 0
  • Joined: 2/3/2009
  • Status: offline
Selecting Multiple Select Element Options On The Fly Monday, January 09, 2012 12:52 AM (permalink)
0
I'm trying to enhance a select multiple element that reads the options from a computers.txt file with radio buttons or buttons that do various selections:
- select all
- select none
- select workstations
- select laptops
- select server
- select workstations+laptops

With that in mind I had to change text file from which the computers are being read to something like this(IP/COMPUTER NAME/MAC ADDRESS/ROLE):

IP - value of select options
PC NAME - text of select options
MAC ADDRESS - for usage by subroutine
ROLE - to be used for selection


192.168.0.1,PC01,00-18-F4-6C-10-BB,server
192.168.0.2,PC02,00-18-F2-6C-10-BC,laptop
192.168.0.3,PC03,00-18-F5-6C-10-BD,workstation
192.168.0.4,PC04,00-18-F1-6C-10-BE,workstation
192.168.0.5,PC05,00-18-F1-6C-10-BF,laptop
192.168.0.6,PC06,00-18-F1-6C-10-BG,workstation

What would be the best approach to achieve these types of selections?
 
#1
    Wakawaka

    • Total Posts : 456
    • Scores: 23
    • Reward points : 0
    • Joined: 8/27/2009
    • Status: offline
    Re:Selecting Multiple Select Element Options On The Fly Monday, January 09, 2012 6:25 AM (permalink)
    0
    I would recommend a class as this is what they were really designed for.  You can have the class contain all the information you need to describe the computer object and an array to hold multiple instances of the computer object.
     
    Note you will have to make Let properties or methods to allow the internal fields to me altered.
     
    Dim oComputer : Set oComputer = New Computer.Init("My computer", "192.168.1.101", "00-00-00-00-00-00", "Server") 
      
      
    With oComputer 
     Msgbox FormatString("Name: {0}, IP: {1}, Mac: {2}, Role: {3}", Array(.Name, .IPAddress, .MACAddress, .Role)) 
    End With 
      
      
    'Just makes it easier for me. 
    Private Function FormatString(ByVal sString, ByRef aParams) 
     Dim formattedString : formattedString = sString 
      
     For i=0 To UBound(aParams) 
       formattedString = Replace(formattedString, "{" & i & "}", aParams(i)) 
     Next 
     FormatString = formattedString 
    End Function 
      
      
    'Contains information about a computer object 
    Class Computer 
     Private mName 
     Private mIP 
     Private mMAC 
     Private mRole 
      
     Public Property Get Name() 
      Name  = mName 
     End Property 
      
     Public Property Get IPAddress() 
      IPAddress  = mIP 
     End Property 
      
     Public Property Get MACAddress() 
      MACAddress  = mMAC 
     End Property 
      
     Public Property Get Role() 
      Role  = mRole 
     End Property 
      
     Public Function Init(ByVal sName, ByVal sIP, ByVal sMAC, ByVal sRole) 
      mName = sName 
      mIP = sIP 
      mMAC = sMAC 
      mRole = sRole 
       
      Set Init = Me 
     End Function 
    End Class 
      
      
    

     
    #2
      cippall

      • Total Posts : 31
      • Scores: 0
      • Reward points : 0
      • Joined: 2/3/2009
      • Status: offline
      Re:Selecting Multiple Select Element Options On The Fly Tuesday, January 10, 2012 2:21 PM (permalink)
      0
      Hi,
      Thanks for the code. But I really don't know  how exactly to use it  to make those selections in the select option element.
       
      So, first I read the file's each line:
       
      Dim oComputer     : Set oComputer = New Computer
      Dim outputFSO      : Set outputFSO = CreateObject("Scripting.FileSystemObject")
      Dim outputFile       : Set outputFile = outputFSO.CreateTextFile("C:\computers.txt",True)
      Do While oFile.AtEndOfStream <> True
      strOutLine = outputFile.ReadLine
      arrIn = Split(strInLine, ",")
       
      >>And from here I'm lost:
       
      oComputer.IPAddress = arrIn(0)
      oComputer.Name = arrIn(1)
      oComputer.MACAddress = arrIn(2)
      oComputer.Role = arrIn(3)
      Loop
      outputFile.Close
      Set outputFile = Nothing
       
      Any suggestions ?
       
      #3
        Wakawaka

        • Total Posts : 456
        • Scores: 23
        • Reward points : 0
        • Joined: 8/27/2009
        • Status: offline
        Re:Selecting Multiple Select Element Options On The Fly Wednesday, January 11, 2012 4:16 AM (permalink)
        0
        For using the select element, you can use either the value of the element or the text and then loop through your collection of Computer objects and match the name to the object.  Before that though, you should check your code as a lot of it is incorrectly written.
         
        In your loop you are using oFile as a variable but you haven't declared it, you are using a completely different variable for it.  You attempt to read in the line using the variable strOutLine but then you try spliting it but you use a completely different variable, strInLine.
         
        I would correct these things before moving forward with getting the class and looking up the wanted value.
        <message edited by Wakawaka on Wednesday, January 11, 2012 4:19 AM>
         
        #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