?
Solved

Collection problem

Posted on 2003-12-05
1
Medium Priority
?
244 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 120 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

718 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