PDA

View Full Version : Solved: Separating the contents of a textbox



Wire323
05-17-2006, 11:11 AM
I have a textbox that is used to enter multiple 2-digit numbers, separated by commas. I want to assign each 2-digit number to a separate string variable (or array (http://www.tek-tips.com/viewthread.cfm?qid=1231684&page=1#) element).

For example:

If the textbox contains "22,25,29,31" I want to have variables like these:

Str1 = "22"
Str2 = "25"
Str3 = "29"
Str4 = "31"

I'm sure the best way to do this would be with an array. I don't know how to go about it though. I also posted this question on tek-tips.

Any help is greatly appreciated.

OBP
05-17-2006, 11:20 AM
You can either store the values in an array or you can store them in individual strings or integer variables. Sometimes individual variables can have more meaningful names like
FirstValue
SecondValue etc
as against
Value(1)
Value(2) etc
Is the data in a field on a form?
Can you post a zipped copy of the Database (less any sensitive daa) on here?

Wire323
05-17-2006, 11:37 AM
Yes, it is a field on a form.

If I use separate variables, how would I assign each part to a different one. And how would I know how many variables to create?

It's a very large database and form, so it would take me too long to strip it down and attach it.

OBP
05-17-2006, 12:01 PM
If you do not know how many 2 digit sets you will have then an array is obviously best. What is the approximate highest number of sets you will encounter?

Wire323
05-17-2006, 12:45 PM
Probably 10.

I was able to get it working using an array, with the Split and UBound functions.

Thanks for the help.

mdmackillop
05-17-2006, 12:46 PM
Hi Wire,
Here's an Excel example, but I think it should be transferrable staight into Access.
Regards
MD

Wire323
05-17-2006, 02:17 PM
Here's what I ended up doing:

Dim strValues() As String

strValues = Split(Me.txtMultiplePorts, ",")
LastPort = UBound(strValues, 1)

CurrentPort = 0

Do While CurrentPort <= LastPort

Do some stuff
Do some more stuff
CurrentPort = CurrentPort + 1

Loop

Edited by geekgirlau 18-May-06. Reason: insert vba tags

geekgirlau
05-17-2006, 06:50 PM
Is this thread solved? If so, make sure you flag it by going to "Thread Tools" at the top of the screen.

I've edited your post to insert vba tags - makes it easier for others to read the code. When you paste (or type) code into a post, select the code text and click on the "VBA" button .

Wire323
05-18-2006, 01:56 PM
Sorry, forgot to mark it as solved.

And thanks for the VBA tags.