Solved

Collection problem

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

738 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