Page 1 of 1 1
Topic Options
#44422 - 2003-08-21 10:08 PM VAL function fails after 9 chars
irie89 Offline
Fresh Scripter

Registered: 2003-08-21
Posts: 9
Loc: Boston
I was hoping to use the VAL function in a script but I noticed it started giving incorrect values when it got to the 10th char. The same type of errors occur with ABS & INT. I was wondering if there's a possible fix or work around. I'm including a sample script to demonstrate issue.

$one = 9
$two = 98
$three = 987
$four = 9876
$five = 98765
$six = 987654
$seven = 9876543
$eight = 98765432
$nine = 987654321
$ten = 9876543210
$eleven = 98765432109
$twelve = 987654321098
$thirteen = 9876543210987
$fourteen = 98765432109876
$fifteen = 987654321098765
$sixteen = 9876543210987654

$valone = VAL("$one")
$valtwo = VAL("$two")
$valthree = VAL("$three")
$valfour = VAL("$four")
$valfive = VAL("$five")
$valsix = VAL("$six")
$valseven = VAL("$seven")
$valeight = VAL("$eight")
$valnine = VAL("$nine")
$valten = VAL("$ten")
$valeleven = VAL("$eleven")
$valtwelve = VAL("$twelve")
$valthirteen = VAL("$thirteen")
$valfourteen = VAL("$fourteen")
$valfifteen = VAL("$fifteen")
$valsixteen = VAL("$sixteen")

? "valeone = $valone"
? "valtwo = $valtwo"
? "valthree = $valthree"
? "valfour = $valfour"
? "valfive = $valfive"
? "valsix = $valsix"
? "valseven = $valseven"
? "valeight = $valeight"
? "valnine = $valnine"
? "valten = $valten"
? "valeleven = $valeleven"
? "valtwelve = $valtwelve"
? "valthirteen = $valthirteen"
? "valfourteen = $valfourteen"
? "valfifteen = $valfifteen"
? "valsixteen = $valsixteen"

Top
#44423 - 2003-08-21 10:11 PM Re: VAL function fails after 9 chars
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
just read the manual.
val() works on integer value and those have limits.

easiest way around is to use double values.
so, instead of:
$sixteen = 9876543210987654

use:
$sixteen = 9876543210987654.0
_________________________
!

download KiXnet

Top
#44424 - 2003-08-21 10:19 PM Re: VAL function fails after 9 chars
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Or using CDBL().
_________________________
There are two types of vessels, submarines and targets.

Top
#44425 - 2003-08-21 10:33 PM Re: VAL function fails after 9 chars
irie89 Offline
Fresh Scripter

Registered: 2003-08-21
Posts: 9
Loc: Boston
My apologies, I should have informed you that I am trying to convert a number that is in a string to a number I can perform mathematical operations on.
Top
#44426 - 2003-08-21 10:34 PM Re: VAL function fails after 9 chars
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ja.
so we quessed.

the answer is above.
that is the only way.
using longer numerical value type than integer.
_________________________
!

download KiXnet

Top
#44427 - 2003-08-21 10:43 PM Re: VAL function fails after 9 chars
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Time to read the KiXtart Manual! See page KiXtart Manual v4.21 23ff and CINT/CDBL/CSTR/VAL.
_________________________
There are two types of vessels, submarines and targets.

Top
#44428 - 2003-08-22 12:44 AM Re: VAL function fails after 9 chars
irie89 Offline
Fresh Scripter

Registered: 2003-08-21
Posts: 9
Loc: Boston
Pardon my ignorance, but either I'm just not getting it or I haven't properly explained what I'm trying to do. The big picture is that I'm trying to write a KIX script to allow our helpdesk to increase userhome quotas on a W2K server. I'm running a diskuse command to get the total amount of disk space in a userhome directory and piping the results of that to a text file. I then use SUBSTR to pull the numerical value out of the TXT file and into a STRING. I've read the manual and tried many different things, however, I can't get the syntaxt correct to convert this STRING to double values. I appreciate your help. Thanks in advance.
Top
#44429 - 2003-08-22 12:47 AM Re: VAL function fails after 9 chars
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
could you give us your current code?

simple example:
$string="3225423524634624"
$double=0.0+$string

that simple.
or the other way:
$string="3225423524634624"
$double=cdbl($string)
_________________________
!

download KiXnet

Top
#44430 - 2003-08-22 03:22 PM Re: VAL function fails after 9 chars
irie89 Offline
Fresh Scripter

Registered: 2003-08-21
Posts: 9
Loc: Boston
I tried that and it doesn't recognize $DOUBLE as a number

;*** In this section we run DISKUSE.EXE to get total bytes of Userhome
$Readfile = "\\$SERVER\QUOTAS$\READFILE.TXT"
$Writefile = "\\$SERVER\QUOTAS$\WRITEFILE.TXT"

SHELL '%comspec% /c %WINDIR%\PSEXEC.EXE \\$SERVER -u DOMAIN\USERID -p PASSWORD C:\WINNT\DISKUSE.EXE F:\USERS\$strUserHome1 /u:DOMAIN\$strUserHome1 /s /f:$ReadFile'

