Solved

Collection problem

Posted on 2003-12-05
1
242 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] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

615 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