Joey Joey - 1 year ago 63 Question

How can i check for a character after certain text within a listbox?

How can i check for a character after other text within a listbox?

Listbox contents:

Key1: V

Key2: F

Key3: S

Key4: H

How do I find what comes after Key1-4:?

Key1-4 will always be the same however what comes after that will be user defined.

I figured out how to save checkboxes as theres only 2 values to choose from, although user defined textboxes is what im struggling with. (I have searched for solutions but none seemed to work for me)


If ListBox1.Items.Contains("Key1: " & UsersKey) Then
TextBox1.Text = UsersKey
End If

would then contain
/ whatever the user defined.

I did try something that kind of worked:

Dim UsersKey as string = "V"
If ListBox1.Items.Contains("Key1: " & UsersKey) Then
TextBox1.Text = UsersKey
End If

but i'm not sure how to add additional letters / numbers to
, then output that specific number/letter to the textbox. (I have special characters blocked)

Reasoning I need this is because I have created a custom save settings which saves on exit and loads with form1 as the built in save settings doesn't have much customization.
e.g Can't choose save path, when filename is changed a new user.config is generated along with old settings lost.

Answer Source

You have multiple keys, I assume you have multiple textboxes to display the results?

Then something like this would work. Loop thru the total number of keys, inside that you loop thru the alphabet. When you find a match, output to the correct textbox:

    Dim UsersKey As String
    For i As Integer = 1 To 4
        For Each c In "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray()
            UsersKey = c
            If ListBox1.Items.Contains("Key" & i & ": " & UsersKey) Then
                Select Case i
                    Case 1
                        TextBox1.Text = UsersKey
                    Case 2
                        TextBox2.Text = UsersKey
                    Case 3
                        TextBox3.Text = UsersKey
                    Case 4
                        TextBox4.Text = UsersKey
                End Select
                Exit For 'match found so exit inner loop
            End If

Also, you say your settings are lost when the filename is changed. I assume when the version changes? The Settings has an upgrade method to read from a previous version. If you add an UpgradeSettings boolean option and set it to True and then do this at the start of your app, it will load the settings from a previous version:

    If My.Settings.UpgradeSettings = True Then
        My.Settings.UpgradeSettings = False
    End If
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download