Mechaflash Posted August 16, 2012 Share Posted August 16, 2012 So I thought I had this coded right... but AutoIt fails saying that the variable isn't defined... C:\Documents and Settings\user\Desktop\test.au3 (8) : ==> Variable used without being declared.: msgbox(0,"",$value) msgbox(0,"",^ ERROR Here's a reproduction of the problem. HotkeySet("{PGUP}", "_Test") While 1 Sleep(10) WEnd Func _Test(Const $value = 1) ; Testing without Const gives the same error as well. But for the sake of my use, I specify Const msgbox(0,"",$value) EndFunc Is this normal behavior and I'm not coding this correctly? Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 16, 2012 Moderators Share Posted August 16, 2012 mechaflash213,From the Help file page for HotKeySet: "The called function can not be given parameters. They will be ignored."So it is hardly surprising that AutoIt considers $value to be undefined. 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...
water Posted August 16, 2012 Share Posted August 16, 2012 (edited) According to the help file: "The called function can not be given parameters. They will be ignored."Too late Edited August 16, 2012 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Mechaflash Posted August 16, 2012 Author Share Posted August 16, 2012 missed that bit... I suppose a workaround would be: HotkeySet("{PGUP}", "_Test") While 1 Sleep(10) WEnd Func _Test(Const $value = 1) If @HotKeyPressed Then $value = 1 ; <<<<<<<<<< msgbox(0,"",$value) EndFunc Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 16, 2012 Moderators Share Posted August 16, 2012 mechaflash213,That will still give you an error because $value is undeclared. But this works: HotKeySet("{PGUP}", "_Test") HotKeySet("{PGDN}", "_Test") While 1 Sleep(10) WEnd Func _Test() Local $value = 0 If @HotKeyPressed = "{PGUP}" Then $value = 1 EndIf MsgBox(0, "", $value) EndFunc ;==>_TestM23 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...
Mechaflash Posted August 16, 2012 Author Share Posted August 16, 2012 heh? I tested my code and it works All it's doing is looking for @HotKeyPressed to have an assignment then set $value = 1. If a hotkey isn't pressed, the whole function gets ignored anyways. Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
water Posted August 16, 2012 Share Posted August 16, 2012 I get an error because $value is defined as a constant. I changed the script a bit. This works: HotKeySet("{PGUP}", "_Test") HotKeySet("{PGDN}", "_Test") HotKeySet("{Exit}", "_Exit") While 1 Sleep(10) WEnd Func _Test($value = 1) If @HotKeyPressed = "{PGUP}" Then $value = 2 If @HotKeyPressed = "{PGDN}" Then $value = 3 MsgBox(0, "", $value) EndFunc ;==>_Test Func _Exit() Exit EndFunc My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Mechaflash Posted August 16, 2012 Author Share Posted August 16, 2012 (edited) I get an error because $value is defined as a constant. I changed the script a bit. This works: HotKeySet("{PGUP}", "_Test") HotKeySet("{PGDN}", "_Test") HotKeySet("{Exit}", "_Exit") While 1 Sleep(10) WEnd Func _Test($value = 1) If @HotKeyPressed = "{PGUP}" Then $value = 2 If @HotKeyPressed = "{PGDN}" Then $value = 3 MsgBox(0, "", $value) EndFunc ;==>_Test Func _Exit() Exit EndFunc Yeah I get that at the au3 check. But that's because the au3 check only knows that a Const variable is defined and we are changing that variable. If you force it to run, it works fine (and will work fine in any circumstance because of the nature of how HotKeySet() treats functions) This is one of the cases where the human mind overrides programming logic If the function is ever called outside of a hotkey assignment, that line is bypassed since a hotkey wasn't pressed. Edited August 16, 2012 by mechaflash213 Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 16, 2012 Moderators Share Posted August 16, 2012 mechaflash213,This is one of the cases where the human mind overrides programming logicWhereas if you do as I suggested above and declare the variable within the functions, both human and AutoIt are quite content. M23P.S. I know your version with a function parameter works, but it is an offence to good practise to code it that way. 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...
Mechaflash Posted August 16, 2012 Author Share Posted August 16, 2012 bah... I ended up creating a wrapper for it since I had to utilize other functions on hotkey press, so I was able to avoid the whole ordeal. On a side note, for the sake of the topic, the function serves as a tool to cycle through images (personal/business check processing). In the program, there's 3 ways to do this: hotkey, pressing a GUI button, and typing an input value to skip to an image #. If it's a single image skip (hotkey or GUI button) no problem, but I needed the ability to still pass an argument with the value to the function if the user decides to use the 'skip to image' so it knows how many to skip. Let's pretend I didn't make a wrapper for it already... my only options would be to create a wrapper ( ), store the value in a file and retrieve it in the function ( ), or duplicate the function for this purpose only ( ) Is it still bad practice in this sense? The only problem that I see is that au3 check isn't programmed to look for a function-hotkey relation and to omit the Const variable rule from its check... which it shouldn't since it could miss a real problem with the Const variable being effected in other ways. It's like wearing a seatbelt... it will save you 99.9% of the time from horrific injuries. But there's that .1% where the seat belt jams and locks on you while your car is on fire... or a head-on collision at 90 mph and you die as opposed to being ejected from the vehicle and thrown into a tree and live . You know those extreme cases lol. Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” 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