Loc Posted July 14, 2021 Share Posted July 14, 2021 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 comment Share on other sites More sharing options...
Subz Posted July 14, 2021 Share Posted July 14, 2021 The issue is probably occurring because multiple expressions are returning true. You can check this with error checking in your code. Have you tried using Switch instead for example: Switch $lable Case $tar[0] To $top[0] Guictrlsetstate($tab2, $gui_show) Case $tar[1] To $top[1] ... EndSwitch Loc 1 Link to comment Share on other sites More sharing options...
Loc Posted July 14, 2021 Author Share Posted July 14, 2021 Thank Subz So this morning I didn't think of it Link to comment Share on other sites More sharing options...
JockoDundee Posted July 14, 2021 Share Posted July 14, 2021 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 comment Share on other sites More sharing options...
Loc Posted July 14, 2021 Author Share Posted July 14, 2021 My tabs have 15 to 30. Not sure if it's ok, I tried If Then this morning and it didn't show the tabs I wanted. Link to comment Share on other sites More sharing options...
Subz Posted July 14, 2021 Share Posted July 14, 2021 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 Loc 1 Link to comment Share on other sites More sharing options...
Loc Posted July 14, 2021 Author Share Posted July 14, 2021 (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 July 14, 2021 by Loc Link to comment Share on other sites More sharing options...
JockoDundee Posted July 14, 2021 Share Posted July 14, 2021 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. Loc 1 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Loc Posted July 15, 2021 Author Share Posted July 15, 2021 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 comment Share on other sites More sharing options...
JockoDundee Posted July 15, 2021 Share Posted July 15, 2021 (edited) Post your entire code with the <> button. I just took your guictrl without looking at it but it doesn’t take a string, and in any event why the “$i + 1” ? Guictrlsetstate($tab&$i+1, $gui_show) Edited July 15, 2021 by JockoDundee Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Loc Posted July 15, 2021 Author Share Posted July 15, 2021 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 comment Share on other sites More sharing options...
Loc Posted July 15, 2021 Author Share Posted July 15, 2021 expandcollapse popup#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 comment Share on other sites More sharing options...
JockoDundee Posted July 15, 2021 Share Posted July 15, 2021 (edited) So why are you storing the controlID for Tab1 in $Tab[0] ? $Tab[$i] = GUICtrlCreateButton("Tab"&$i+1, $left, 0, 75, 25) Edited July 15, 2021 by JockoDundee Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Loc Posted July 15, 2021 Author Share Posted July 15, 2021 about arrays, the variable $tab = 0 to... as for the name, tab = 1 to ... so it must be given = $i +1 Link to comment Share on other sites More sharing options...
Loc Posted July 15, 2021 Author Share Posted July 15, 2021 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 comment Share on other sites More sharing options...
Solution Loc Posted July 16, 2021 Author Solution Share Posted July 16, 2021 (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) expandcollapse popup#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 July 16, 2021 by Loc Link to comment Share on other sites More sharing options...
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