Results 1 to 6 of 6

Thread: splitting a number

  1. #1
    Guest

    Unhappy

    Help, I'm trying to split a 3 digit number into 3 seperate variables.
    Here is the snippet of code:

    Select Case F1TOT
    Case 1 To 9 'THIS IS GOOD
    F1Tot1 = Right(F1TOT, 1)
    F1Tot2 = "NULL"
    F1Tot3 = "NULL"
    Case 10 To 99 'THIS IS GOOD
    F1Tot1 = Right(F1TOT, 1)
    F1Tot2 = Left(F1TOT, 1)
    F1Tot3 = "NULL"
    Case 100 To 999 'THIS IS BAD
    F1Tot1 = Right(F1TOT, 1)
    F1Tot2 = Mid(F1TOT, 2, 1)
    F1Tot3 = Left(F1TOT, 1)
    Case Else
    End Select


    I need to solve this really quick. Any ideas?

    Thanks

  2. #2
    Guest
    Are you just trying to, for example

    A = 123

    and you want

    B = 1
    C = 2
    D = 3

    is that what you are trying to do?


    Sunny

  3. #3
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    try this:

    Code:
    Dim var1, var2, var3 As Integer
    Dim myNum As String
    myNum = 123
    MsgBox Len(myNum)
    Select Case Len(myNum)
    Case 0
    Debug.Print "Variable Needed"
    Case 1
    var1 = Left(myNum, 1)
    MsgBox var1
    Case 2
    var1 = Left(myNum, 1)
    var2 = Mid$(myNum, 2, 1)
    MsgBox var1
    MsgBox var2
    Case 3
    var1 = Left(myNum, 1)
    MsgBox var1
    var2 = Mid$(myNum, 2, 1)
    MsgBox var2
    var3 = Right(myNum, 1)
    MsgBox var3
    Case Else
    End Select

  4. #4
    Guest

    Cool splitting numbs

    Thanks. It looks like the problem was not using mid$. I was using mid. Anyhow, it works now!

  5. #5
    Member
    Join Date
    Feb 2000
    Location
    Toronto, Canada
    Posts
    44
    Try this,

    Code:
    Dim iF1TOT(3) As Integer
    Dim F1TOT As String
    Dim counter As Integer
    
    F1TOT= 123 
    
    For counter =1 To len(F1TOT)'use 3 for three digits only
        iF1TOT(counter) = Val(mid(F1TOT,counter,1))
    Next counter
    Where;

    F1TOT whole number as a string
    iF1TOT(1) most significant digit as integer
    iF1TOT(2) middle number as integer
    iF1TOT(3) least significant digit as integer

    [Edited by Sacred_knight on 05-03-2000 at 08:03 AM]

    [Edited by Sacred_knight on 05-03-2000 at 09:41 AM]
    Sacred_Knight
    Electronic Technologist
    E-Mail: [email protected]

    He who laughs last, laughs later.

  6. #6
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    yeah, but mid does it too, my code was a simplified version of yours, (that worked)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width