G
Guest
Thanks for taking the time to read my question.
I have a string that I am parsing, and sticking into an array. The string
has text and numbers. I want only the numbers.
So I've tried setting my array to Double, but it is still allowing text.
What am I doing wrong?
Thanks for your help,
Brad
CODE:
====================================================
TheString = " Test Test 9 3 2"
Option Compare Database
Dim NamesArray(10) As String
Dim InventoryArray(10), SowsBredWeekArray(10), SowsFarrowWeekArray(10),
PigsWeanedWeekArray(10), AvgWeanAgeArray(10), BornAliveArray(10) As Double
----------------------------------------------------------------------------------------------
Sub GetSowsBredWeek(TheString As String)
Dim Result, X, Y, Z As Integer
On Error GoTo GetSowsBredWeek_Err
X = 1
Y = 0
Do Until X = Len(TheString)
Result = InStr(X, TheString, " ", vbBinaryCompare)
If Result > X + 1 Then
'The Next line is where it all happens for the first time.
'Here the Array should only accept numbers, but it will except "Test"
'"Test" should cause an error 13, Type Mismatch, go through error
handling
'skip the line and continue.
SowsBredWeekArray(Y) = Mid(TheString, X, Result - X)
Debug.Print SowsBredWeekArray(Y)
Y = Y + 1
X = Result
Else
If Result < X Then
SowsBredWeekArray(Y) = Right(TheString, Len(TheString) - (X - 1))
Debug.Print SowsBredWeekArray(Y)
X = Len(TheString)
Else
X = X + 1
End If
End If
Loop
GetSowsBredWeek_Exit:
Exit Sub
GetSowsBredWeek_Err:
If Err.Number = 13 Then
Resume Next
Else
MsgBox Err.Number
Resume GetSowsBredWeek_Exit
End If
End Sub
I have a string that I am parsing, and sticking into an array. The string
has text and numbers. I want only the numbers.
So I've tried setting my array to Double, but it is still allowing text.
What am I doing wrong?
Thanks for your help,
Brad
CODE:
====================================================
TheString = " Test Test 9 3 2"
Option Compare Database
Dim NamesArray(10) As String
Dim InventoryArray(10), SowsBredWeekArray(10), SowsFarrowWeekArray(10),
PigsWeanedWeekArray(10), AvgWeanAgeArray(10), BornAliveArray(10) As Double
----------------------------------------------------------------------------------------------
Sub GetSowsBredWeek(TheString As String)
Dim Result, X, Y, Z As Integer
On Error GoTo GetSowsBredWeek_Err
X = 1
Y = 0
Do Until X = Len(TheString)
Result = InStr(X, TheString, " ", vbBinaryCompare)
If Result > X + 1 Then
'The Next line is where it all happens for the first time.
'Here the Array should only accept numbers, but it will except "Test"
'"Test" should cause an error 13, Type Mismatch, go through error
handling
'skip the line and continue.
SowsBredWeekArray(Y) = Mid(TheString, X, Result - X)
Debug.Print SowsBredWeekArray(Y)
Y = Y + 1
X = Result
Else
If Result < X Then
SowsBredWeekArray(Y) = Right(TheString, Len(TheString) - (X - 1))
Debug.Print SowsBredWeekArray(Y)
X = Len(TheString)
Else
X = X + 1
End If
End If
Loop
GetSowsBredWeek_Exit:
Exit Sub
GetSowsBredWeek_Err:
If Err.Number = 13 Then
Resume Next
Else
MsgBox Err.Number
Resume GetSowsBredWeek_Exit
End If
End Sub