Jump to content

Process If Then statement to show tab


Go to solution Solved by Loc,

Recommended Posts

Gui includes 4 tabs and 1 $label number of desk numbers Each tab has a space number: 
$tar[3], $top[3]
$tar[0] = Iniread(1)
$top[0] = Iniread(10)
$tar[1] = Iniread(11)
$top[1] = Iniread(20)
$tar[2] = Iniread(21) 
$top[2] = Iniread(30) 
$Tab1 = $tar[0] to $top[0] 
$Tab2 = $tar[1] to $top[1] 
$tab3 = $tar[2] to $top[2] 
I just simulated for easy understanding, so I didn't write enough structure -------------------------- 
I use this to show tabs 
If $label <= $tar[0] And $label >= $top[0] then Guictrlsetstate($tab1, $gui_show) 
ElseIf $label <= $tar[1] And $label >= $top[1] then 
Guictrlsetstate($tab2, $gui_show) 
ElseIf $label <= $tar[2] And $label >= $top[2] then 
Guictrlsetstate($tab3, $gui_show) 
Endif 
___________________ 
$label = random from 1 to 30 I did so why is it wrong? It took me all morning to fix this problem and it didn't work

Link to post
Share on other sites

Case is sweet, no doubt, but If else works as well:

If     $label >= $tar[0] And $label <= $top[0] Then 
   Guictrlsetstate($tab1, $gui_show) 
ElseIf $label >= $tar[1] And $label <= $top[1] Then 
   Guictrlsetstate($tab2, $gui_show) 
ElseIf $label >= $tar[2] And $label <= $top[2] Then 
   Guictrlsetstate($tab3, $gui_show) 
Endif

 

Code hard, but don’t hard code...

Link to post
Share on other sites

The following works for me:

#include <GUIConstantsEx.au3>
#include <GuiTab.au3>

Example()

Func Example()
    GUICreate("Tab Example", 300, 160)
    GUISetBkColor(0x00E0FFFF)
    GUISetFont(9, 300)
    Local $idTab = GUICtrlCreateTab(10, 10, 280, 110)
        GUICtrlCreateTabItem("Tab  0")
        GUICtrlCreateTabItem("Tab  1")
        GUICtrlCreateTabItem("Tab  2")
    GUICtrlCreateTabItem("")
    Local $idLabel = GUICtrlCreateInput("", 10, 130, 50, 20)
    Local $idOK = GUICtrlCreateButton("OK", 65, 130, 50, 20)
    GUISetState(@SW_SHOW)
    Local $idMsg
    While 1
        $idMsg = GUIGetMsg()
        If $idMsg = $GUI_EVENT_CLOSE Then ExitLoop
        Switch $idMsg
            Case $idOK
                Switch GUICtrlRead($idLabel)
                    Case 0 To 15
                        _GUICtrlTab_SetCurFocus($idTab, 0)
                    Case 16 To 30
                        _GUICtrlTab_SetCurFocus($idTab, 1)
                    Case 31 To 50
                        _GUICtrlTab_SetCurFocus($idTab, 2)
                    Case Else
                        _GUICtrlTab_SetCurFocus($idTab, 0)
                EndSwitch
        EndSwitch
    WEnd
EndFunc

 

Link to post
Share on other sites
Posted (edited)
24 minutes ago, Subz said:

The following works for me:

#include <GUIConstantsEx.au3>
#include <GuiTab.au3>

Example()

Func Example()
    GUICreate("Tab Example", 300, 160)
    GUISetBkColor(0x00E0FFFF)
    GUISetFont(9, 300)
    Local $idTab = GUICtrlCreateTab(10, 10, 280, 110)
        GUICtrlCreateTabItem("Tab  0")
        GUICtrlCreateTabItem("Tab  1")
        GUICtrlCreateTabItem("Tab  2")
    GUICtrlCreateTabItem("")
    Local $idLabel = GUICtrlCreateInput("", 10, 130, 50, 20)
    Local $idOK = GUICtrlCreateButton("OK", 65, 130, 50, 20)
    GUISetState(@SW_SHOW)
    Local $idMsg
    While 1
        $idMsg = GUIGetMsg()
        If $idMsg = $GUI_EVENT_CLOSE Then ExitLoop
        Switch $idMsg
            Case $idOK
                Switch GUICtrlRead($idLabel)
                    Case 0 To 15
                        _GUICtrlTab_SetCurFocus($idTab, 0)
                    Case 16 To 30
                        _GUICtrlTab_SetCurFocus($idTab, 1)
                    Case 31 To 50
                        _GUICtrlTab_SetCurFocus($idTab, 2)
                    Case Else
                        _GUICtrlTab_SetCurFocus($idTab, 0)
                EndSwitch
        EndSwitch
    WEnd
