473,396 Members | 2,109 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,396 software developers and data experts.

Splitting a string

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
3 991
Killer42
8,435 Expert 8TB
This will be much simpler if you use an array rather than dig1, dig2 and so on.
Nov 28 '07 #2
vdraceil
236 100+
...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
925 512MB
...I want to split the result string up to ...
Use mid function with a loop to split your text.
ALI
Dec 9 '07 #4

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

Similar topics

6
by: qwweeeit | last post by:
Splitting with RE has (for me!) misterious behaviour! I want to get the words from this string: s= 'This+(that)= a.string!!!' in a list like that considering "a.string" as a word. Python...
5
by: fatted | last post by:
I'm trying to write a function which splits a string (possibly multiple times) on a particular character and returns the strings which has been split. What I have below is kind of (oh dear!)...
4
by: JeffM | last post by:
Quick C# question: I have comma delimited values in a string array that I want to pass to seperate variables. Any tips on splitting the array? Thanks in advance! JM
2
by: Trint Smith | last post by:
Ok, My program has been formating .txt files for input into sql server and ran into a problem...the .txt is an export from an accounting package and is only supposed to contain comas (,) between...
20
by: Opettaja | last post by:
I am new to c# and I am currently trying to make a program to retrieve Battlefield 2 game stats from the gamespy servers. I have got it so I can retrieve the data but I do not know how to cut up...
2
by: CharChabil | last post by:
Using Vb.net 2005, I want to read each part in this string in an array (splitting the string) ----------- A1/EXT "BK82 LB73 21233" 105 061018 1804 ----------- That Code that i used is as follow:...
6
by: HMS Surprise | last post by:
The string s below has single and double qoutes in it. For testing I surrounded it with triple single quotes. I want to split off the portion before the first \, but my split that works with...
2
by: shadow_ | last post by:
Hi i m new at C and trying to write a parser and a string class. Basicly program will read data from file and splits it into lines then lines to words. i used strtok function for splitting data to...
4
by: yogi_bear_79 | last post by:
I have a simple string (i.e. February 27, 2008) that I need to split into three parts. The month, day, and year. Splitting into a string array would work, and I could convert day and years to...
37
by: xyz | last post by:
I have a string 16:23:18.659343 131.188.37.230.22 131.188.37.59.1398 tcp 168 for example lets say for the above string 16:23:18.659343 -- time 131.188.37.230 -- srcaddress 22 ...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.