# Abs returned value ?

## Recommended Posts

Hello,

I have this in my code :

```\$input = InputBox("Graphique", "Entrez le nombre de chiffres retenus après la virgule en X", \$decx, Default, 310, 140); Decimal places for X
\$cancel = @error
If Not \$cancel And StringIsDigit(Abs(\$input)) Then
\$decx = \$input
EndIf
If Not StringIsDigit(Abs(\$input)) And Not \$cancel Then
MsgBox(16, "Graphique", "Veuillez entrer un nombre valide")
EndIf```

I want to valid a number, it can be negative but not floating.

If I enter "4r4" the number is valid as if Abs("4r4") would return 4... But then I use that \$decx = \$input in a Round([...], \$decx) and still it seems like Round([...],"4r4") works like Round([...],4).

I tried with StringIsInt but if I write "aasdf" in the inputbox, it still works...

Thanks

##### Share on other sites

Check first using StringIsInt, then in the true case use the Abs function.

##### Share on other sites

But I write this :

\$input = InputBox("Graphique", "Entrez le nombre de chiffres retenus après la virgule en X", \$decx, Default, 310, 140); Decimal places for X

\$cancel = @error

If Not \$cancel And StringIsInt(\$input) Then

\$decx = \$input

EndIf

If Not StringIsInt(\$input) And Not \$cancel Then

MsgBox(16, "Graphique", "Veuillez entrer un nombre valide")

EndIf

If I write "2a" or "2+2" or "a2a", the value is valid and it shouldn't.

##### Share on other sites

strange. StringIsInt give true only if the number is in the form -123 or 123. No decimal point or anything else.

##### Share on other sites

strange. StringIsInt give true only if the number is in the form -123 or 123. No decimal point or anything else.

Not very strange at all. StringIsInt is short for StringIsInteger, and 123.2 sure is not an integer.

Instead do: If StringIsInt() Or StringIsFloat() Then...

Edited by monoceres

Broken link? PM me and I'll send you the file!

##### Share on other sites

I don't want floating numbers.

I want only numbers as these :

-526

-102

0

-0

8745

52

And not :

a6

6a

6.2

-0.1

-2.5

1+1

+1

I use "If StringIsInt() Or StringIsFloat()" when I want only numbers from -100000000.00 to 100000000.00 but now I don't want decimal.

Thanks.

##### Share on other sites

```Dim \$aNums[10] = ['a01', 'a.3', '-0', '123', '-123', '1+2', '2_3', '2.0', '55-5', '-5-4']

For \$i = 0 To 9
If StringIsInt(\$aNums[\$i]) Then ConsoleWrite(\$i & ' ==> ' & \$aNums[\$i] & @LF)
Next[```

Results in true only for \$i = 2, 3, 4.

##### Share on other sites

```If StringRegExp(\$input, "^-?[0-9]+\$") Then
; it's an integer
EndIf```

##### Share on other sites

Oh God, you will hate me... I was modifying a copy of my script, then running the shortcut to my original...

StringIsInt works fine, thanks...

D'uh !

Sorry for that.

Edited by TheReveller

## Create an account

Register a new account