EndFunc

 

Thanks for coding for me, I got it done. I mean to JockoDundee I have 15 to 30 tabs so I guess using If Then it returns true, so I do this

For $i = 0 to 30

Switch $lable

Case $tar[$i] To $top[$i]

Guictrlsetstate($tab&$i+1, $gui_show)

EndSwitch

Next

Edited by Loc
Link to post
Share on other sites

Fwiw, there should be no runtime difference between

For $i = 0 to 30

   Switch $lable
   
      Case $tar[$i] To $top[$i]

         Guictrlsetstate($tab&$i+1, $gui_show)

   EndSwitch

Next

and 

For $i = 0 to 30

   If $lable >= $tar[$i] And $label <= $top[$i] Then Guictrlsetstate($tab&$i+1, $gui_show)

Next

I was pointing this out not because I believe one is better than the other, but just so you didn’t have the impression that one works and one doesn’t.  The choice between “If” and “Switch” is mainly a stylistic one.

Code hard, but don’t hard code...

Link to post
Share on other sites

don't know if my code is buggy but both If Then and Switch the result is not as expected for me. From 0 to 30, in which 1 to 29 can show and 0 and 30 can't

Link to post
Share on other sites

start of tab = 1 And $tar and $top = 0 should use $i +1 for tab My code is very long. Let me see if I can cut it outdon't know if my code is buggy but both If Then and Switch the result is not as expected for me. From 0 to 30, in which 1 to 29 can show and 0 and 30 can't

Link to post
Share on other sites
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $Tab[7], $Present, $Currenttable[8], $ini = @ScriptDir & "\Fileini.ini"


IniWrite($ini, 'Save', 'ReadStar0', 1)
IniWrite($ini, 'Save', 'ReadSTop0', 6)
IniWrite($ini, 'Save', 'ReadStar1', 7)
IniWrite($ini, 'Save', 'ReadSTop1', 12)
IniWrite($ini, 'Save', 'ReadStar2', 13)
IniWrite($ini, 'Save', 'ReadSTop2', 18)
IniWrite($ini, 'Save', 'ReadStar3', 19)
IniWrite($ini, 'Save', 'ReadSTop3', 24)
IniWrite($ini, 'Save', 'ReadStar4', 25)
IniWrite($ini, 'Save', 'ReadSTop4', 30)
IniWrite($ini, 'Save', 'ReadStar5', 31)
IniWrite($ini, 'Save', 'ReadSTop5', 36)


$Form1 = GUICreate("Test", 478, 168, 192, 124)
$left = 0
For $i = 0 To 6
$Tab[$i] = GUICtrlCreateButton("Tab"&$i+1, $left, 0, 75, 25)
$Currenttable[$i+1] = GUICtrlCreateLabel("", $left, 88, 75, 60, $SS_CENTER+$SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0x99B4D1)
GUICtrlSetFont(-1, 15)
$left += 80
Next
$Present = GUICtrlCreateLabel("", 200, 32, 72, 25, $SS_CENTER+$SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xA6CAF0)
GUICtrlSetData(-1, IniRead($ini, 'Save', 'Read', ''))
_Showtab($Present)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    For $i = 0 to 6
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            IniWrite($ini, 'Save', 'Read', GUICtrlRead($Present))
            Exit
        Case $Tab[$i]
            _Createtab(IniRead($ini, 'Save', 'ReadStar'&$i, ''), IniRead($ini, 'Save', 'ReadSTop'&$i, ''))
        Case $Currenttable[$i+1]
            GUICtrlSetData($Present, StringReplace(GUICtrlRead($Currenttable[$i+1]), 'Table ', ''))
    EndSwitch
    Next
WEnd

Func _Showtab($ctrlshow)
Local $readstar[7], $readstop[7]
Local $placeS = GUICtrlRead($ctrlshow)
For $i = 0 To 6
$readstar[$i] = IniRead($ini, 'Save', 'ReadStar'&$i, '')
$readstop[$i] = IniRead($ini, 'Save', 'ReadSTop'&$i, '')
If $placeS >= $readstar[$i] And $placeS <= $readstop[$i] Then
MsgBox(0,'Test Return', $readstar[$i] & ' to '& $readstop[$i])
_Createtab($readstar[$i], $readstop[$i])
Endif
Next
EndFunc

