Sign in to follow this  
Followers 0
WoodGrain

Taking user input and calling a function from the input

3 posts in this topic

Hi guys,

Could someone please tell me what I'm doing wrong with this code?
I'm trying to take user input and then run a function with the same name, but it's not calling the function.

So in the below after pressing Shift+F8 I would enter the text (without quotes) "testFunc".
As you can see I've also tried this with IF statements, I'm new to using Switch/Case.

HotKeySet("+{F8}", RunManually)

Func RunManually()
   ;Use a case statement with 1 hot key and an InputBox to manually run functions
   $funcName = InputBox("Which Func to Run?", "Enter the name of the function to run")
   MsgBox(0, "Entered value", $funcName)
   ;If $funcName = testFunc Then testFunc()
   ;If $funcName = test2Func Then test2Func()
   Switch $funcName
      Case testFunc
         MsgBox(0, "Calling", "Calling Function")
         testFunc()
         MsgBox(0, "Called", "Function call finished")
      Case test2Func
         MsgBox(0, "Calling", "Calling Function")
         test2Func()
         MsgBox(0, "Called", "Function call finished")
   EndSwitch
EndFunc

While 1
   ;testFunc()
   Sleep(1000)
WEnd

Func testFunc()
      MsgBox(0, "func running", "Seems to work!")
EndFunc

Func test2Func()
      MsgBox(0, "func 2 running", "2 Seems to work!")
EndFunc

Thanks!

Share this post


Link to post
Share on other sites



Use quotation marks you are comparing against an String value which is what InputBox get...

HotKeySet("+{F8}", RunManually)

Func RunManually()
   ;Use a case statement with 1 hot key and an InputBox to manually run functions
   $funcName = InputBox("Which Func to Run?", "Enter the name of the function to run")
   MsgBox(0, "Entered value", $funcName)
   
   ;If $funcName = "testFunc" Then
    ;   testFunc()
   ;EndIf
   ;If $funcName = "test2Func" Then
       ;test2Func()
   ;EndIf
   
   Switch $funcName
      Case "testFunc"
         MsgBox(0, "Calling", "Calling Function")
         testFunc()
         MsgBox(0, "Called", "Function call finished")
     Case "test2Func"
       MsgBox(0, "Calling", "Calling Function")
      test2Func()
         MsgBox(0, "Called", "Function call finished")
   EndSwitch
EndFunc

While 1
   ;testFunc()
   Sleep(1000)
WEnd

Func testFunc()
      MsgBox(0, "func running", "Seems to work!")
EndFunc

Func test2Func()
      MsgBox(0, "func 2 running", "2 Seems to work!")
EndFunc

Note both versions works, the one with the IF and the one with the Case...
 

 

Share this post


Link to post
Share on other sites

Thanks!!

