Jump to content

Recommended Posts

Posted (edited)

I am currently at work and i was playing around with a tool i was making. When i compile and run i get a " Line -1: Error: Variable used without bieng declared."

Here is the source:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 422, 194, 192, 114)
$Label1 = GUICtrlCreateLabel("Alternative Downloader", 88, 8, 251, 31)
GUICtrlSetFont(-1, 18, 400, 0, "Arial")
$Input1 = GUICtrlCreateInput("", 8, 88, 401, 21)
$Label2 = GUICtrlCreateLabel("Direct Download Link:", 120, 56, 187, 26)
GUICtrlSetFont(-1, 14, 400, 0, "Arial")
$Button1 = GUICtrlCreateButton("Download", 152, 144, 137, 33, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
    $nMsg = GUIGetMsg()
    If $nMsg = GUICtrlGetState($Button1) Then
        $filesize = InetGetSize($Input1)
        $filemsg = MsgBox(4 + 32, "Alternative Downloader", "The size of the file is " & $filesize & " bytes" & @CRLF & "Are you sure you want to download it?")
    ElseIf $filemsg = 6 Then
        $filesave = FileSaveDialog("Please enter a filename and its appropiate file extension", @DesktopDir, "(*.*)", "")
        InetGet($Input1, $filesave)
    ElseIf $filemsg = 7 Then
        ContinueLoop
    EndIf
    If $nMsg = $GUI_EVENT_CLOSE Then
        Exit
    EndIf
WEnd

I cant seem to find the variable that is not declared. :)

Edited by anzacfalcon
Posted

Hi

Found the error very quickly using scite. If you press f5 when in scite it attempts to run your script. Pretty good details about the error is then shown in the console at the bottom. As an extra thought for you.

Your if statement is asking if $nMsg is a number. I'm not sure if you realize that the number actually refers to a control. So if you did msgbox(0,"", $Input1) you would also get a number....not sure if I'm being clear.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 422, 194, 192, 114)
$Label1 = GUICtrlCreateLabel("Alternative Downloader", 88, 8, 251, 31)
GUICtrlSetFont(-1, 18, 400, 0, "Arial")
$Input1 = GUICtrlCreateInput("", 8, 88, 401, 21)
$Label2 = GUICtrlCreateLabel("Direct Download Link:", 120, 56, 187, 26)
GUICtrlSetFont(-1, 14, 400, 0, "Arial")
$Button1 = GUICtrlCreateButton("Download", 152, 144, 137, 33, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
    $nMsg = GUIGetMsg()
    If $nMsg = GUICtrlGetState($Button1) Then
        $filesize = InetGetSize($Input1)
        $filemsg = MsgBox(4 + 32, "Alternative Downloader", "The size of the file is " & $filesize & " bytes" & @CRLF & "Are you sure you want to download it?")
    ElseIf $nMsg = 6 Then
        $filesave = FileSaveDialog("Please enter a filename and its appropiate file extension", @DesktopDir, "(*.*)", "")
        InetGet($Input1, $filesave)
    ElseIf $nMsg = 7 Then
        ContinueLoop
    EndIf
    If $nMsg = $GUI_EVENT_CLOSE Then
        Exit
    EndIf
WEnd
Posted

Hi

Found the error very quickly using scite. If you press f5 when in scite it attempts to run your script. Pretty good details about the error is then shown in the console at the bottom. As an extra thought for you.

Your if statement is asking if $nMsg is a number. I'm not sure if you realize that the number actually refers to a control. So if you did msgbox(0,"", $Input1) you would also get a number....not sure if I'm being clear.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 422, 194, 192, 114)
$Label1 = GUICtrlCreateLabel("Alternative Downloader", 88, 8, 251, 31)
GUICtrlSetFont(-1, 18, 400, 0, "Arial")
$Input1 = GUICtrlCreateInput("", 8, 88, 401, 21)
$Label2 = GUICtrlCreateLabel("Direct Download Link:", 120, 56, 187, 26)
GUICtrlSetFont(-1, 14, 400, 0, "Arial")
$Button1 = GUICtrlCreateButton("Download", 152, 144, 137, 33, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
    $nMsg = GUIGetMsg()
    If $nMsg = GUICtrlGetState($Button1) Then
        $filesize = InetGetSize($Input1)
        $filemsg = MsgBox(4 + 32, "Alternative Downloader", "The size of the file is " & $filesize & " bytes" & @CRLF & "Are you sure you want to download it?")
    ElseIf $nMsg = 6 Then
        $filesave = FileSaveDialog("Please enter a filename and its appropiate file extension", @DesktopDir, "(*.*)", "")
        InetGet($Input1, $filesave)
    ElseIf $nMsg = 7 Then
        ContinueLoop
    EndIf
    If $nMsg = $GUI_EVENT_CLOSE Then
        Exit
    EndIf
WEnd

Yep i think i understand, thank's.
Posted

Always put "Opt("MustDeclareVars", 1)" at the top of your script.

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]

