[Gambas-user] type mismatch: wanted integer, got string instead

Dimitris Anogiatis dosida at ...626...
Tue Aug 25 07:00:07 CEST 2009


Hey MSulchan,

if you're trying to convert either "x", "-", or NULL
to an integer you're correctly going to get a mismatch error

basically the mismatch error is a way of saying
"I can't convert "x" into an integer, I don't know what number to convert
"x" to"

what I would personally use instead of  iRain = CInt(sRain) is a Select
statement like this one

SELECT CASE sRain
   Case  "0"
     iRain = 0
   Case  "1"
     iRain = 1
   Case  "2"
     iRain = 2
   Case  "x"
     iRain = 3
   Case  "-"
     iRain = 4
   Case  ELSE  'this case would be used in case of anything else including
null
     iRain = -1
END SELECT

this way iRain would always have an integer and you wouldn't have to worry
about
the mismatch error... assuming "0", "1", "2", "x", "-" and NULL are the only
values
used in your database.

I hope this helps

Regards
Dimitris

On Mon, Aug 24, 2009 at 10:35 PM, MSulchan Darmawan <bleketux at ...626...>wrote:

> 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.
>
> 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.
>
> Help !
> I'm using gambas2 2.8.2 on linux mint 7.
>
> Thanks in advance.
> Regards,
> Sulchan
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus
> on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
>



More information about the User mailing list