Page 1 of 1 1
Topic Options
#184641 - 2008-01-17 12:22 PM Problem with nummeric expression
GvMC Offline
Fresh Scripter

Registered: 2006-05-31
Posts: 9
Loc: Germany, Munich
Hi,
again I have strange problem, I´m not sure if I´m stupid or kix.
I read a line from a file with format like 1,2,3,4,5,6,7,8,9,10,11, into an array, I split this array with delimiter ",", this works fine no problem.
 Code:
$KSArray = Split ($KSAnzahl,",")
For Each $KSNR in $KSArray
	Gosub Tauschen
Next


The variable $KSNR contains an Value from 1 to XX which I need in the subroutine called "Tauschen". In this Subroutine a UNC Path is created to connect to a network share.

 Code:
:Tauschen
Select
	Case $KSNR < 0
	Return

	Case $KSNR <= 9
	$POS = "POS0"

	Case $KSNR >= 10 
	$POS = "POS"

EndSelect

? $Site + $POS + $KSNR
Return

The Result is:


DEU04712POS01
DEU04712POS02
DEU04712POS03
DEU04712POS04
DEU04712POS05
DEU04712POS06
DEU04712POS07
DEU04712POS08
DEU04712POS09
All fine but:



DEU04712POS010
DEU04712POS011
DEU04712POS012
....


Correct it should be
DEU04712POS11
DEU04712POS12

I tried also with if clauses, i tried with duoble quotes nothing runs like i want.

What the hell I do wrong?!

Top
#184642 - 2008-01-17 01:10 PM Re: Problem with nummeric expression [Re: GvMC]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Well, Split returns an array of strings, not an array of numbers, so you're doing string comparisons. This may not be valid. If you do something like:
Case Val($KSNR) >= 10
it should work.

Personally, I'd prefer something like:
 Code:
$KSArray = Split ($KSAnzahl,",")
For Each $KSNR in $KSArray
  If Val($KSNR) >= 0
    $POS = $Site + "POS" + Right("00" + $KSNR, 2)
    "Site is " $POS ?
  EndIf
Next

This can eliminate the Gosub, and will always left-pad your number with zeros to the length of two digits. The logic can be extended to perform padding to any length by increasing the string of zeros, and the desired string length.

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

Top
#184718 - 2008-01-21 11:25 AM Re: Problem with nummeric expression [Re: Glenn Barnas]
GvMC Offline
Fresh Scripter

Registered: 2006-05-31
Posts: 9
Loc: Germany, Munich
Something I should care next time, I forgot that I get strings back.
Thanks a lot!

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

Generated in 0.05 seconds in which 0.023 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