TheReveller Posted April 7, 2009 Share Posted April 7, 2009 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 Link to comment Share on other sites More sharing options...
Authenticity Posted April 7, 2009 Share Posted April 7, 2009 Check first using StringIsInt, then in the true case use the Abs function. Link to comment Share on other sites More sharing options...
TheReveller Posted April 7, 2009 Author Share Posted April 7, 2009 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 = @errorIf Not $cancel And StringIsInt($input) Then $decx = $inputEndIfIf Not StringIsInt($input) And Not $cancel Then MsgBox(16, "Graphique", "Veuillez entrer un nombre valide")EndIfIf I write "2a" or "2+2" or "a2a", the value is valid and it shouldn't. Link to comment Share on other sites More sharing options...
Authenticity Posted April 7, 2009 Share Posted April 7, 2009 strange. StringIsInt give true only if the number is in the form -123 or 123. No decimal point or anything else. Link to comment Share on other sites More sharing options...
monoceres Posted April 7, 2009 Share Posted April 7, 2009 (edited) 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 April 7, 2009 by monoceres Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
TheReveller Posted April 7, 2009 Author Share Posted April 7, 2009 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. Link to comment Share on other sites More sharing options...
Authenticity Posted April 7, 2009 Share Posted April 7, 2009 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. Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 7, 2009 Share Posted April 7, 2009 If StringRegExp($input, "^-?[0-9]+$") Then ; it's an integer EndIf Link to comment Share on other sites More sharing options...
TheReveller Posted April 7, 2009 Author Share Posted April 7, 2009 (edited) 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 April 7, 2009 by TheReveller Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now