Splitting a string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • diese1
    New Member
    • Nov 2007
    • 1

    Splitting a string

    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:

    Code:
    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:

    Code:
    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.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    This will be much simpler if you use an array rather than dig1, dig2 and so on.

    Comment

    • vdraceil
      New Member
      • Jul 2007
      • 236

      #3
      Originally posted by diese1
      ...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.
      Last edited by Killer42; Dec 10 '07, 12:47 AM.

      Comment

      • Ali Rizwan
        Banned
        Contributor
        • Aug 2007
        • 931

        #4
        Originally posted by diese1
        ...I want to split the result string up to ...
        Use mid function with a loop to split your text.
        ALI
        Last edited by Killer42; Dec 10 '07, 12:42 AM. Reason: Reduced excessive quote block.

        Comment

        Working...