Jump to content

What am i doing wrong with my script?


Rafaelinio
 Share

Go to solution Solved by Melba23,

Recommended Posts

#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?

Link to comment
Share on other sites

  • Moderators
  • Solution

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:

#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   ;==>Gui
Please ask if you have any questions. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...