Page 1 of 1 1
Topic Options
#196199 - 2009-10-01 05:48 PM Cnverting string to number
kmurphy Offline
Fresh Scripter

Registered: 2000-04-21
Posts: 15
Loc: Nashua, NH USA
I am able to get the size of 2 files but they are strings so I can't add their sized together. I can't find any way to convert the numeric string into it's corresponding number.
How can I convert the 2 strings to numbers so that I can add them together?
_________________________

Thanx,
Kevin Murphy

Top
#196200 - 2009-10-01 05:49 PM Re: Cnverting string to number [Re: kmurphy]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Maybe use
CInt() or CDbl()

Top
#196204 - 2009-10-01 06:32 PM Re: Cnverting string to number [Re: Witto]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Or - you could simply cast the result by starting your math with a number:
 Code:
0 + GetFileSize('file1') + GetFileSize('File2')
This "introduces" the first value as a number (integer in this case, but could be a double if you use 0.0 instead), causing the entire expression to be handled as arithmetic, rather than string concatenation.

This is a simple trick in Kix, which implies "CInt(GetFileSize())". Tricks like this can simplify code and even speed things a bit, but really deserve a comment to describe what's happening, since the result is less obvious than using explicit CInt or CDbl functions.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 363 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.054 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org