#44422 - 2003-08-21 10:08 PM
VAL function fails after 9 chars
|
irie89
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
|
|
|
|
#44425 - 2003-08-21 10:33 PM
Re: VAL function fails after 9 chars
|
irie89
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
|
|
|
|
#44428 - 2003-08-22 12:44 AM
Re: VAL function fails after 9 chars
|
irie89
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
|
|
|
|
#44430 - 2003-08-22 03:22 PM
Re: VAL function fails after 9 chars
|
irie89
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
|
|
|
|
#44432 - 2003-08-22 04:57 PM
Re: VAL function fails after 9 chars
|
irie89
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
|
|
|
|
#44434 - 2003-08-22 05:27 PM
Re: VAL function fails after 9 chars
|
irie89
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
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
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
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 271 anonymous users online.
|
|
|