Jump to content

Recommended Posts

Posted

I wrote a example script to do the following:

If the example.ini has the following key- tabnumber = 2, then the GUI would have 2 tabs. any other number, it would have one tab.

The problem I'm having is I'm getting a error on my Func. It says it is badly formatted. ?????? It works fine if I just use the line 7 where I got it remarked out, and remark out anything with the ini. :P

#include <GuiConstants.au3>
#include <File.au3>

$main_gui = GUICreate("example", 600, 115)
$tab = GUICtrlCreateTab(-1, -1, 600)
$tab1 = GuiCtrlCreateTabItem("tab1")
;$tab2 = GuiCtrlCreateTabItem("tab2")
$ini = iniread("example.ini", "tab number", "tab")
if $ini == 2 then _tab_2
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    endselect
wend
            
Func _tab_2
    $tab2 = GuiCtrlCreateTabItem("tab2")
EndFunc
Posted

OK, that fix that problem, but now I got a new issue. I get a error on line 16 saying the variable not being declared. :P

#include <GuiConstants.au3>
#include <File.au3>

$main_gui = GUICreate("example", 600, 115)
$tab = GUICtrlCreateTab(-1, -1, 600)
$tab1 = GuiCtrlCreateTabItem("tab1")
$ini = iniread("unplus.ini", "tab number", "tab", "2")
if $ini == 2 then _tab_2()   
;
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button1
        msgbox(0, "ok", "it worked")    
    endselect
wend
            
Func _tab_2()
    $tab2 = GuiCtrlCreateTabItem("tab2")
    $button1 = GUICtrlCreateButton("OK", 530, 35, 60, 20)
EndFunc
Posted

OK, that fix that problem, but now I got a new issue. I get a error on line 16 saying the variable not being declared. :P

#include <GuiConstants.au3>
#include <File.au3>

$main_gui = GUICreate("example", 600, 115)
$tab = GUICtrlCreateTab(-1, -1, 600)
$tab1 = GuiCtrlCreateTabItem("tab1")
$ini = iniread("unplus.ini", "tab number", "tab", "2")
if $ini == 2 then _tab_2()   
;
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button1
        msgbox(0, "ok", "it worked")    
    endselect
wend
            
Func _tab_2()
    $tab2 = GuiCtrlCreateTabItem("tab2")
    $button1 = GUICtrlCreateButton("OK", 530, 35, 60, 20)
EndFunc

that's becaues you haven't assigned a anything to $button1

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Posted (edited)

Get in the habit of declaring (see global, local, dim) your variables before you use them and you'll be set.

- Steven

Edited by s_mack
Posted

Oh, I see now... and that's why you probably got a compilation "warning" and not an "error", right? If I'm following right, you should be able to ignore the "warning" and it should work... but its still not kosher practice. Just declare the variable first... leave it the way you have it but add:

Dim $button1
somewhere near the top

- Steven

Posted

I take it back... it probably was an error. This is because of your "if"... with the code as you have it, if $ini doesn't == 2 then you continue on without calling the function that declares the $button1 variable... then you end up with a variable being used that your script has no idea what it is. Again, adding the code I wrote will fix this. (other solutions and practices exist)

- Steven

Posted (edited)

I just figured it out.

#include <GuiConstants.au3>
#include <File.au3>

$main_gui = GUICreate("example", 600, 115)
$tab = GUICtrlCreateTab(-1, -1, 600)
$tab1 = GuiCtrlCreateTabItem("tab1")
$button = GUICtrlCreateButton("OK", 530, 35, 60, 20)
$ini = iniread("unplus.ini", "tab number", "tab", "2")
if $ini == 2 then _tab_2()   

GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button
        msgbox(0, "ok", "it worked")
        exit    
    endselect
wend
            
Func _tab_2()
GUISetState()
    $tab2 = GuiCtrlCreateTabItem("tab2")
    $button1 = GUICtrlCreateButton("OK", 530, 35, 60, 20)
    While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button1
        msgbox(0, "ok", "it worked")
        exit    
    endselect
wend
EndFunc
Edited by vollyman
Posted

Couple of changes as commented. Try it.

#include <GuiConstants.au3>
#include <File.au3>

$main_gui = GUICreate("example", 600, 115)
$tab = GUICtrlCreateTab(-1, -1, 600)
$tab1 = GUICtrlCreateTabItem("tab1")
$button = GUICtrlCreateButton("OK", 530, 35, 60, 20)
$ini = IniRead("unplus.ini", "tab number", "tab", "2")
If $ini == 2 Then _tab_2()   

GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button
            MsgBox(0, "ok", "it worked")
            Exit    
    EndSelect
WEnd

Func _tab_2()
    $tab2 = GUICtrlCreateTabItem("tab2")
    $button1 = GUICtrlCreateButton("OK", 530, 35, 60, 20)
    GUISetState(); Moved this down
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $button; Added this
                MsgBox(0, "ok", "it worked"); Added this
                Exit; Added this
            Case $msg = $button1
                MsgBox(0, "ok", "it worked")
                Exit    
        EndSelect
    WEnd
EndFunc
Posted

