Newtoai Posted April 20, 2011 Share Posted April 20, 2011 Hi, I'm totally struck with the declaration of variables, and / or with Select and Switch. I'm trying to set up a macro system for my computer, for various hotkeys and for different scopes, i.e. depending on the program that is running, the same hotkey is to have a different effect, i.e. to trigger a different macro. Thus, I did this: global $scope ; is to be numeric, I first called it just $s, but 1 character or more, problems stay global $title ; this is the name of the current program in use Opt("WinTitleMatchMode", 2) ; set to "substring" (default is 1 = "start") ; this is necessary since the titles contain program names AND file names, sometimes at the beginning Opt("MustDeclareVars", 1) ; yes (default is 0 = no) ; yes or no doesn't make any difference for my problem ; here I deleted most of my script in order to make it more readable: hotkeyset ("{F3}", "A" ) hotkeyset ("{F4}", "B" ) hotkeyset ("{F5}", "C" ) While 1 Sleep (100) Wend Func A() GetScope() ; runs my function GetScope() below ; gets never back to function A() though: Switch $scope Case 1 Send("^c") Case 2 Send("^c") Case 3 Send("^c") MsgBox(0, "And again, scope is:", $scope) ; never... Case 4 Send("^c") Endswitch ; of course, I tried with Select, then Case $scope = 1, $scope = 2, etc. ; I also tried with "==" instead of "=", to no avail Endfunc Func B() GetScope() ; same missing of results Endfunc Func C() ; etc. etc. Endfunc Func GetScope() $title = WinGetTitle("[active]") ; this indeed gets the correct title into that variable Switch $title Case "iGrafx Flowcharter 2000" $scope = 1 Case "ActionOutline" $scope = 2 Case "Ultra Recall Professional" $scope = 3 Case "Windows Internet Explorer" $scope = 4 ; I tried all these with and without indentation, to no avail EndSwitch MsgBox(0, "Full title of active window is:", $title) ; it's correctly presented MsgBox(0, "Scope is:", $scope) ; it's always void or 0 (zero) if I had initialized it that way Endfunc ; Thus, NEVER EVER the statement line(s) after the case lines are executed, the values (1 to 4) are ; never assigned to the (numerical) variable. What do I wrong, please? (Of course, I tried the help and the forum, for Select, Switch, declaration of variables, scope of variables, variable assignment, call for functions within other functions, etc. etc.) Link to comment Share on other sites More sharing options...
Developers Jos Posted April 20, 2011 Developers Share Posted April 20, 2011 You are doing an exact match in the GetScope() Func and likely the Window title is different. E.g.: Case "Windows Internet Explorer" The content in $title is more than the Case string you test against. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
BrewManNH Posted April 20, 2011 Share Posted April 20, 2011 Your problem is that you're not trying to compare the Window title with the Case statements. You're comparing the contents of $title variable to part of what you're expecting the window title to be. Try this instead: Select Case StringInStr($title, "iGrafx Flowcharter 2000") $scope = 1 Case StringInStr($title, "ActionOutline") $scope = 2 Case StringInStr($title, "Ultra Recall Professional") $scope = 3 Case StringInStr($title, "Windows Internet Explorer") $scope = 4 ; I tried all these with and without indentation, to no avail EndSelect 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...
Newtoai Posted April 20, 2011 Author Share Posted April 20, 2011 Jos and BrewManNH, you're both totally right, I am deeply indebted to you. This is a tremendous site with tremendous help, that's why I've chosen AI over AHK. I'm really glad such a fine community exists. (I've finally come to experiment with AI, so I'm a total beginner, and thus I only searched my probable error in the probable misunderstanding of the language, instead of also checking the logic of my thinking, that's why I'd been stuck. Many, many thanks again!) 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