Jump to content

Variable used without being declared problem.


tommytx
 Share

Recommended Posts

I am having a confusing not declared question that I cannot seem to find a solution for. When the script is run without the call mode... meaning remove the main program from the function, the button in the capture function works just fine.. but as soon as I enclose the main program so I can call it the entire program works fine with exception of the one $oButton inside the capture function... The other $oButton's work every time under both conditions.

Here is the code.. keep in mind this is a huge program and everything is perfect with exception of the button call in the capture function... i have only included a small portion of the actual script.

call("mywork")


Func mywork()
$oButton = _IETagNameGetCollection ($oIE, "button",1)
$oButton.click
Sleep(1000)

$oButton = _IETagNameGetCollection ($oIE, "button",0)
$oButton.click
Sleep(1000)

;****************
$ans = decapture()
; ***************

$oButton = _IETagNameGetCollection ($oIE, "button",1)
$oButton.click
Sleep(3000)

$oButton = _IETagNameGetCollection ($oIE, "button",0)
$oButton.click
Sleep(1000)

EndFunc


Func decapture()
$oButton = _IETagNameGetCollection ($oIE, "button",0)
$oButton.click
Sleep(9000)
EndFunc

The resulting error that was thrown.

C:\work\post.au3 (231) : ==> Variable used without being declared.:
$oButton = _IETagNameGetCollection ($oIE, "button",0)
$oButton = _IETagNameGetCollection (^ ERROR
>Exit code: 1    Time: 53.262

Here is what I have tried..

1. GLOBAL $oButton at beginning of main program.

2. Local $oButton just inside the first line of the decapture function

3. Dim $0Button just inside the first line of the decapture function.

4. Any ideas for me to try would be greatly appreciated.

Edited by tommytx
Link to comment
Share on other sites

OH... shoot I solved it myself... you guys are making me get better.... as I keep digging in the books..

I thought it was referring to the button when in fact it was referring to the browser...

So all I needed to do was add the following..

$ans = decatpure($oIE) in the main program then add same to the function..

Func decapture($oIE)

EndFunc

But thanks anyway... of course that variable was not being passed to the funtion, but still not sure why it is not necessary when the call is not used.. since the use of $oIE is still inside a function... but anyway it works now..

Link to comment
Share on other sites

@tommyxt - so you don't run in to this issue again I recommend you use 'Opt("MustDeclareVars", 1)' at the top of your script.

You can use '#AutoIt3Wrapper_run_debug_mode=Y' to find out exactly where the program is falling over.

Lastly, if you are going to use the same var names (which I would avoid) then you must understand scope. The helpfile explains it well enough.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...