MikiiTakagi Posted April 10, 2019 Share Posted April 10, 2019 (edited) Im making a autoIt Script with multiple UI, working fine until I have to change a label inside a secondary UI with a function. Here the code i have, i don't understand since placing a msgbox in the function seem to work! I removed some code from my project because it as 900 line :S. If i try the function on my MainMenu, it work just fine. Is there something im missing? Im kinda new to programming too! Thanks! expandcollapse popup#RequireAdmin ;Include Library #Region #include <ButtonConstants.au3> #include <MsgBoxConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ColorConstants.au3> #include <WinAPISys.au3> #include <Date.au3> #include <Constants.au3> #include <FileConstants.au3> #EndRegion ;Set Static Dummy Variable Global $frmWindowsMenu = 9999 Global $lblFirewallEtat = 9998, $btnFirewall = 9998 MainMenu() ;Main Menu #Region Func MainMenu() Local $frmMainMenu = GUICreate("Tech Tool 1.0", 475, 350, -1, -1) Local $btnWindowsMenu = GUICtrlCreateButton("Windows Config", 10, 280, 100, 40) Local $btnCloseMenu = GUICtrlCreateButton("Close", 355, 280, 100, 40) Local $lblInfoSection = GUICtrlCreateLabel("INFORMATION", 150, 5, 150, 20) Local $lblInfoSection = GUICtrlSetFont(-1, 16, 800, 0, "Arial") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $btnCloseMenu ExitLoop Case $btnWindowsMenu GUICtrlSetState(@SW_DISABLE, $frmWindowsMenu) WindowsMenu() GUICtrlSetState(@SW_ENABLE, $frmWindowsMenu) EndSwitch WEnd EndFunc #EndRegion ;Windows Menu #Region Func WindowsMenu() Global $frmWindowsMenu = GUICreate("Windows Tools", 350, 250, -1, -1) Local $btnWindowsMenuClose = GUICtrlCreateButton("Close", 125, 200, 100, 40) Global $lblFirewallEtat = GUICtrlCreateLabel("ATTENTE", 10, 10, 60, 20, $SS_CENTER) Global $lblFirewallEtat = GUICtrlSetFont(-1, 10, 400, 0, "Arial") Local $lblFirewall = GUICtrlCreateLabel("Firewall", 90, 10, 175, 20, $SS_CENTER) Local $lblFirewall = GUICtrlSetFont(-1, 10, 400, 0, "Arial") Global $btnFirewall = GUICtrlCreateButton("Fix", 275, 5, 45, 25) Global $btnFirewall = GUICtrlSetFont(-1, 8, 800, 0, "Arial Narrow") GUICtrlSetState(-1, $GUI_DISABLE) GetAllInfosWindows() GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($frmWindowsMenu) ExitLoop Case $btnWindowsMenuClose GUIDelete($frmWindowsMenu) ExitLoop EndSwitch WEnd EndFunc #EndRegion Func GetAllInfosWindows() GetInfoFirewall() EndFunc ;Firewall Check Func GetInfoFirewall() $oFW = ObjCreate("HNetCfg.FwMgr") $oLocPol = $oFW.LocalPolicy $oCurrProf = $oLocPol.CurrentProfile $sText = $oCurrProf.FirewallEnabled if $sText = "True" then GUICtrlSetData($lblFirewallEtat, "Activé") GUICtrlSetColor($lblFirewallEtat, $COLOR_WHITE) GUICtrlSetBkColor($lblFirewallEtat, $COLOR_RED) GUICtrlSetState($btnFirewall, $GUI_ENABLE) Else GUICtrlSetData($lblFirewallEtat, "Désactivé") GUICtrlSetColor($lblFirewallEtat, $COLOR_WHITE) GUICtrlSetBkColor($lblFirewallEtat, $COLOR_GREEN) GUICtrlSetState($btnFirewall, $GUI_DISABLE) EndIf EndFunc Ps: sry for my bad english, it a second language Edited April 10, 2019 by MikiiTakagi Link to comment Share on other sites More sharing options...
BrewManNH Posted April 10, 2019 Share Posted April 10, 2019 Make sure to declare all Global variables at the start of the script, and not inside functions. Then, don't REdeclare them once you're in the function, just assign a value to them at that point. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
MikiiTakagi Posted April 11, 2019 Author Share Posted April 11, 2019 Yeah I just saw my problem! I didn't know the first parameter "-1" was for! I fixed it! Thanks for the help! expandcollapse popup#RequireAdmin ;Include Library #Region #include <ButtonConstants.au3> #include <MsgBoxConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ColorConstants.au3> #include <WinAPISys.au3> #include <Date.au3> #include <Constants.au3> #include <FileConstants.au3> #EndRegion ;Set Static Dummy Variable Global $frmWindowsMenu = 9999 Global $lblFirewallEtat = 9998, $btnFirewall = 9998 MainMenu() ;Main Menu #Region Func MainMenu() Local $frmMainMenu = GUICreate("Tech Tool 1.0", 475, 350, -1, -1) Local $btnWindowsMenu = GUICtrlCreateButton("Windows Config", 10, 280, 100, 40) Local $btnCloseMenu = GUICtrlCreateButton("Close", 355, 280, 100, 40) Local $lblInfoSection = GUICtrlCreateLabel("INFORMATION", 150, 5, 150, 20) Local $lblInfoSection = GUICtrlSetFont(-1, 16, 800, 0, "Arial") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $btnCloseMenu ExitLoop Case $btnWindowsMenu GUICtrlSetState(@SW_DISABLE, $frmWindowsMenu) WindowsMenu() GUICtrlSetState(@SW_ENABLE, $frmWindowsMenu) EndSwitch WEnd EndFunc #EndRegion ;Windows Menu #Region Func WindowsMenu() Global $frmWindowsMenu = GUICreate("Windows Tools", 350, 250, -1, -1) Local $btnWindowsMenuClose = GUICtrlCreateButton("Close", 125, 200, 100, 40) Global $lblFirewallEtat = GUICtrlCreateLabel("ATTENTE", 10, 10, 60, 20, $SS_CENTER) GUICtrlSetFont(-1, 10, 400, 0, "Arial") ;Remove the variable declaration Local $lblFirewall = GUICtrlCreateLabel("Firewall", 90, 10, 175, 20, $SS_CENTER) GUICtrlSetFont(-1, 10, 400, 0, "Arial") ;Remove the variable declaration Global $btnFirewall = GUICtrlCreateButton("Fix", 275, 5, 45, 25) GUICtrlSetFont(-1, 8, 800, 0, "Arial Narrow") ;Remove the variable declaration GUICtrlSetState(-1, $GUI_DISABLE) GetAllInfosWindows() GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($frmWindowsMenu) ExitLoop Case $btnWindowsMenuClose GUIDelete($frmWindowsMenu) ExitLoop EndSwitch WEnd EndFunc #EndRegion Func GetAllInfosWindows() GetInfoFirewall() EndFunc ;Firewall Check Func GetInfoFirewall() $oFW = ObjCreate("HNetCfg.FwMgr") $oLocPol = $oFW.LocalPolicy $oCurrProf = $oLocPol.CurrentProfile $sText = $oCurrProf.FirewallEnabled if $sText = "True" then GUICtrlSetData($lblFirewallEtat, "Activé") GUICtrlSetColor($lblFirewallEtat, $COLOR_WHITE) GUICtrlSetBkColor($lblFirewallEtat, $COLOR_RED) GUICtrlSetState($btnFirewall, $GUI_ENABLE) Else GUICtrlSetData($lblFirewallEtat, "Désactivé") GUICtrlSetColor($lblFirewallEtat, $COLOR_WHITE) GUICtrlSetBkColor($lblFirewallEtat, $COLOR_GREEN) GUICtrlSetState($btnFirewall, $GUI_DISABLE) EndIf EndFunc Link to comment Share on other sites More sharing options...
BrewManNH Posted April 11, 2019 Share Posted April 11, 2019 You're still declaring your Global variables inside the functions, that's a bad coding technique. Get rid of the Global before all variables that you've already declared at the start of the script, and move all global declarations to the start of the script instead of having any of them inside a function. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
MikiiTakagi Posted April 11, 2019 Author Share Posted April 11, 2019 Ohhh good to know! Should I remove the Local in front of other Variable? Link to comment Share on other sites More sharing options...
BrewManNH Posted April 11, 2019 Share Posted April 11, 2019 6 minutes ago, MikiiTakagi said: Should I remove the Local in front of other Variable? As long as the variable is a local variable you're only using the Local keyword inside of functions you haven't previously declared the variable already in the same function then they can stay as they are. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
MikiiTakagi Posted April 11, 2019 Author Share Posted April 11, 2019 Thanks for the info! I'll pay more attention to this in the future! 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