;* In this section we remove useless lines using YANK.EXE from the file ***
;USERID = local admin on servers
SHELL '%comspec% /c %WINDIR%\PSEXEC.EXE \\$SERVER -u DOMAIN\USERID -p PASSWORD C:\WINNT\YANK.EXE /i "$ReadFile" "DISK"'
SHELL '%comspec% /c %WINDIR%\PSEXEC.EXE \\$SERVER -u DOMAIN\USERID -p PASSWORD C:\WINNT\YANK.EXE /i "$ReadFile" "----"'
SHELL '%comspec% /c %WINDIR%\PSEXEC.EXE \\$SERVER -u DOMAIN\USERID -p PASSWORD C:\WINNT\YANK.EXE /i "$ReadFile" "USER"'

;*** In this section we read the value in and write it to new file
IF Open(3,"$Readfile", ) =0
AT(4,1)
$x = ReadLine(3)
While @Error = 0
IF Open(5, $Writefile, 5) = 0
$trimx = Trim($x)
$y = WriteLine(5,$trimx)
$z = Close(5)
ELSE
Beep
? "Writing Writefile text file failed with error code " @ERROR
SLEEP 3
ENDIF
$x = ReadLine(3)
Loop
ELSE
ENDIF
$x = Close(3)
$z = Close(5)

;** In this section we extract the number from the newly created TXT file. More importantly, we now have the number in the variable $HOMEmb

DIM $HOMEmb
DIM $HOMEbytes
DIM $HOMEbytes2

CLS

IF Open(3,"$WriteFile", ) =0
AT(4,1)
$v = ReadLine(3)
$trimv = Trim($v)

$HOMEbytes = SUBSTR("$trimv",12,25)
$DOUBLE = 0.0+ $HOMEbytes
$HOMEmb = $DOUBLE / 1048576

? "Homebytes = $HOMEbytes"
? "Double = $DOUBLE"
? "Homemb = $HOMEmb"
$v = ReadLine(3)
$v = Close(3)
SLEEP 10
ENDIF

Top
#44431 - 2003-08-22 03:34 PM Re: VAL function fails after 9 chars
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
now...
could you specify little more how you know it's not regocnized as number?

the only way to be sure would be to check it's vartype() which you don't do.
_________________________
!

download KiXnet

Top
#44432 - 2003-08-22 04:57 PM Re: VAL function fails after 9 chars
irie89 Offline
Fresh Scripter

Registered: 2003-08-21
Posts: 9
Loc: Boston
When I do a VARTYPE, $DOUBLE is a 5. I thought it wasn't being recognized as a number because nothing is displayed to the screen when I do
? "Double = $DOUBLE"

Top
#44433 - 2003-08-22 05:19 PM Re: VAL function fails after 9 chars
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Try this:
code:
? 'Vartypename = '+vartypename($DOUBLE)
? 'Double = '+$DOUBLE

_________________________
There are two types of vessels, submarines and targets.

Top
#44434 - 2003-08-22 05:27 PM Re: VAL function fails after 9 chars
irie89 Offline
Fresh Scripter

Registered: 2003-08-21
Posts: 9
Loc: Boston
$HOMEbytes = SUBSTR("$trimv",12,25)
$DOUBLE = CDBL($HOMEbytes)
$HOMEmb = CINT($DOUBLE/1048576)
? "Homebytes = $HOMEbytes" ?
? "DOUBLE = $DOUBLE" ?
? "Homemb = $HOMEmb" ?

Now shows me appropiate values for $Homebytes & more importantly $Homemb, which is the value I want. Thus I am all set. I'm just not sure why $DOUBLE is still not reporting a value.

Thank you for your help.

Top
#44435 - 2003-08-22 05:33 PM Re: VAL function fails after 9 chars
irie89 Offline
Fresh Scripter

Registered: 2003-08-21
Posts: 9
Loc: Boston
? 'Vartypename = '+vartypename($DOUBLE)
? 'Double = '+$DOUBLE
That worked. Thanks again.

Top
#44436 - 2003-08-27 04:41 PM Re: VAL function fails after 9 chars
irie89 Offline
Fresh Scripter

Registered: 2003-08-21
Posts: 9
Loc: Boston
I'm using FSUTIL.EXE to modify disk quotas from a command line and this EXE will not work with VARTYPE = 5 numbers, where as it will w\ VARTYPE = 3 numbers that are within the integer limits.
I don't suppose there's a function out there that I am missing to convert the DOUBLE back to an integer. INT & ABS work for the smaller numbers within integer limits but not those above the integer limit.

Top
#44437 - 2003-08-27 05:22 PM Re: VAL function fails after 9 chars
irie89 Offline
Fresh Scripter

Registered: 2003-08-21
Posts: 9
Loc: Boston
I used CSTR to convert the DOUBLE number to a VARTYPE = 8 and the EXE accepted the numbers as a string.
Top
#44438 - 2003-08-27 05:59 PM Re: VAL function fails after 9 chars
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ja.
like you see, integer is not the answer when really playing with other data than counters and such.
it's limits are too small for so many things.
_________________________
!

download KiXnet

Top
#44439 - 2003-08-27 06:15 PM Re: VAL function fails after 9 chars
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
What you are trying to do is not possible. In most computer languages there is a limit to the maximum and minimum size of integer numbers. Depending on the language, OS & computer the limit may differ but generally it is still there. Big numbers really require a scientific/floating point representation to store them in a limited space. If the number is very large the full accuracy of the original number will not be preserved since it will be truncated/rounded. Thus converting a string to a number & then back to a string will not always reproduce the same number.
_________________________
Jack

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
0 registered and 302 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.15 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

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