Solved

Collection problem

Posted on 2003-12-05
1
235 Views
Last Modified: 2010-05-01

------------------------------------------------
Private Sub Form_Load()
Dim inputLine As String
 Dim values As Variant

    Set ServerInfo = New Collection
    If Dir(App.Path & "\Server.txt") <> "" Then
        Open App.Path & "\Server.txt" For Input As #1
        Do While Not EOF(1)
            Line Input #1, inputLine
            values = Split(inputLine, ",")
            Combo1.AddItem values(0)
            ServerInfo.Add inputLine, values(0)
        Loop
        Close #1
    End If

If ServerInfo.Count > 0 Then
        inputString = ServerInfo.Item(Combo1.List(0))
        Combo1.Text = Combo1.List(0)
        values1 = Split(inputString, ",")
        txtServerIP.Text = Trim(values1(1))
        txtPort.Text = Trim(values1(2))
  End If

Private Sub Combo1_Click()

Dim inputString As String
    Dim values As Variant
    If Combo1.ListIndex <> -1 Then
        inputString = ServerInfo.Item(Combo1.List(Combo1.ListIndex))
        values = Split(inputString, ",")
        txtServerIP.Text = Trim(values(1))
        txtPort.Text = Trim(values(2))
       
    End If

End Sub

-------------------------------
this is how my collection works , so my problem is how can i edit txtServerIp and txtPort and save back to the collection without adding a new collection ? what i mean is to "edit" a certain collection.. thanks
0
Comment
Question by:vbaddictor
1 Comment
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 30 total points
ID: 9885776
Just remove the old entry from the collection using the currently selected item in Combo1 as the key.  Then build a new string based the key and the ip/port and add it back to the collection.

Private Sub Command1_Click()
    Dim key As String
    Dim newEntry As String
    Dim values As Variant

    If Combo1.ListIndex <> -1 Then
        key = Combo1.List(Combo1.ListIndex)
        ServerInfo.Remove key
        newEntry = key & ", " Trim(txtServerIP.Text) & ", " & Trim(txtPort.Text)      
        ServerInfo.Add newEntry, key
    End If
End Sub
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question