Jump to content

Proper Use Of The Guictrlcreateinput Command


Recommended Posts

I am trying to make a few self running examples of code to use in my future programs, and I've reached this problem. As you will see in the attached code, I am trying to create a GUI that allows the user to define some variables (there will be many in the future, but only 4 in the sample). It creates the Gui and allows them to change things just fine. However, when the button to continue is clicked, it should save the variables to an ini file. Instead, it tells me the variables are not defined and then errors out. I can't see why my coding for GuiCtrlCreateInput doesn't work, as I molded it off of the example. Probably missed something, though, since it isn't working...

Also, while less important, how do I get it to close the Gui window when the button is pressed, but continue on with the script?

Thanks for any help you can give.

Link to comment
Share on other sites

You declared variables within the NewINI() function, they aren't globably declared.

Try adding this near the top:

dim $mboard, $version, $rarity, $greet

I got it to run, but I'm not exactly sure what it's trying to do, hopefully this helped.

Edited by pacman1176
Link to comment
Share on other sites

You declared variables within the NewINI() function, they aren't globably declared.

Try adding this near the top:

dim $mboard, $version, $rarity, $greet

I got it to run, but I'm not exactly sure what it's trying to do, hopefully this helped.

Ok, so after adding that to the top (should have figured to define the variables BEFORE trying to do things), I ran it again. No longer does it error out, but it still doesn't store the text in the ini file; it stores numbers where the text should be. How do I get it to store the text from the input boxes?

I've uploaded the new file, so...

Link to comment
Share on other sites

maybe

#include <GuiConstants.au3>
;Variable Creation (Will load from .ini, or create it if .ini doesn't exist)
Dim $mdefault = "I am trading $version $rarity in 1:1 trades.  No PM, just open trade :]"
Dim $gdefault = "Welcome $user.  I am trading $version $rarity cards 1:1.  Please confirm when you have chosen what you need."
Dim $rarity = 1
Dim $version = 1
Dim $mboard, $greet

$file = "Bot Stats.ini"
If Not FileExists($file) Then
    $iMsgBoxAnswer = MsgBox(52, "Critical File Not Found!", "The file must be created/recreated at this time.  After the time is created, you will no longer see this message when you run this bot." & @CRLF & "" & @CRLF & "If you want to change the settings in the future, just delete the file ""Bot Stats.ini"", and you will see this screen the next time you run the program." & @CRLF & "" & @CRLF & "Create the file at this time?", 15)
    If $iMsgBoxAnswer = 7 Then;No
        MsgBox(0, "", "Goodbye.")
        Exit
    EndIf
Else
    $mdefault = IniRead($file, "User Defined Stats", "Message Board Message", "Not Found")
    $gdefault = IniRead($file, "User Defined Stats", "Greeting Message", "Not Found")
    $rarity = IniRead($file, "User Defined Stats", "Rarity", "0")
    $version = IniRead($file, "User Defined Stats", "Version", "0")
EndIf
    NewINI()
    MsgBox(0,"Ready","Continue with your script from here")


Func NewINI()
    $main = GUICreate("Bot Setup", 550, 250)
    GUICtrlCreateLabel("Info:", 2, 3, 20, 20)
    GUICtrlCreateLabel("$user = The person trading with the bot.", 10, 14, 200, 20)
    GUICtrlCreateLabel("$rarity = What you are trading (common, uncommon, or rare) as defined below.", 10, 28, 375, 20)
    GUICtrlCreateLabel("$version = Card version (regular or foil) as defined below.", 10, 42, 325, 20)
    GUICtrlCreateLabel("Message Board:", 2, 61, 90, 20)
    
    $mboard = GUICtrlCreateInput($mdefault, 95, 58, 450, 20)
    GUICtrlCreateLabel("Greeting Message:", 2, 81, 90, 20)
    
    $greet = GUICtrlCreateInput($gdefault, 95, 78, 450, 20)
    $group_1 = GUICtrlCreateGroup("Rarity", 2, 101, 103, 80)
    $rar1 = GUICtrlCreateRadio("Commons", 25, 116, 70)
    If $rarity = 1 Then GUICtrlSetState(-1, $GUI_CHECKED)
    $rar2 = GUICtrlCreateRadio("Uncommons", 25, 136, 70)
    If $rarity = 2 Then GUICtrlSetState(-1, $GUI_CHECKED)
    $rar3 = GUICtrlCreateRadio("Rare", 25, 156, 60)
    If $rarity = 3 Then GUICtrlSetState(-1, $GUI_CHECKED)
    $group_2 = GUICtrlCreateGroup("Version", 106, 101, 95, 80)
    $ver1 = GUICtrlCreateRadio("Any", 125, 116, 55)
    If $version = 1 Then GUICtrlSetState(-1, $GUI_CHECKED)
    $ver2 = GUICtrlCreateRadio("Regular", 125, 136, 70)
    If $version = 2 Then GUICtrlSetState(-1, $GUI_CHECKED)
    $ver3 = GUICtrlCreateRadio("Foil", 125, 156, 60)
    If $version = 3 Then GUICtrlSetState(-1, $GUI_CHECKED)
    GUICtrlCreateGroup("", -99, -99, 1, 1);close group
    $okbutton = GUICtrlCreateButton("Click Here when you are satisfied with your settings.", 2, 187, 546, 60)
    
;Waits for all parameters to be filled and the button to be clicked, then will save the file and start program.
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit
            Case $msg >= $rar1 And $msg <= $rar3
                $rarity = $msg - $rar1 + 1
            Case $msg >= $ver1 And $msg <= $ver3
                $version = $msg - $ver1 + 1
            Case $msg = $okbutton
                CreateINI()
                GUIDelete($main)
                ExitLoop
        EndSelect
    WEnd
EndFunc  ;==>NewINI

Func CreateINI()
    IniWrite($file, "User Defined Stats", "Message Board Message", GUICtrlRead($mboard))
    IniWrite($file, "User Defined Stats", "Greeting Message", GUICtrlRead($greet))
    IniWrite($file, "User Defined Stats", "Rarity", $rarity)
    IniWrite($file, "User Defined Stats", "Version", $version)
EndFunc  ;==>CreateINI

8)