Func _Createtab($Star, $Stop)
If $Star = 0 Or $Stop = 0 Or $Star = '' Or $Stop = '' Then
Return
EndIf
$table = 0
For $i = $Star to $Stop
$table +=1
GUICtrlSetData($Currenttable[$table], 'Table '&$i)
Next
EndFunc

When $Present = 2 to 9 it returns wrong result, I summarize my code, in my code Table range from 1 to 300. here I shortened to only 1 to 36

Link to post
Share on other sites
4 hours ago, JockoDundee said:

So why are you storing the controlID for Tab1 in $Tab[0] ?

$Tab[$i] = GUICtrlCreateButton("Tab"&$i+1, $left, 0, 75, 25)

 

I just use $tab[$i] but what does the tab name & $i have to do with each other?

Link to post
Share on other sites
  • Solution
Posted (edited)

I found a solution to solve this problem of mine by using StringFormat assigning to all my desk numbers. For example: The highest number of tables = 900, then StringFormat("%03s", $table)) then the result will appear as 001...900. 

solution: Local $placeS = StringFormat("%03s", GUICtrlRead($ctrlshow))

repair: GUICtrlSetData($Currenttable[$table], 'Table '&StringFormat("%03s",$i)) => GUICtrlSetData($Currenttable[$table], 'Table '&$i)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $Tab[6], $Present, $Currenttable[8], $ini = @ScriptDir & "\Fileini.ini"


IniWrite($ini, 'Save', 'ReadStar0', 01)
IniWrite($ini, 'Save', 'ReadSTop0', 06)
IniWrite($ini, 'Save', 'ReadStar1', 07)
IniWrite($ini, 'Save', 'ReadSTop1', 12)
IniWrite($ini, 'Save', 'ReadStar2', 13)
IniWrite($ini, 'Save', 'ReadSTop2', 18)
IniWrite($ini, 'Save', 'ReadStar3', 19)
IniWrite($ini, 'Save', 'ReadSTop3', 24)
IniWrite($ini, 'Save', 'ReadStar4', 25)
IniWrite($ini, 'Save', 'ReadSTop4', 30)
IniWrite($ini, 'Save', 'ReadStar5', 99)
IniWrite($ini, 'Save', 'ReadSTop5', 104)


$Form1 = GUICreate("Test", 478, 168, 192, 124)
$left = 0
For $i = 0 To 5
$Tab[$i] = GUICtrlCreateButton("Tab"&$i+1, $left, 0, 75, 25)
$Currenttable[$i+1] = GUICtrlCreateLabel("", $left, 88, 75, 60, $SS_CENTER+$SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0x99B4D1)
GUICtrlSetFont(-1, 12)
$left += 80
Next
$Present = GUICtrlCreateLabel("", 200, 32, 72, 25, $SS_CENTER+$SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xA6CAF0)
GUICtrlSetData(-1, IniRead($ini, 'Save', 'Read', ''))
_Showtab($Present)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    For $i = 0 to 5
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            IniWrite($ini, 'Save', 'Read', GUICtrlRead($Present))
            Exit
        Case $Tab[$i]
            _Createtab(IniRead($ini, 'Save', 'ReadStar'&$i, ''), IniRead($ini, 'Save', 'ReadSTop'&$i, ''))
        Case $Currenttable[$i+1]
            GUICtrlSetData($Present, StringReplace(GUICtrlRead($Currenttable[$i+1]), 'Table ', ''))
    EndSwitch
    Next
WEnd

Func _Showtab($ctrlshow)
Local $readstar[7], $readstop[7]
Local $placeS = GUICtrlRead($ctrlshow)
For $i = 0 To 5
$readstar[$i] = StringFormat("%03s", IniRead($ini, 'Save', 'ReadStar'&$i, ''))
$readstop[$i] = StringFormat("%03s", IniRead($ini, 'Save', 'ReadSTop'&$i, ''))
If $placeS >= $readstar[$i] And $placeS <= $readstop[$i] Then
MsgBox(0,'Test Return', $readstar[$i] & ' to '& $readstop[$i])
_Createtab($readstar[$i], $readstop[$i])
Endif
Next
EndFunc

Func _Createtab($Star, $Stop)
If $Star = 0 Or $Stop = 0 Or $Star = '' Or $Stop = '' Then
Return
EndIf
$table = 0
For $i = $Star to $Stop
$table +=1
GUICtrlSetData($Currenttable[$table], 'Table '&StringFormat("%03s", $i))
Next
EndFunc

 

Edited by Loc
Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...