Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking if parsing to double fails

Status
Not open for further replies.

drewdaman

Programmer
Aug 5, 2003
302
CA
hi all.
i have a button on the main menu of my application to display the largest bar code (the primary key) in use. it works fine if everything in there is a number. I have declared this field as a string because i was told to allow for changes in the scheme for bar codes... ie they might have alphanumeric characters later on.

my problem is this.. i want to check if a certain value can be converted to a double. if not, i want to call another subroutine. this is the line i try to do this in (and it doesn't work):

If CDbl(s.Fields(0).Value) Then
blah blah

here is all the code for this button:

Private Sub cmdMaxBC_Click()
Dim intMaxBC As Double
Dim intNext As Double
Dim s As ADODB.Recordset
Set s = New ADODB.Recordset
s.Open "Select BarCode from [ItemInfo]", CodeProject.Connection, adOpenStatic
If s.RecordCount = 0 Then
MsgBox ("There are no items in the inventory")
Else
intMaxBC = CDbl(s.Fields(0))
's.MoveNext
Do While Not s.EOF
If CDbl(s.Fields(0).Value) Then
intNext = CDbl(s.Fields(0).Value)
If intNext > intMaxBC Then
intMaxBC = intNext
End If
s.MoveNext
Else
MaxBCStr
End If
Loop
MsgBox ("The largest bar code in use is " & intMaxBC & ".")
End If

End Sub

thanks in advance!
drew
 
You can use the "IsNumeric" function to find whether a given expression can be evaluated as a number.

P.S. Don't use .RecordCount, loop until the .EOF is true.
 
thanks!

but why not use .recordcount, loop till eof is true? are you saying that i should go through the recordset once before doing anything??

thanks again!
drew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top