[Gambas-user] Numeric operation between strings.

user demosthenesk at ...626...
Mon Nov 8 11:36:27 CET 2010


ok i see this but

CStr(-19776) output is it a string?

for example i think there is difference between

DIM sVar1="-19776" AS String
DIM iVar2=-19776 AS Integer

why Gambas re-convert a string to integer again when see a + operator?

The statement
PRINT CStr(-19776) + CStr(-19776)

should be equal to

PRINT ("-19776" + "-19776")

and raise an error, strings cannot be sumed.

This function of Gambas seems to reconvert strings to numbers with +
operator.

Should be this happend?


On Mon, 2010-11-08 at 10:31 +0100, Caveat wrote:
> Well CStr(-19776) gives -19776 so if you use the arithmetic addition
> operator you're gonna get -19776 plus -19776 giving -39552.
> 
> Using the arithmetic operator in this case only works if both your
> strings can be treated as floats, so this will raise an error:
> 
> PRINT CStr(-19776) + CStr("W")
> 
> If you used the ampersand (&) instead, like this:
> 
> PRINT CStr(-19776) & CStr(-19776)
> 
> you'd've gotten the expected(?) result of:
> 
> -19776-19776
> 
> and:
> 
> PRINT CStr(-19776) & CStr("W")
> 
> would not fail, but give:
> 
> -19776W
> 
> Regards,
> Caveat
> 
> On Mon, 2010-11-08 at 10:51 +0200, user wrote:
> > Hi to all and good morning.
> > 
> > I have this code
> > 
> > PRINT CStr(-19776) + CStr(-19776)
> > 
> > and i get -39552
> > 
> > How this is possible? Numeric operations between Strings?
> > 
> > 
> > 
> > 
> > ------------------------------------------------------------------------------
> > The Next 800 Companies to Lead America's Growth: New Video Whitepaper
> > David G. Thomson, author of the best-selling book "Blueprint to a 
> > Billion" shares his insights and actions to help propel your 
> > business during the next growth cycle. Listen Now!
> > http://p.sf.net/sfu/SAP-dev2dev
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> 
> 
> 
> ------------------------------------------------------------------------------
> The Next 800 Companies to Lead America's Growth: New Video Whitepaper
> David G. Thomson, author of the best-selling book "Blueprint to a 
> Billion" shares his insights and actions to help propel your 
> business during the next growth cycle. Listen Now!
> http://p.sf.net/sfu/SAP-dev2dev
> _______________________________________________
> 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