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

Dimitris Anogiatis dosida at ...626...
Tue Aug 25 08:50:52 CEST 2009


MSulchan,

in http://www.gambasdoc.org/help/cat/datatypes you will find a breakdown of
the available data types
supported by Gambas2 and in http://www.gambasdoc.org/help/cat/conv the
available data conversion
functions. In this section of Gambasdoc
http://www.gambasdoc.org/help/cat/type   you will also find
datatype functions that can help you with the special cases... ie IsNULL
will detect if your variable
is null or not.

Now as for a strategy to deal with the floats...

Depending on the floating number's floating part (meaning if the number's
floating part is no more than 2 digits ie 0.90)
seeing as it represents percentage you could always multiply them * 100 and
turn them into an integer. If of course
you get a large number like 0.9999582694 multiplying it by 100 and turning
that into an integer, you'll end up with
rounded data. The other approach is to use a float type variable but then
you need to change your code to handle
floats.

With this new data about your project's input

You could try something like this...
'------------------------------------------------------------------------------------------------------------------------------------------------------
'if the value of sRain is NOT a null

if IsNull(Val(sRain)) = False  THEN

   'if the number is an integer just assign it to the iRain variable
   if IsInteger(Val(sRain)) = TRUE THEN
      iRain = Val(sRain)

     'if it's not an integer
   ELSE
      'check to see if it's a string
      SELECT CASE isString(sRain)
         CASE True

             'if it's a string check here to see which one of the
             'designated strings you have and assign a value to iRain

             if sRain = "x" then iRain = 0.4 'or anything else you want to
make it
             if sRain = "-" then iRain = 0 'or anything else you want to
make it
         CASE False

             ' if it's neither an integer nor a string, convert it into an
integer multiply it by 100 turn it assign it to the iRain variable
             iRain = Val(sRain) * 100
         CASE ELSE
      END SELECT
   ENDIF

'if the value of sRain is a null then just assign a negative integer to
iRain
ELSE
  iRain = -1
ENDIF
'------------------------------------------------------------------------------------------------------------------------------------------------------

I hope this helps a bit more

Regards
Dimitris


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

> Pada Mon, 24 Aug 2009 23:00:07 -0600
> Dimitris Anogiatis <dosida at ...626...> menulis:
>
> > 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.
>
> Thanks Dimitris and JY,
>
> Unfortunately, the possible values are more then that, it's just a
> sample.
> The values are amount of rainfall data, so it has numbers (0 to 400)
> also with floating number 0.5, 1.7, and so on.
> The field of old data on the database was set with string type, which
> "x" represent as a value less then 0.5, "-" represent as no rain, and
> NULL represent as no data.
>
> So, for temporary solution, I'll use TRY statement to exclude "x", "-",
> and NULL, but the problem is with the floating number.
> I don't know how to handle this yet.
> any idea how to solve this ?
>
> 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