437,594 Members | 2,016 Online 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 DIM result as string DIM firstdoub as double DIM current as double DIM firststr as string DIM digstr as string   result = firstdoub + current                     TextBox4.Text = result                     firststr = result                     digstr = result I have also declared the following: Expand|Select|Wrap|Line Numbers Dim dig1 As String Dim dig2 As String Dim dig3 As String Dim dig4 As String 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
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

 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

 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 