Rafaelinio Posted November 3, 2013 Posted November 3, 2013 expandcollapse popup#include <GUIConstantsEx.au3> #include <Constants.au3> Local $CheckActivation $CheckActivation = RegRead("HKEY_CURRENT_USER\Software\Simple Script Generator", "Activation Key") If $CheckActivation = "Activated" Then Gui2() Gui1() Gui2() Func Gui1() Global $checked Local $msg, $Button1, $MsgTitle, $Message, $ChckBox1, $Button2, $AutomationText, $Button3, $Activation, $Label1, $Label2, $CheckActivation GUICreate("Simple Script Generator") Opt("GUICoordMode", 2) $Button1 = GUICtrlCreateButton("Create a simple message box",1,1, 402, 50) $ChckBox1 = GUICtrlCreateCheckbox("Loop (Warning: Loop is Endless.)", -400, 0,172,15) $Button2 = GUICtrlCreateButton("Notepad Automation", -174,0, 402, 50) $Button3 = GUICtrlCreateButton("Activate", -402, 236) $Label2 = GUICtrlCreateLabel("Beta V1.0", -50, -65, 60, 15) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $Button1 $MsgTitle = InputBox("Insert Title", "Please Insert Your Message Box Title:") $Message = InputBox("Insert Message", "Please Insert The Message:") $checked = BitAND(GUICtrlRead($ChckBox1), $GUI_CHECKED) = $GUI_CHECKED If $checked Then MsgBox(0, $MsgTitle, $Message) Else MsgBox(0, $MsgTitle, $Message) EndIf Case $msg = $Button2 $AutomationText = InputBox("Text", "Insert the text you want to type:") Run("notepad.exe") WinWaitActive("Untitled - Notepad") Send($AutomationText) Sleep(2000) WinClose("Untitled - Notepad") WinWaitActive("Notepad") Send("!n") Case $msg = $Button3 $Activation = InputBox("Activate", "Insert Your Activation Key To Access Beta Features That Are Still In Development:") If $Activation = "HLodf1234" Then MsgBox(0, "Success", "Activation Succesfull!") $Label1 = GUICtrlCreateLabel("Product Activated: Restart Program To Take Effect.", -411, -14, 270) GUICtrlSetState($Button3, $GUI_DISABLE) RegWrite("HKEY_CURRENT_USER\Software\Simple Script Generator", "Activation Key", "REG_SZ", "Activated") Else MsgBox(0, "Activation Failed", "Activation Failed. Check Your Key And Try Again") EndIf EndSelect Wend EndFunc Gui2() Func Gui2() Local $msg, $Button1, $MsgTitle, $Message, $ChckBox1, $Button2, $AutomationText, $Button3, $Activation, $Label1, $Label2, $CheckActivation, $Label3 GUICreate("Simple Script Generator") Opt("GUICoordMode", 2) $Button1 = GUICtrlCreateButton("Create a simple message box",1,1, 402, 50) $ChckBox1 = GUICtrlCreateCheckbox("Loop (Warning: Loop is Endless.)", -400, 0,172,15) $Button2 = GUICtrlCreateButton("Notepad Automation", -174,0, 402, 50) $Label2 = GUICtrlCreateLabel("Beta V1.0", -50, 270, 60, 15) $Label1 = GUICtrlCreateLabel("Product is Activated", -410, -14, 100) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $Button1 $MsgTitle = InputBox("Insert Title", "Please Insert Your Message Box Title:") $Message = InputBox("Insert Message", "Please Insert The Message:") $checked = BitAND(GUICtrlRead($ChckBox1), $GUI_CHECKED) = $GUI_CHECKED If $checked Then MsgBox(0, $MsgTitle, $Message) Else MsgBox(0, $MsgTitle, $Message) EndIf Case $msg = $Button2 $AutomationText = InputBox("Text", "Insert the text you want to type:") Run("notepad.exe") WinWaitActive("Untitled - Notepad") Send($AutomationText) Sleep(2000) WinClose("Untitled - Notepad") WinWaitActive("Notepad") Send("!n") EndSelect Wend EndFunc im trying to make the activation thing work BUT whatever is typed it gets activated. What am i doing wrong with my script?
Moderators Solution Melba23 Posted November 3, 2013 Moderators Solution Posted November 3, 2013 Rafaelinio,You were declaring $CheckActivation as Global - I know you had declared it as Local, but as it is outside a function is is forced to Global by AutoIt. You then redeclared it as Local inside the function which created a new variable - and it would always be set to "". I would also use a single function and just amend the controls depending on the activation state. This works for me:expandcollapse popup#include <GUIConstantsEx.au3> #include <Constants.au3> Global $checked, $CheckActivation $CheckActivation = RegRead("HKEY_CURRENT_USER\Software\Simple Script Generator", "Activation Key") Gui() Func Gui() Local $msg, $Button1, $MsgTitle, $Message, $ChckBox1, $Button2, $AutomationText, $Button3, $Activation, $Label1, $Label2 GUICreate("Simple Script Generator", 400, 400) $Button1 = GUICtrlCreateButton("Create a simple message box", 0, 0, 400, 50) $ChckBox1 = GUICtrlCreateCheckbox("Loop (Warning: Loop is Endless.)", 0, 50, 172, 15) $Button2 = GUICtrlCreateButton("Notepad Automation", 1, 65, 400, 50) $Label2 = GUICtrlCreateLabel("Beta V1.0", 360, 385, 60, 15) ; Create the controls as required <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If $CheckActivation = "Activated" Then ConsoleWrite(1 & @CRLF) $Label1 = GUICtrlCreateLabel("Product is Activated", 0, 385, 100) $Button3 = 9999 Else ConsoleWrite(2 & @CRLF) $Button3 = GUICtrlCreateButton("Activate", 0, 350, 400, 50) $Label1 = 9999 EndIf GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $Button1 $MsgTitle = InputBox("Insert Title", "Please Insert Your Message Box Title:") $Message = InputBox("Insert Message", "Please Insert The Message:") $checked = BitAND(GUICtrlRead($ChckBox1), $GUI_CHECKED) = $GUI_CHECKED If $checked Then MsgBox(0, $MsgTitle, $Message) Else MsgBox(0, $MsgTitle, $Message) EndIf Case $msg = $Button2 $AutomationText = InputBox("Text", "Insert the text you want to type:") Run("notepad.exe") WinWaitActive("Untitled - Notepad") Send($AutomationText) Sleep(2000) WinClose("Untitled - Notepad") WinWaitActive("Notepad") Send("!n") Case $msg = $Button3 $Activation = InputBox("Activate", "Insert Your Activation Key To Access Beta Features That Are Still In Development:") If $Activation = "HLodf1234" Then MsgBox(0, "Success", "Activation Succesfull!") $Label1 = GUICtrlCreateLabel("Product Activated: Restart Program To Take Effect.", -411, -14, 270) GUICtrlSetState($Button3, $GUI_DISABLE) RegWrite("HKEY_CURRENT_USER\Software\Simple Script Generator", "Activation Key", "REG_SZ", "Activated") ; Change the controls to match activation <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlDelete($Button3) $Label1 = GUICtrlCreateLabel("Product is Activated", 0, 385, 100) Else MsgBox(0, "Activation Failed", "Activation Failed. Check Your Key And Try Again") EndIf EndSelect WEnd EndFunc ;==>GuiPlease ask if you have any questions. M23 Rafaelinio 1 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: Reveal hidden contents 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
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