Issue with numeric fields

3 posts / 0 new
Last post
leylalkan
Offline
Joined: 11/27/2019 - 03:43
Issue with numeric fields

Hi, 
I tried to solve this issue I'm having, but couldn't find a solution.
The code I upload work very well when a user choose date fields or character fields in the dropdown boxes. However, in case of numeric fields chosen, it says that "Bad equation provided"
The part I'm talking about is the following:
If extractionType Then
If IsNumeric(acilirListeVerisi1) And IsNumeric(acilirListeVerisi2) Then
eqn = acilirListeVerisi1 & " <> " & acilirListeVerisi2
Else
eqn = "@Strip(" & acilirListeVerisi1 & ") <> @Strip(" & acilirListeVerisi2 & ")"
End If
Else
If IsNumeric(acilirListeVerisi1) And IsNumeric(acilirListeVerisi2) Then
eqn = acilirListeVerisi1 & " == " & acilirListeVerisi2
Else
eqn = "@Strip(" & acilirListeVerisi1 & ") == @Strip(" & acilirListeVerisi2 & ")"
End If
End If
I don't know why eqn = acilirListeVerisi1 & " <> " & acilirListeVerisi2 and eqn = acilirListeVerisi1 & " == " & acilirListeVerisi2 do not work. 
Note: in the dialog box, "aynı" stands for "==" and "farklı" stands for "<>"
Thanks in advance!

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi leylalkan,

The problem is using the IsNumeric is testing that what is contained in the variable is numeric.  In this case the variable contains the Field name so it will always not be numeric.  What you want to do is test that the actual field is a numeric or character field.  

To check if a field is numeric you can write a short function to do that:

function checkIfFieldIsNumeric(sFilename as string, sFieldname as string) as boolean

     Set db = Client.OpenDatabase(sFilename)

     set table = db.TableDef

     Set field = table.GetField(sFieldname)

     If field.IsNumeric then

          checkIfFieldIsNumeric = True

     else

         checkIfFieldIsNumeric = False

    end if

    Set Field = nothing

    Set Table = Nothing

    Set Db = nothing

end function

This will return true if the field is numeric and false if it is not.

leylalkan
Offline
Joined: 11/27/2019 - 03:43

Thank you! This definitely solves the problem.