Posted (edited)

Thank's. I also figured it out.

The order of the If and ElseIf statements are very important. This was the reason why the variable want declared.

While 1
    $nMsg = GUIGetMsg()
    $file = GUICtrlRead ( $Input1 )
    If $nMsg = $Button1 Then
        $filesize = InetGetSize ( $file )
        $filemsg = MsgBox(4 + 32, "Alternative Downloader", "The size of the file is " & $filesize & " bytes" & @CRLF & "Are you sure you want to download it?")
        If $filemsg = 6 Then
            $filesave = FileSaveDialog("Please enter a filename and its appropiate file extension", @DesktopDir, "(*.*)", "")
            InetGet($file, $filesave)
        ElseIf $filemsg = 7 Then
            ContinueLoop
        EndIf
    EndIf
    If $nMsg = $GUI_EVENT_CLOSE Then
        Exit
    EndIf
WEnd

This is the correct code.

Edited by anzacfalcon
Posted (edited)

I did it for the lulz

I'm amateur coder, so don't expect this as perfect (or optimized for performance) script.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

dim $filesize = 0
dim $filemsg = 0
dim $DownloadPath = ""
dim $DownloadProgress = 0
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Alternative Downloader", 422, 194, 192, 114)
$Label1 = GUICtrlCreateLabel("Alternative Downloader", 88, 8, 251, 31)
GUICtrlSetFont(-1, 18, 400, 0, "Arial")
$DownloadLink = GUICtrlCreateInput("", 8, 88, 401, 21)
$Label2 = GUICtrlCreateLabel("Direct Download Link:", 120, 56, 187, 26)
GUICtrlSetFont(-1, 14, 400, 0, "Arial")
$DownloadButton = GUICtrlCreateButton("Download", 152, 144, 137, 33, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
    $nMsg = GUIGetMsg()
    Select 
        Case $nMsg = $DownloadButton
            $DownloadPath = GUICtrlRead ($DownloadLink)
            msgbox (1, $DownloadPath, $DownloadPath)
            $filesize = InetGetSize($DownloadPath)
            $filemsg = MsgBox(4 + 32, "Alternative Downloader", "The size of the file is " & $filesize & " bytes" & @CRLF & "Are you sure you want to download it?")
            if $filemsg = 6 Then
                $filesave = FileSaveDialog("Please enter a filename and its appropiate file extension", @DesktopDir, "Executable (*.exe) | *.* (*.*)", 16, "")
                InetGet ($DownloadPath, $filesave, 0, 1)
                $DownloadProgress = 1
                While $DownloadProgress = 1
                    While @InetGetActive
                        TrayTip("Downloading", "Bytes = " & @InetGetBytesRead, 10, 16)
                        Sleep(1000)
                    Wend
                    Msgbox (0, "Download is Complete", "Download is now complete.")
                    $DownloadProgress = 0
                    WEnd
            EndIf
        
        Case $nMsg = $GUI_EVENT_CLOSE
        Exit
    EndSelect

WEnd
Edited by CounterCraft
Posted

Now that im home, im working on my proper one. Thank's for teaching me how to do the progress system. I would of figured it out but it's always good to be sure. Kthnxbai.

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
  • Recently Browsing   0 members

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