NEWHeader1.png

Link to comment
Share on other sites

Also I noticed as it was running, that you are printing raw variable names, such as in

$mdefault="I am trading $version $rarity in 1:1 trades.  No PM, just open trade :]"


$gdefault="Welcome $user.  I am trading $version $rarity cards 1:1.  Please confirm when you have chosen what you need."

Where you could be doing this, just for a single example.

$mdefault="I am trading " & $version & $rarity & " in 1:1 trades. No PM, just send trade :]"


$mdefault="Welcome " & $user & ". I am trading " & $version & " " & $rarity & " cards 1:1. Please confirm whan you have chosen what you need."

This should show what $user is, not just printing "$user".

Also, a little nit-picky thing with me, it seems that your initiating message box is a rather large line.

$iMsgBoxAnswer=MsgBox(52,"Critical File Not Found!","The file must be created/recreated at this time.  After the time is created, you will no longer see this message when you run this bot." & @CRLF & "" & @CRLF & "If you want to change the settings in the future, just delete the file ""Bot Stats.ini"", and you will see this screen the next time you run the program." & @CRLF & "" & @CRLF & "Create the file at this time?",15)

This can be significantly easier on the eye with the use of underscores.

It also looked as if you were trying to use "double quotes" within a string,

$iMsgBoxAnswer=MsgBox(52,"Critical File Not Found!","The file must be created/recreated at this time." & _
    "After the time is created, you will no longer see this message when you run this bot." & @CRLF & _
    @CRLF & "If you want to change the settings in the future, just delete the file ""Bot Stats.ini"", " & _
    " and you will see this screen the next time you run the program." & @CRLF & "" & @CRLF & _
    "Create the file at this time?",15)

And, another thing that you're doing with your $file and the .ini writing, you have it set up kind of weird..

It won't really write anything to the INI 'cause the $file = FileOpen returns a value of -1 through 2, not really what you're looking for. It can see if it results in an error but I set it up so that it actually writes to the .ini (or creates one).

Give it a shot, I commented out things that I deleted, and explained above things I replaced.

