[Gambas-user] type mismatch: wanted integer, got string instead
Dimitris Anogiatis
dosida at ...626...
Tue Aug 25 12:29:32 CEST 2009
Fabien,
if IsInteger(Val(sRain)) turns out to be false
the select statement will check whether it's either an "x" or a "-"
if that is also false then it must be a float.
but looking at your remarks and taking a second look at my code I see now
where I was wrong.
'------------------------------------------------------------------------------------------------------------------------------------------------------
'if the value of sRain is NOT a null
if IsNull(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 sRain
CASE "x"
iRain = 40 'or anything else you want to make it
CASE "-"
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 think this will work much better.
give it a try MSulchan and tell me if it works for you
Performance is always a multifaceted issue...
if MSulchan wants to squeeze every ounce of performance out of that
piece of code all he has to do is change the select statement into
a few if/then statements like the ones below:
if sRain ="x" then iRain = 40
if sRain = "-" then iRain = 0
if Comp(sRain, "x") <> 0 and Comp(sRain, "-") <> 0 THEN iRain =
Val(sRain)*100
But thanks Fabien for picking up on my mistakes.
Regards
Dimitris
On Tue, Aug 25, 2009 at 3:38 AM, Fabien Bodard <gambas.fr at ...626...> wrote:
> if IsInteger(Val(sRain)) = TRUE THEN
> iRain = Val(sRain)
>
> 'if it's not an integer
> ELSE
>
>
> and if it's not an integer ? ... a float for exemple...
>
>
> and be carefull ... select case if more slow than if then
>
>
> why did you convert a string into a val to see if it is a string ???
>
>
>
>
>
> 2009/8/25 MSulchan Darmawan <bleketux at ...626...>:
> > Pada Tue, 25 Aug 2009 00:50:52 -0600
> > Dimitris Anogiatis <dosida at ...626...> menulis:
> >
> >> I hope this helps a bit more
> >
> > Great... this is more reasonable...
> > I'll try it first...
> > Thank you guys...
> >
> > --
> > Cheers,
> > [-Sulchan-]
> > Terbang dengan claws-mail 3.7.2
> > Mendarat di hardy heron 8.04.3 LTS
> >
> >
> ------------------------------------------------------------------------------
> > 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
> >
> >
>
>
> ------------------------------------------------------------------------------
> 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