Solved

Collection problem

Posted on 2003-12-05
1
233 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now