#include <GuiConstants.au3>
;Variable Creation (Will load from .ini, or create it if .ini doesn't exist)

dim $mboard, $version, $rarity, $greet
$user = "User here"
$rarity = "rarity here"
$version = "version here"
$gdefault = "gdefault"


;$file=FileOpen("Bot Stats.ini",0)
$file="Bot Stats.ini"
; If $file=-1 Then
  If $file Then
    $iMsgBoxAnswer=MsgBox(52,"Critical File Not Found!","The file must be created/recreated at this time." & _
    "After the time is created, you will no longer see this message when you run this bot." & @CRLF & _
    @CRLF & "If you want to change the settings in the future, just delete the file ""Bot Stats.ini"", " & _
    " and you will see this screen the next time you run the program." & @CRLF & "" & @CRLF & _
    "Create the file at this time?",15)
    Select
      Case $iMsgBoxAnswer=6;Yes
        NewINI()
      Case $iMsgBoxAnswer=7;No
        MsgBox(0,"","Goodbye.")
        Exit
      Case $iMsgBoxAnswer=-1;Timeout
        NewINI()
    EndSelect
  EndIf

Func NewINI()
  GUICreate("Bot Setup",550,250)
    GuiCtrlCreateLabel("Info:",2,3,20,20)
      GuiCtrlCreateLabel($user & " = The person trading with the bot.",10,14,200,20)
      GuiCtrlCreateLabel($rarity & "= What you are trading (common, uncommon, or rare) as defined below.",10,28,375,20)
      GuiCtrlCreateLabel($version & "= Card version (regular or foil) as defined below.",10,42,325,20)
    GuiCtrlCreatelabel("Message Board:",2,61,90,20)
      $mdefault="I am trading " & $version & " " &$rarity & " in 1:1 trades. No PM, just send trade :]"
        $mboard=GuiCtrlCreateInput($mdefault,95,58,450,20)
    GuiCtrlCreateLabel("Greeting Message:",2,81,90,20)
      $mdefault="Welcome " & $user & ". I am trading " & $version & " " & $rarity & " cards 1:1. Please confirm whan you have chosen what you need."
        $greet=GuiCtrlCreateInput($gdefault,95,78,450,20)
    $group_1=GuiCtrlCreateGroup("Rarity",2,101,103,80)
      $rar1=GuiCtrlCreateRadio("Commons",25,116,70)
      $rar2=GuiCtrlCreateRadio("Uncommons",25,136,70)
      $rar3=GuiCtrlCreateRadio("Rare",25,156,60)      
        GUICtrlCreateGroup("",-99,-99,1,1);close group
    $group_2=GuiCtrlCreateGroup("Version",106,101,95,80)
      $ver1=GuiCtrlCreateRadio("Any",125,116,55)
      $ver2=GuiCtrlCreateRadio("Regular",125,136,70)
      $ver3=GuiCtrlCreateRadio("Foil",125,156,60)
        GuiCtrlCreateGroup("",-99,-99,1,1);close group
    $okbutton=GuiCtrlCreateButton("Click Here when you are satisfied with your settings.",2,187,546,60)

;Waits for all parameters to be filled and the button to be clicked, then will save the file and start program.
GUISetState()
  While 1
    $msg=GUIGetMsg()
    Select
      Case $msg=$GUI_EVENT_CLOSE
        Exit
      Case $msg>=$rar1 and $msg<=$rar3
        $rarity=$msg-$rar1+1
      Case $msg>=$ver1 and $msg<=$ver3
        $version=$msg-$ver1
      Case $msg=$okbutton
        CreateINI()
    EndSelect
  Wend
EndFunc

Func CreateINI()
  IniWrite($file,"User Defined Stats","Message Board Message",$mboard)
  IniWrite($file,"User Defined Stats","Greeting Message",$greet)
  IniWrite($file,"User Defined Stats","Rarity (Common=1, Uncommon=2, Rare=3)",$rarity)
  IniWrite($file,"User Defined Stats","Version (Any=0, Regular=1, Foil=2)",$version)
EndFunc
Edited by pacman1176
Link to comment
Share on other sites

maybe

#include <GuiConstants.au3>
;Variable Creation (Will load from .ini, or create it if .ini doesn't exist)
Dim $mdefault = "I am trading $version $rarity in 1:1 trades.  No PM, just open trade :]"
Dim $gdefault = "Welcome $user.  I am trading $version $rarity cards 1:1.  Please confirm when you have chosen what you need."
Dim $rarity = 1
Dim $version = 1
Dim $mboard, $greet

$file = "Bot Stats.ini"
If Not FileExists($file) Then
    $iMsgBoxAnswer = MsgBox(52, "Critical File Not Found!", "The file must be created/recreated at this time.  After the time is created, you will no longer see this message when you run this bot." & @CRLF & "" & @CRLF & "If you want to change the settings in the future, just delete the file ""Bot Stats.ini"", and you will see this screen the next time you run the program." & @CRLF & "" & @CRLF & "Create the file at this time?", 15)
    If $iMsgBoxAnswer = 7 Then;No
        MsgBox(0, "", "Goodbye.")
        Exit
    EndIf
Else
    $mdefault = IniRead($file, "User Defined Stats", "Message Board Message", "Not Found")
    $gdefault = IniRead($file, "User Defined Stats", "Greeting Message", "Not Found")
    $rarity = IniRead($file, "User Defined Stats", "Rarity", "0")
    $version = IniRead($file, "User Defined Stats", "Version", "0")
EndIf
    NewINI()
    MsgBox(0,"Ready","Continue with your script from here")
Func NewINI()
    $main = GUICreate("Bot Setup", 550, 250)
    GUICtrlCreateLabel("Info:", 2, 3, 20, 20)
    GUICtrlCreateLabel("$user = The person trading with the bot.", 10, 14, 200, 20)
    GUICtrlCreateLabel("$rarity = What you are trading (common, uncommon, or rare) as defined below.", 10, 28, 375, 20)
    GUICtrlCreateLabel("$version = Card version (regular or foil) as defined below.", 10, 42, 325, 20)
    GUICtrlCreateLabel("Message Board:", 2, 61, 90, 20)
    
    $mboard = GUICtrlCreateInput($mdefault, 95, 58, 450, 20)
    GUICtrlCreateLabel("Greeting Message:", 2, 81, 90, 20)
    
    $greet = GUICtrlCreateInput($gdefault, 95, 78, 450, 20)
    $group_1 = GUICtrlCreateGroup("Rarity", 2, 101, 103, 80)
    $rar1 = GUICtrlCreateRadio("Commons", 25, 116, 70)
    If $rarity = 1 Then GUICtrlSetState(-1, $GUI_CHECKED)
    $rar2 = GUICtrlCreateRadio("Uncommons", 25, 136, 70)
    If $rarity = 2 Then GUICtrlSetState(-1, $GUI_CHECKED)
    $rar3 = GUICtrlCreateRadio("Rare", 25, 156, 60)
    If $rarity = 3 Then GUICtrlSetState(-1, $GUI_CHECKED)
    $group_2 = GUICtrlCreateGroup("Version", 106, 101, 95, 80)
    $ver1 = GUICtrlCreateRadio("Any", 125, 116, 55)
    If $version = 1 Then GUICtrlSetState(-1, $GUI_CHECKED)
    $ver2 = GUICtrlCreateRadio("Regular", 125, 136, 70)
    If $version = 2 Then GUICtrlSetState(-1, $GUI_CHECKED)
    $ver3 = GUICtrlCreateRadio("Foil", 125, 156, 60)
    If $version = 3 Then GUICtrlSetState(-1, $GUI_CHECKED)
    GUICtrlCreateGroup("", -99, -99, 1, 1);close group
    $okbutton = GUICtrlCreateButton("Click Here when you are satisfied with your settings.", 2, 187, 546, 60)
    
;Waits for all parameters to be filled and the button to be clicked, then will save the file and start program.
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit
            Case $msg >= $rar1 And $msg <= $rar3
                $rarity = $msg - $rar1 + 1
            Case $msg >= $ver1 And $msg <= $ver3
                $version = $msg - $ver1 + 1
            Case $msg = $okbutton
                CreateINI()
                GUIDelete($main)
                ExitLoop
        EndSelect
    WEnd
EndFunc ;==>NewINI

Func CreateINI()
    IniWrite($file, "User Defined Stats", "Message Board Message", GUICtrlRead($mboard))
    IniWrite($file, "User Defined Stats", "Greeting Message", GUICtrlRead($greet))
    IniWrite($file, "User Defined Stats", "Rarity", $rarity)
    IniWrite($file, "User Defined Stats", "Version", $version)
EndFunc ;==>CreateINI

8)

Thanks to both pacman and valuator for your help. Using the code Valuator provided, I've been able to get everything working as I see it working in my mind. I'm not entirely sure about all the things that were changed, but I'll see shortly when I compare the new to the original.

Thanks again for your help, guys.

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