array with split is reading incorrectly

  • Thread starter mls via AccessMonster.com
  • Start date
M

mls via AccessMonster.com

My code below shows run-time error 6 overflow at lot_number = farray(0).
some how the number is not captured. It should show 705302. Any thoughts?

Sub test()
FileName = "705302 build postfill 01-27-2010 sns "
Dim farray() As String
Dim lot_number As Integer
Dim Material As String
Dim Serialno As Integer

farray = Split(FileName, " ")

If (IsNumeric(farray(0))) Then
lot_number = farray(0)
Else
lot_number = 0
End If

Material = farray(1) & " " & farray(2)
'Serailno = farray(3)
MsgBox Material

If (IsNumeric(farray(4))) Then
Serialno = farray(4)
Else
Serialno = 0
End If
MsgBox Serialno
End Sub
 
M

Marshall Barton

mls said:
My code below shows run-time error 6 overflow at lot_number = farray(0).
some how the number is not captured. It should show 705302. Any thoughts?

Sub test()
FileName = "705302 build postfill 01-27-2010 sns "
Dim farray() As String
Dim lot_number As Integer
Dim Material As String
Dim Serialno As Integer

farray = Split(FileName, " ")

If (IsNumeric(farray(0))) Then
lot_number = farray(0)
Else
lot_number = 0
End If

Material = farray(1) & " " & farray(2)
'Serailno = farray(3)
MsgBox Material

If (IsNumeric(farray(4))) Then
Serialno = farray(4)
Else
Serialno = 0
End If
MsgBox Serialno
End Sub


The largest number an Interger can hild is 32,765. Declare
lot_number as a Long instead.
 
J

Jack Leach

You have lot_number declared as an integer, which is not large enough to
handle that size number. Change it to Long datatype instead.

Also, note that Serialno will fail when you get that far... it is also
declared as an integer, and you are trying to assign "01-27-2010" to it (a
string).

For the record, the general rule is to use string datatypes for
"non-calculable" numbers. For example, I'm guessing that a Lot Number and
Serial Number are not basis for a calculation, and should therefore be
handled as Strings rather than numbers.

hth
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
M

mls via AccessMonster.com

Thanks. It's is working perfectly.

Marshall said:
My code below shows run-time error 6 overflow at lot_number = farray(0).
some how the number is not captured. It should show 705302. Any thoughts?
[quoted text clipped - 25 lines]
MsgBox Serialno
End Sub

The largest number an Interger can hild is 32,765. Declare
lot_number as a Long instead.
 
M

mls via AccessMonster.com

That's good idea. I will change my serialno to string but my lot_number is
the primary key so I want to keep that as number instead of string, even if I
don't perform any calculations.


Jack said:
You have lot_number declared as an integer, which is not large enough to
handle that size number. Change it to Long datatype instead.

Also, note that Serialno will fail when you get that far... it is also
declared as an integer, and you are trying to assign "01-27-2010" to it (a
string).

For the record, the general rule is to use string datatypes for
"non-calculable" numbers. For example, I'm guessing that a Lot Number and
Serial Number are not basis for a calculation, and should therefore be
handled as Strings rather than numbers.

hth
My code below shows run-time error 6 overflow at lot_number = farray(0).
some how the number is not captured. It should show 705302. Any thoughts?
[quoted text clipped - 25 lines]
MsgBox Serialno
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top