botanic Posted October 15, 2009 Posted October 15, 2009 (edited) My code has a chance that the $BlockChance can become invalid, is there any way to test for that, this doesn't work $BlockChance=Sqrt(Sqrt($Defender[3][12]+$Defender[3][13]-$Attacker[3][10]))*10 if @error Then $BlockChance = 5 MsgBox(0, "", $BlockChance) if $BlockChance<5 then $BlockChance=5 MsgBox(0, "", $BlockChance) EndIf Edited October 15, 2009 by botanic
Mison Posted October 15, 2009 Posted October 15, 2009 (edited) Hi, $BlockChance=Sqrt(Sqrt($Defender[3][12]+$Defender[3][13]-$Attacker[3][10]))*10 if @error Then $BlockChance = 5 If Not StringIsAlNum($BlockChance) Then $BlockChance = 5 ; check if -1#.IND present MsgBox(0, "", $BlockChance) if $BlockChance<5 then $BlockChance=5 MsgBox(0, "", $BlockChance) EndIf Edited October 15, 2009 by Mison Hi ;)
botanic Posted October 15, 2009 Author Posted October 15, 2009 Doesnt work, $BlockChance=Sqrt(Sqrt($Defender[3][12]+$Defender[3][13]-$Attacker[3][10]))*10 MsgBox(0, @ScriptLineNumber, $BlockChance) if @error Then $BlockChance = 5 MsgBox(0, @ScriptLineNumber, $BlockChance) If Not StringIsAlNum($BlockChance) Then $BlockChance = 5 ; check if -1#.IND present MsgBox(0, @ScriptLineNumber, $BlockChance) if $BlockChance<5 then $BlockChance=5 MsgBox(0, @ScriptLineNumber, $BlockChance) if $BlockChance>94 then $BlockChance=96 If Not StringIsAlNum($BlockChance) Then $BlockChance = 5 is triggered even if it is a number...
Beege Posted October 15, 2009 Posted October 15, 2009 StringisALNum checks if its all Alpha Numeric, not all numbers. You want all digits correct? Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator
Mison Posted October 15, 2009 Posted October 15, 2009 Really? It must be the "."... so remove it. If Not StringIsAlNum(StringReplace($BlockChance,".","")) Then $BlockChance = 5 Hi ;)
botanic Posted October 15, 2009 Author Posted October 15, 2009 got it by using int() $BlockChance=Sqrt(Sqrt($Defender[3][12]+$Defender[3][13]-$Attacker[3][10]))*10 $BlockChance = int($BlockChance) if @error Then $BlockChance = 5 MsgBox(0, @ScriptLineNumber, $BlockChance) if $BlockChance<5 then $BlockChance=5 MsgBox(0, @ScriptLineNumber, $BlockChance) if $BlockChance>94 then $BlockChance=96
Beege Posted October 15, 2009 Posted October 15, 2009 StringIsAlNum allows all letters. $BlockChance=Sqrt(Sqrt($Defender[3][12]+$Defender[3][13]-$Attacker[3][10]))*10 If Not StringIsDigit(StringReplace($BlockChance, '.', '')) Then $BlockChance = 5 Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator
Mison Posted October 15, 2009 Posted October 15, 2009 Originally I thought to use Int().. but then you will lost all numbers after the decimal point. If that's okay with you, use it. Hi ;)
botanic Posted October 15, 2009 Author Posted October 15, 2009 just using int() as a way to evaluate for the -1#.IND so it doesn't matter
jvanegmond Posted October 15, 2009 Posted October 15, 2009 Local $In = -1 ; Input declaration and assignment Local $BlockChance = 0 ; Output declaration ; Method 1 $BlockChance = Sqrt($In) ; Calculate square root and see if it goes wrong If @error Then $BlockChance = 5 ; This WILL trigger on -1.#IND!! ; You also know the exact conditions under which it will error.. If ($In < 0) Then ; Trap invalid input $BlockChance = 5 Else $BlockChance = Sqrt($In) EndIf github.com/jvanegmond
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