Well, 1 message loop would be easier if possible. I'm guessing this may suit your cause ?

#include <GuiConstants.au3>
#include <File.au3>

$main_gui = GUICreate("example", 600, 115)
$tab = GUICtrlCreateTab(-1, -1, 600)
$tab1 = GUICtrlCreateTabItem("tab1")
$button = GUICtrlCreateButton("OK", 530, 35, 60, 20)
$ini = IniRead("unplus.ini", "tab number", "tab", "2")
If $ini == 2 Then
    $tab2 = GUICtrlCreateTabItem("tab2")
    $button1 = GUICtrlCreateButton("OK", 530, 35, 60, 20)
Else
    Global $button1 = -1, $tab2 = -1
EndIf  

GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button
            MsgBox(0, "ok", "it worked")
            Exit
        Case $msg = $button1
            MsgBox(0, "ok2", "it worked")
            Exit
    EndSelect
WEnd
Posted

I got it working. Here is the example code. If you wish to test it, you only need to change the iniread from 5 to whatever number between 1 - 5:

#include <GuiConstants.au3>
#include <File.au3>

$main_gui = GUICreate("example", 600, 115)
$tab = GUICtrlCreateTab(-1, -1, 600)
$tab1 = GUICtrlCreateTabItem("TAB 1")
$button1 = GUICtrlCreateButton("TAB 1", 530, 35, 60, 20)
$ini = IniRead("test.ini", "tab number", "tab", "5")
If $ini == 2 Then _tab_2()
If $ini == 3 Then _tab_3() 
If $ini == 4 Then _tab_4()
If $ini == 5 Then _tab_5() 

GUISetState()
;tab 1
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $button1
            MsgBox(0, "TAB 1", "it worked")
            Exit    
    EndSelect
WEnd

;tab 2
Func _tab_2()
    $tab2 = GUICtrlCreateTabItem("TAB 2")
    $button2 = GUICtrlCreateButton("TAB 2", 530, 35, 60, 20)
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit
            Case $msg = $button; Added this
                MsgBox(0, "ok", "it worked")
                Exit 
            Case $msg = $button2
                MsgBox(0, "ok", "it worked")
                Exit    
        EndSelect
    WEnd
EndFunc

;tab3
Func _tab_3()
    $tab2 = GUICtrlCreateTabItem("TAB 2")
    $button2 = GUICtrlCreateButton("TAB 2", 530, 35, 60, 20)
    $tab3 = GUICtrlCreateTabItem("TAB 3")
    $button3 = GUICtrlCreateButton("TAB 3", 530, 35, 60, 20)   
    
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit
            Case $msg = $button1; Added this
                MsgBox(0, "ok", "it worked")
                Exit 
            Case $msg = $button2
                MsgBox(0, "ok", "it worked")
            Case $msg = $button3
                MsgBox(0, "ok", "it worked")
                Exit    
        EndSelect
    WEnd
EndFunc

Func _tab_4()
    $tab2 = GUICtrlCreateTabItem("TAB 2")
    $button2 = GUICtrlCreateButton("TAB 2", 530, 35, 60, 20)
    $tab3 = GUICtrlCreateTabItem("TAB 3")
    $button3 = GUICtrlCreateButton("TAB 3", 530, 35, 60, 20)   
    $tab4 = GUICtrlCreateTabItem("TAB 4")
    $button4 = GUICtrlCreateButton("TAB 4", 530, 35, 60, 20)    
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit
            Case $msg = $button1; Added this
                MsgBox(0, "ok", "it worked")
                Exit 
            Case $msg = $button2
                MsgBox(0, "ok", "it worked")
                exit
            Case $msg = $button3
                MsgBox(0, "ok", "it worked")
                Exit    
            Case $msg = $button4
                MsgBox(0, "ok", "it worked")
                Exit 
        EndSelect
    WEnd
EndFunc

Func _tab_5()
    $tab2 = GUICtrlCreateTabItem("TAB 2")
    $button2 = GUICtrlCreateButton("TAB 2", 530, 35, 60, 20)
    $tab3 = GUICtrlCreateTabItem("TAB 3")
    $button3 = GUICtrlCreateButton("TAB 3", 530, 35, 60, 20)   
    $tab4 = GUICtrlCreateTabItem("TAB 4")
    $button4 = GUICtrlCreateButton("TAB 4", 530, 35, 60, 20)
    $tab5 = GUICtrlCreateTabItem("TAB 5")
    $button5 = GUICtrlCreateButton("TAB 5", 530, 35, 60, 20)  
       
    GUISetState(); Moved this down
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit
            Case $msg = $button1; Added this
                MsgBox(0, "ok", "it worked")
                Exit 
            Case $msg = $button2
                MsgBox(0, "ok", "it worked")
                exit
            Case $msg = $button3
                MsgBox(0, "ok", "it worked")
                Exit    
            Case $msg = $button4
                MsgBox(0, "ok", "it worked")
                Exit 
            Case $msg = $button5
                MsgBox(0, "ok", "it worked")
                Exit                 
        EndSelect
    WEnd
EndFunc

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...