[Gambas-user] type mismatch: wanted integer, got string instead
Jean-Yves F. Barbier
12ukwn at ...626...
Tue Aug 25 07:03:16 CEST 2009
MSulchan Darmawan a écrit :
> Dear sir,
>
> I have the following code :
>
> DIM sRain AS String
> DIM iRain AS Integer
> DIM iPos AS Integer
> DIM iYear AS String
> DIM iMonth AS String
>
> modMain.Connect
> hRes = modMain.$Con.Exec("SELECT * FROM table")
>
> FOR EACH hRes
>
> iPos = hRes!id
> iYear = hRes!yr
> iMonth = hRes!mn
> sRain = hRes!r1
>
> ' PRINT iPos, iYear, iMonth, sRain
> iRain = CInt(sRain)
> IF iRain > 100 THEN PRINT iPos, iYear, iMonth
>
> NEXT
>
> on this line : iRain = CInt(sRain)
> I got the type mismatch error.
> This is my first try to program on gambas.
> So why the error happened ? Any suggestion to fix are welcome.
Because you don't feed CInt() with an integer
> FYI, the database connected successfully, hRes!r1 is a string, sRain is
> a string, and I'd like to get the integer value of sRain.
> The possible value of sRain is : "0", "1", "2", "x", "-", NULL.
^^^^^^^^^^^^^^
Those aren't integer!
May be you're trying to convert an ASCCI to its DECIMAL value in the
ASCII table: Asc("x")
You can't ask a converter to convert "x" or "-" to a number: they are not,
so it is not possible.
And once for all, NULL is NOT a value: it is... NULL, so it need a separate
processing: IsNull("something")
SELECT CASE iRain
CASE IsNull(iRain)
' Do something
CASE IsAscii(iRain)
' Do another thing
...
END SELECT
JY
--
More information about the User
mailing list