Share this post


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
Sign in to follow this  
Followers 0

  • Similar Content

    • Skysnake
      By Skysnake
      From From here, bottom of the post
      I am not arguing the logic of this, merely would like to point out that if there is such a rule, it is not documented...  Are there other such rules?
      Skysnake
    • wakillon
      By wakillon
      SciTE Hopper : Jump to Any line by one click and many other helpfull functions !


      As Ashalshaikh suggested me after leaving me the task to continue >SciTE Hopper, i open a new Topic about it.
      It will be more easy for futures updates.

      Many helpfull functions in contextual menu.
      SciTE Hopper is now multipurpose.
      • Color Catcher added
      • BinaryToAu3Kompressor added
      • TinyAu3Search replaced by StringFinder
      • RegJumper added
      • Edit With SciTE added (available in Options)
      • SpecialCharactersViewer added (available in Tray menu)
      New Contextual Menu :

      For a right Click on a function :

      • Copy function name
      • Insert a function header
      • Cut function
      • Copy function
      • Delete function
      • Create a variables List
      • Remove usseless Blank lines
      • Remove Debug lines ( all lines starting with ConsoleWrite or _ArrayDisplay )
      • Set AutoIt Code Layout
      • Remove Comments

      For entire script :

      • Create a functions List
      • Create a variables List
      • Remove usseless Blank lines
      • Remove Debug lines ( all lines starting with ConsoleWrite or _ArrayDisplay )
      • Set AutoIt Code Layout
      • Remove Comments
      • ( Open in SciTE a ) Duplicate of current Script in Temp Dir
      • ( Open in SciTE a ) Duplicate of current Script in Same Dir
      • Explore Parent Script Folder
      • Copy Script name
      • Copy Script path
      • Find Unused Functions
      • Find Unused Variables
      • Set all functions in alphabetic order.( func headers and regions ( in fact, all lines between functions ) are not supported.)

      SciTE Editor New Contextual Menu if SciTE Hopper is added ( in Options ) to SciTE Editor :
      when you made a selection in SciTE Editor you can :

      • Open a Reg Key in Regedit using RegJumper
      • Open a Url in your default Browser
      • Search on google in your default Browser
      • Search on AutoIt Website in your default Browser
      Now Can be added to windows start (minimized)
      Options are available by Tray Menu.
      A double click on tray icon will open clipboard content to SciTE Editor ( Handy when you have copied some code from your browser )

      How to proceed for add SciTE Hopper to SciTE Editor :
      Run Scite Editor, run Scite Hopper ( compiled! ) go to Options and select Add/Remove to SciTE Tab. then click on Add button and it's done !
      Right click on SciTE Editor and choose SciTE Hopper in Contextual Menu for run it when you need it !
      Update of 07 Dec 2017
      TinyAu3Search is replaced by StringFinder

      Previous downloads : 1287
      Script and compiled version are available in the download section
       
      Thanks to Ashalshaikh, Melba23, Th3 MMA, Alzri2, taitel, Manadar, taz742, Yashield, Authenticity, Xenobiologist for their help
      and asdf8 for his >Includes Helper and azjio for his >FileSearch.

      Hope it help you and happy Scripting !

       
    • mati
      By mati
      Hi,
      I wonder if
      AutoIt3Wrapper_run_debug_mode = Y can include run information about functions which are called within the main code. So far I noticed in the console that the function itself is called but no specific run information from  inside the function is provided. Is there a chance to show the entire debug log including functions in the console?
      I furthermore noticed a stop of information when a loop is entered. What could be the reason for that?
       
      Thanks for help.
    • TrashBoat
      By TrashBoat
      Is this possible:
      Executing a function from an include, but taking the function name from a gui input and then executing that function using the include:
      #include <Something.au3> ;input reads "Tree" $functionName = GuiCtrlRead($input1) $functionName(1) And the include is gonna have
      Func Tree($x) If $x = 1 Then $this = "text" MsgBox(0,$this,"whatever") EndFunc is it possible?
    • hcI
      By hcI
      Hello, i'm making a little script that lets users enter a question and if the script can't answer to, it ask what would be the answer (a bit like siri on IPhones). And I try to display the "supposed array" I still have an error.. I searched on Google and got nothing looked in the help file too.. I'm here to know if someone have a solution to my error please.
      Here is where $a and $b should become arrays :
      Dim $dossier = @AppDataDir & "\Siri2" Dim $chemin = $dossier & "\data.ini" Global $a = _InfoRead($chemin, 0) Global $b = _InfoRead($chemin, 1) with this function :
      Func _InfoRead($path, $mode = 0) If DirGetSize($dossier) = -1 Then Return SetError(-4) If Not FileExists($chemin) Then Return SetError(-5) Local $readed = IniReadSection($path, "data") If @error Then Return SetError(-3) $size = $readed[0][0] Local $return[$size] For $i = 1 To $size Step 1 $return[$i - 1] = $readed[$i][$mode] Next Return $return EndFunc and the thing that i don't understand is that, after _InfoRead return affected to $a, I can't use _ArrayDisplay because of  error 1 "$aArray is not an array" (and same fpr the variable $b)..
      Can please someone help me to understand why is it doing this ?

      -hcI