473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to pull substrings from a combobox?

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
1 2955
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Leandro Pardini | last post by:
Hello there, I'm trying to process a binary file and I really don't know how. The story: gPhoto2 downloads the images from my camera just fine, but small areas of 10x3 pixels are screwed up. I...
9
by: C3 | last post by:
I have to process some data in C that is given to me as a char * array. I have a fairly large number of substrings (well, they're not actually printable, but let's treat them as strings) that I...
0
by: SQLCE Server | last post by:
Not sure this is the right group to post to - but any help would be appreciated. I'm developing in VB.NET Compact Framework. I want to be able to pull data out of a SQLCE database on the mobile...
2
by: Jeremy Dillinger | last post by:
I have a program setup to pull data from a database. My database table has things such as (category, Item, price, etc.) In my program I want to have multiple list boxes that will have a pull down...
10
by: Ivan V via DotNetMonster.com | last post by:
Hi All: How can I activate the spacebar to pull down the combobox? For instance, once the tab stopped at the combobox, suppose i can use dnarrow or F4 to pull down the combobox to make...
1
by: kieran | last post by:
Hi, I have a string Array called Groups and this has x number of groups. Each row of the Array is divided up by ';' and has the name of the group in the second position (i.e. after the first...
4
by: Robert Dodier | last post by:
Hello all, I'm trying to find substrings that look like 'FOO blah blah blah' in a string. For example give 'blah FOO blah1a blah1b FOO blah2 FOO blah3a blah3b blah3b' I want to get three...
8
by: girish | last post by:
Hi, I want to generate all non-empty substrings of a string of length >=2. Also, each substring is to be paired with 'string - substring' part and vice versa. Thus, gives me , , , , , ] etc....
2
by: Pilcrow | last post by:
This problem was raised in comp.lang.perl.misc, and the poster was concerned, among other things, by the speed of execution. Since C is faster than perl, I wonder how a C coder would solve it? ...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.