By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,582 Members | 1,694 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,582 IT Pros & Developers. It's quick & easy.

How to pull substrings from a combobox?

P: n/a
Here is my Combobx code:

Private Sub cboTo_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cboTo.SelectedIndexChanged
Dim Target As String
Dim Value As String
Target = cboTo.SelectedItem
If Target.IndexOf("BAR17") Or Target.IndexOf("FRE09") Or
Target.IndexOf("KAN10") Or Target.IndexOf("RES02") _
Or Target.IndexOf("TON01") Or Target.IndexOf("ZRI01") Then
Target = Trim((Target.Substring(Target.Length - 5)))
Else
Target = Trim((Target.Substring(Target.Length - 7)))
End If
Value = Target
End Sub

My Form1_load code:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
cboTo.Items.Clear()
cboTo.Items.Insert(0, "Gary B. - Logon ID:BAR17")
cboTo.Items.Insert(1, "Paul F. - Logon ID:FRE09")
cboTo.Items.Insert(2, "Colleen H. - Logon ID:HEM4021")
cboTo.Items.Insert(3, "John K. - Logon ID:KAN10")
cboTo.Items.Insert(4, "Anne P. - Logon ID:PET0661")
cboTo.Items.Insert(5, "Johnny P. - Logon ID:POO2223")
cboTo.Items.Insert(6, "Steve R. - Logon ID:RES02")
cboTo.Items.Insert(7, "Symitria S. - Logon ID:STE4825")
cboTo.Items.Insert(8, "Kim T. - Logon ID:TON01")
cboTo.Items.Insert(9, "Robert Z. - Logon ID:ZRI01")
End Sub

If you look at the ComboBox code above I want to trim certain amount of
characters from the string based on a 'IndexOf' check. If any of the
six 'IndexOf's are true
then I just want to pull off -5 charcters otherwise I want to pull off
-7 chararcters.

Example if the user selects: Gary B. - Logon ID:BAR17

It would pull off: BAR17

If the user selects: Anne P. - Logon ID:PET0661

It sould pull off: PET0661 but it's pulling off: T0661

Somehow it's retaining the trim of -5 each time.

Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Here is a possible solution to your problem:

///
Private Sub cboTo_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cboTo.SelectedIndexChanged
Dim Target As String
Dim Value As String
Target = cboTo.SelectedItem
'Populate Value w/ the portion of Target after the colon
Value = Target.Substring(Target.IndexOf(":") + 1)
End Sub
\\\

This way you will not have to change your code everytime you change the
items in the combobox.

HTH.
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.