multiloser Posted March 18, 2007 Share Posted March 18, 2007 (edited) Up until now, I've been using While statements to create my program loops,but I've been having trouble with it on other programs, so I need to move on to Func () statements.This is part of a script I have going: (you can skip it for now)BEGIN CODE$sString = _IEBodyReadHTML ($oMain)StringReplace($sString, 'NOT YOU', '')$NotBefore = @extendedStringReplace($sString, '+', '')$YouBefore = @extended_IELinkClickByText ($oMain, "Go back to Money Making Game")$oAmount = 1000$oForm = _IEFormGetObjByName ($oMain, "makebet")$oBet = _IEFormElementGetObjByName ($oForm, "howmuch")First()Func First() _IEFormElementSetValue ($oBet, $oAmount) _IEFormSubmit ($oForm) _IELinkClickByText ($oMain, "Look at your Bet Archive") $sString = _IEBodyReadHTML ($oMain) StringReplace($sString, 'NOT YOU', '') $NotAfter = @extended StringReplace($sString, '+', '') $YouAfter = @extended Second()EndFuncFunc Second() If $NotAfter > $NotBefore Then $oAmount = $oAmount + $oAmount $NotBefore = $NotAfter _IELinkClickByText ($oMain, "Go back to Money Making Game") First() ElseIf $YouAfter > $YouBefore Then $oAmount = 1000 $YouBefore = $YouAfter _IELinkClickByText ($oMain, "Go back to Money Making Game") First() Else Sleep (1000) _IEAction ($oMain, "Refresh") Second() EndIfEndFuncEND CODEI get:"Line 45If $NotAfter > $NotBefore ThenIf ^ ERRORError: Variable used without being declared."This probably isn't a Func() mistake, but I don't know what's wrong or how to fix it!!!I thought I declared them!Look at the bolds above.Why doesnt this work!!!!!AHHH!Thanks! (lol) Edited March 18, 2007 by multiloser Link to comment Share on other sites More sharing options...
hearurscream Posted March 18, 2007 Share Posted March 18, 2007 (edited) You declared the variable in one function and used it in another. When you create a variable in a function, it is automatically deleted when the function is exited. You must globally declare it in the main part of your program. Hope this helps. EDIT: you used them in the main part, but you must specifically GLOBALLY declare them before you use them. Edited March 18, 2007 by hearurscream Infinity is a floorless room without walls or ceiling.Anyone who cannot cope with mathematics is not fully human. At best he is a tolerable subhuman who has learned to wear shoes, bathe, and not make messes in the house. Link to comment Share on other sites More sharing options...
multiloser Posted March 18, 2007 Author Share Posted March 18, 2007 You declared the variable in one function and used it in another. When you create a variable in a function, it is automatically deleted when the function is exited. You must globally declare it in the main part of your program. Hope this helps.EDIT: you used them in the main part, but you must specifically GLOBALLY declare them before you use them.And when I modify it in a function will that modification carry over? Link to comment Share on other sites More sharing options...
hearurscream Posted March 18, 2007 Share Posted March 18, 2007 I believe so, try it and see. Infinity is a floorless room without walls or ceiling.Anyone who cannot cope with mathematics is not fully human. At best he is a tolerable subhuman who has learned to wear shoes, bathe, and not make messes in the house. Link to comment Share on other sites More sharing options...
multiloser Posted March 18, 2007 Author Share Posted March 18, 2007 (edited) I've bolded my modifications....Same result...Am I still missing more? Do I need to Globally declare the variables INSIDE the functions?Global $NotAfter = 0Global $YouAfter = 0$sString = _IEBodyReadHTML ($oMain)StringReplace($sString, 'NOT YOU', '')Global $NotBefore = @extendedStringReplace($sString, '+', '')Global $YouBefore = @extended_IELinkClickByText ($oMain, "Go back to Money Making Game")Global $oAmount = 1000$oForm = _IEFormGetObjByName ($oMain, "makebet")$oBet = _IEFormElementGetObjByName ($oForm, "howmuch")First()Func First()_IEFormElementSetValue ($oBet, $oAmount)_IEFormSubmit ($oForm)_IELinkClickByText ($oMain, "Look at your Bet Archive")$sString = _IEBodyReadHTML ($oMain)StringReplace($sString, 'NOT YOU', '')$NotAfter = @extendedStringReplace($sString, '+', '')$YouAfter = @extendedSecond()EndFuncFunc Second() If $NotAfter > $NotBefore Then $oAmount = $oAmount + $oAmount $NotBefore = $NotAfter _IELinkClickByText ($oMain, "Go back to Money Making Game") First() ElseIf $YouAfter > $YouBefore Then $oAmount = 1000 $YouBefore = $YouAfter _IELinkClickByText ($oMain, "Go back to Money Making Game") First() Else Sleep (1000) _IEAction ($oMain, "Refresh") Second() EndIfEndFunc Edited March 18, 2007 by multiloser Link to comment Share on other sites More sharing options...
multiloser Posted March 18, 2007 Author Share Posted March 18, 2007 Nevermind! It works! But now it just refreshes over and over again (stuck on refresh part) Are the "If $NotAfter > $NotBefore Then" type parts valid? Link to comment Share on other sites More sharing options...
multiloser Posted March 18, 2007 Author Share Posted March 18, 2007 Nevermind! I'm good! Thanks for the help! 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