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

Splitting a string

P: 1
I've found this site really useful in the recent days as I've introduced myself to Visual Basic.

I have set myself the task of creating a calculator (similar to the Windows calculator - but more alike the calculator found on the default Mac dashboard), and have come across my first serious problem.

My problem begins with this piece of code:

Expand|Select|Wrap|Line Numbers
  1. DIM result as string
  2. DIM firstdoub as double
  3. DIM current as double
  4. DIM firststr as string
  5. DIM digstr as string
  6.  
  7. result = firstdoub + current
  8.                     TextBox4.Text = result
  9.                     firststr = result
  10.                     digstr = result
I have also declared the following:

Expand|Select|Wrap|Line Numbers
  1. Dim dig1 As String
  2. Dim dig2 As String
  3. Dim dig3 As String
  4. Dim dig4 As String
  5. Dim dig5 As String
These dig'x' strings are to be used for 7 segment digits (digital clock style digits).

My problem:

Lets assume the following:

current = 12345
firstdoub = 12345

Thus:

result = "24690"

I want to split the result string up to satisfy the following (in this case of result):

dig1 = "2"
dig2 = "4"
dig3 = "6"
dig4 = "9"
dig5 = "0"

result will be different each time so I can't simply assign a value to it.

If someone could explain how I should even approach this step I'd appreciate it, and if someone were to offer me example code, I'd appreciate that even more so.

Any help is greatly appreciated.

Thanks for your time.
Nov 27 '07 #1
Share this Question
Share on Google+
3 Replies


Expert 5K+
P: 8,434
This will be much simpler if you use an array rather than dig1, dig2 and so on.
Nov 28 '07 #2

vdraceil
100+
P: 236
...I want to split the result string up to ...
If "24690" is the string, first use Len() function to get its length, convert it into a long or integer (according to the value you get), divide the number by 10^(Len("24690")-i) to get the number in order,store it in an array--'i' varies from 1 to (Len("24690")-1). You'll get 2, 24, 246, 2469, 24690 (the last is the original number). For each number find x mod 10, where x is the numbers you've stored in an array!
All the best with your project.
Dec 9 '07 #3

Ali Rizwan
100+
P: 927
...I want to split the result string up to ...
Use mid function with a loop to split your text.
ALI
Dec 9 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.