20Ice18 Posted June 19, 2023 Share Posted June 19, 2023 (edited) I am encountering a perplexing issue while running a script, and I would appreciate your insights and assistance in resolving it. Here's a brief description of the problem: When I execute the script within the AutoIt environment, it runs smoothly without any errors or problems. However, when I compile the script into an executable and attempt to run it, an error occurs stating, "Variable used without being declared." I have made diligent efforts to identify the undeclared variable, but unfortunately, I have been unsuccessful in locating it. I have reviewed EzMySqll.au3 UDF made by @Yoriz thoroughly, and declared all undeclared variables now they all appear to be appropriately declared before usage. expandcollapse popupGlobal $str_db_host, $str_db_user, $str_db_password, $str_database Func data_computers_insert() Local $serialNumber Local $computerName Local $submissionDate Local $sqlQuery ; Start the MySQL connection _EzMySql_Startup() ; Open the connection to the database _EzMySql_Open($str_db_host, $str_db_user, $str_db_password, $str_database, "3306") If @error Then MsgBox(16, "Error", "Failed to open the MySQL connection.") Return EndIf ; Set the values for the computer $serialNumber = RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\BIOS", "SystemProductName") If @error Then MsgBox(16, "Error", "Failed to read the serial number from the registry.") _EzMySql_Close() _EzMySql_ShutDown() Return EndIf $computerName = @ComputerName $submissionDate = @YEAR & "-" & @MON & "-" & @MDAY ; Build the SQL query $sqlQuery = "INSERT INTO Computers (SerialNumber, ComputerName, SubmissionDate) VALUES ('" & $serialNumber & "', '" & $computerName & "', '" & $submissionDate & "')" ; Display the SQL query in the console ConsoleWrite("SQL Query: " & $sqlQuery & @CRLF) ; Execute the query _EzMySql_Exec($sqlQuery) If @error Then MsgBox(16, "Error", "Failed to execute the SQL query.") _EzMySql_Close() _EzMySql_ShutDown() Return EndIf _EzMySql_Close() _EzMySql_ShutDown() EndFunc I run this script using mentioned UDF. But I keep getting error when my program is compiled. After error msgbox there is an empty file created called libmySQL_x64.dll, and its only created there when I get an error. Edited June 19, 2023 by 20Ice18 ❤️ Link to comment Share on other sites More sharing options...
20Ice18 Posted June 19, 2023 Author Share Posted June 19, 2023 (edited) By the way I made this function that you can add to EzMySql.au3 udf to check if value already exists in database to prevent multiple identical records if anyone needs it. Func EntryExistsInDatabase($$str_column1, $str_column2) Local $existingQuery = "SELECT COUNT(*) FROM Computers WHERE SerialNumber = '" & $str_column1 & "' AND ComputerName = '" & $str_column2 & "'" Local $existingResult = _EzMySql_Exec($existingQuery) If @error Then MsgBox(16, "Error", "Failed to execute the existing entry check query.") Return False EndIf If $existingResult = 1 Then Return True Else Return False EndIf EndFunc example: expandcollapse popupFunc data_computers_insert() Local $str_column1 Local $str_column2 Local $str_column3 Local $sqlQuery ; Start the MySQL connection _EzMySql_Startup() ; Open the connection to the database _EzMySql_Open($str_db_host, $str_db_user, $str_db_password, $str_database, "3306") If @error Then MsgBox(16, "Error", "Failed to open the MySQL connection.") Return EndIf ; Set the values for the computer $str_column1 = RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\BIOS", "SystemProductName") If @error Then MsgBox(16, "Error", "Failed to read the serial number from the registry.") _EzMySql_Close() _EzMySql_ShutDown() Return EndIf $str_column2 = @ComputerName $str_column3 = @YEAR & "-" & @MON & "-" & @MDAY ; Check if the entry already exists If EntryExistsInDatabase($str_column1, $str_column2) Then ;modify however you want MsgBox(16, "Error", "Entry already exists in the database.") _EzMySql_Close() _EzMySql_ShutDown() Return EndIf ; Build the SQL query $sqlQuery = "INSERT INTO Computers (SerialNumber, ComputerName, SubmissionDate) VALUES ('" & $str_column1 & "', '" & $str_column2 & "', '" & $str_column3 & "')" ; Display the SQL query in the console ConsoleWrite("SQL Query: " & $sqlQuery & @CRLF) ; Execute the query _EzMySql_Exec($sqlQuery) If @error Then MsgBox(16, "Error", "Failed to execute the SQL query.") _EzMySql_Close() _EzMySql_ShutDown() Return EndIf _EzMySql_Close() _EzMySql_ShutDown() EndFunc You can modify it to meet your specific requirements. I tested it and turns out that it's able to create .dll 32 bit even when its compiled, so I guess the issue is somewhere where 64 bit .dll is created. Edited June 19, 2023 by 20Ice18 ❤️ Link to comment Share on other sites More sharing options...
Solution 20Ice18 Posted June 19, 2023 Author Solution Share Posted June 19, 2023 The issue was in EzMtSql_Dll.au3 file there is at the fist sight obvious mistake with a lining, I thought since there is a comment ; Dont Tidy me! Author is aware of it but it probably was because of other reason. so I rewrote the original Func _EzMySql_Dll() ; Dont Tidy me! If @AutoItX64 = 0 Then Local $sData = '0x4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000F00000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000C9F688528D97E6018D97E6018D97E60130D870018197E6.... to Func _EzMySql_Dll() ; Dont Tidy me! Local $sData If @AutoItX64 = 0 Then $sData = '0x4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000F.... Anyone whos reading this and has the same issue make sure to line up the function and condition correctly and put Local $sData into the function, not into If statement, or else $sData will be undefined in Else statement later. 😬 ❤️ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 19, 2023 Moderators Share Posted June 19, 2023 20Ice18, Delighted you got it sorted, but please do not pad your post count unnecessarily. There is an edit function, so please use it. Many posts merged above. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
20Ice18 Posted June 19, 2023 Author Share Posted June 19, 2023 (edited) Sorry I didn't know they can merge. 😶 Edited June 19, 2023 by 20Ice18 ❤️ 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