Jump to content

Maintaining global variable value?


Recommended Posts

Problem:As part of a GUI (using On Event), I have a combo with 6 selections. If any of the first 4 are chosen, an associated value is assigned and displayed. If the 5th one is chosen, it calls a function that makes another combo available. Choosing from this combo should assign a value to the same variable and displayed it BUT it does not display at all. The value is set to a global variable. Inside the called function the value is good. It does not make it to the calling function. Further testing shows that the calling function does not wait for the called function to perform before displaying the variable's value, even with a sleep (10000) statement. Please enlighten me with my error(s).

Thanks

Code snippet below (did not want to include all 185 lines of test code)

Func SetCoreAppsList()

;;Determine Winstall list file to use from Office version selected

$CoreAppsList = ""

GUICtrlSetState ($CoreAppsLabel, $GUI_HIDE)

GUICtrlSetData ($WinInstallInput,"")

GUICtrlSetState ($WinInstallInput, $GUI_HIDE)

GUICtrlSetState ($GoldBuildLabel, $GUI_HIDE)

GUICtrlSetState ($GoldBuildCombo, $GUI_HIDE)

Switch GUICtrlRead($OfficeCombo)

Case "Office XP Std"

$CoreAppsList = "xpcorestdsoesp2.lst"

Case "Office XP Pro"

$CoreAppsList = "xpcoreprosoesp2.lst"

Case "Office 2003 Std"

$CoreAppsList = "xpcorestd2003soesp2.lst"

Case "Office 2003 Pro"

$CoreAppsList = "xpcorepro2003soesp2.lst"

;Case "Gold Build 3.0"

;$CoreAppsList = "GB3.0core.lst"

>>>>> Case "Gold Build"

GUICtrlSetState ($GoldBuildLabel, $GUI_SHOW)

GUICtrlSetState ($GoldBuildCombo, $GUI_SHOW)

GUICtrlSetOnEvent($GoldBuildCombo,"SetGoldCore")

Case "Other"

GUICtrlSetState ($WinInstallInput, $GUI_SHOW)

$CoreAppsList = GUICtrlRead ($WinInstallInput)

EndSwitch

msgbox(0,"Core Apps",$CoreAppsList)

If $CoreAppsList <> "Other" then

$CoreAppsLabel = GUICtrlCreateLabel($CoreAppsList,130, 176, 170, 20)

GUICtrlSetState($CoreAppsLabel, $GUI_SHOW)

GUICtrlSetColor(-1, 0xFFFF00)

GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

EndIf

EndFunc

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;

Func SetGoldCore ()

;

Switch GUICtrlRead($GoldBuildCombo)

Case "3.0"

$CoreAppsList = "GB3.0core.lst"

;Case ""

;$CoreAppsList = "GB3.0core.lst"

EndSwitch

msgbox(0,"Core Apps",$CoreAppsList)

EndFunc

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;

Link to comment
Share on other sites

Code snippet below (did not want to include all 185 lines of test code)

Perhaps put the rest of the code as an attachment? Either that, or use the forum "autoit" tags to pop it in the thread?

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Link to comment
Share on other sites

I don't know what else you expect...

At the beginning of SetCoreAppsList() you're clearing that variable. Later in this function the value of it doesn't change in the case of Gold. You're not calling any other function. You're just setting up an OnEvent function for that another combo (eventhough you should better be doing it in the beginning when creating GUI).

I think you slightly misunderstand how OnEvent functions work.

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

The variable clearing at the top of the form is done because some fields are hidden. If the user makes a different selection, I need those fields to revert to a hidden state.

I agree it should all be created in the main GUI section but this was an off the top mod and I was planning to go back and clean up later.

I was hoping that the SetGoldCore function would set the variable and (because the variable is global) it would carry back to the calling function which would then display the results. Until I understand why it does not work as I describe above, I cannot rewrite it correctly.

Link to comment
Share on other sites

I was hoping that the SetGoldCore function would set the variable and (because the variable is global) it would carry back to the calling function which would then display the results.

It carries back, but at the beginning of the SetCoreAppsList() function it is OVERWRITTEN with a "".

Ok, that's how it goes:

Selection in "Application suite" combobox changes, SetCoreAppsList() function is triggered. Global var $CoreAppsList is set to empty string. Then in case of first four items, it is written with a new value. In case of "Gold Build" a new combo box is set to be shown and OnEvent function for that combo is registered (this does not change $CoreAppsList in any way, and that function is NOT executed (not until user changes selection of that other combo)). And at the end of this function a label is created anew (not very smart practice too) and set with the $CoreAppsList (which in case of "Gold build" is still "").

Sorry but I'm not very good at explaining things.

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

I tried commenting that out but I still saw the same results. Also tried spreading msgbox around. In SetGoldCore it displays the correct value. If I placed one immediatley after the calling line, it returns a blank, even with the reset line commented out. It almost seems like the script does not wait for the calling function to return thus the variable is not set and therefore returns a blank.

Link to comment
Share on other sites

If I placed one immediatley after the calling line, it returns a blank, even with the reset line commented out.

Sighz... There is no "calling line". If you think that SetGoldCore() is somehow called from SetCoreAppsList(), you're fundamentally wrong. So far in your code SetGoldCore() is only executed when user changes Gold build combo.

Plz reread my previous post. Also you might want to read Helpfile about OnEvent mode.

Anyways, I'm done with this..., since either you're not listening, or I'm just a very bad instructor. :whistle:

Hope you get to the solution one way or another.

Edited by Siao

"be smart, drink your wine"

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