|
-
May 2nd, 2000, 02:03 PM
#1
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
-
May 2nd, 2000, 02:09 PM
#2
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
-
May 2nd, 2000, 03:02 PM
#3
Conquistador
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
-
May 2nd, 2000, 06:44 PM
#4
splitting numbs
Thanks. It looks like the problem was not using mid$. I was using mid. Anyhow, it works now!
-
May 2nd, 2000, 07:01 PM
#5
Member
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.
-
May 4th, 2000, 03:02 PM
#6
Conquistador
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|