How to make fn() function work in this simple GUI? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

How to make fn() function work in this simple GUI?

10 Jun 2019, 02:02

Hello Friends..


Please look at these codes-

Code: Select all

Gui Add, Edit, x165 y66 w120 h21 vv1 gg1
Gui Add, Edit, x365 y63 w120 h21 vv2

Gui Show, w620 h420, Window
Return

g1:
fn(v2, v1)
return

fn(param1, param2)
{
	gui, Submit, NoHide
	GuiControl,,param1, % param2*100
}
The above codes are not working. While the following codes are working fine-

Code: Select all

Gui Add, Edit, x165 y66 w120 h21 vv1 gg1
Gui Add, Edit, x365 y63 w120 h21 vv2

Gui Show, w620 h420, Window
Return

g1:
gui, Submit, NoHide
GuiControl,,v2, % v1*100
return
I am not understanding why earlier codes are not working. I want to use functions in gui that's why i made fn() function in first example. But this is not working. Have I make any mistake in making and calling function?

Please tell and guide..

Thanks a lot..
I don't normally code as I don't code normally.
aifritz
Posts: 301
Joined: 29 Jul 2018, 11:30
Location: Germany

Re: How to make fn() function work in this simple GUI?

10 Jun 2019, 02:45

Code: Select all

fn(param1, param2)
   {
     global
     gui, Submit, NoHide 
     GuiControl,,param1, % param2*100
  }
Try it, using the global command inside the function and it may work...
just me
Posts: 9574
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to make fn() function work in this simple GUI?

10 Jun 2019, 04:11

There are several errors in your approach.
  1. Code: Select all

    g1:
    fn(v2, v1)
    return
    If you want to pass the contents of the control variables to the function, you have to get the current contents of the controls by either Gui, Submit, ... or GuiControlGet, ... prior to this.
  2. Code: Select all

    	gui, Submit, NoHide
    This updates the global variables v1 and v2. When used within an assume-local function (default), the function cannot access the variables. And even if it could, ...
  3. Code: Select all

         GuiControl,,param1, % param2*100
    ... you don't use the control variables here. param1 is taken as a literal control name and % param2*100 uses the value passed in param2.
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: How to make fn() function work in this simple GUI?  Topic is solved

10 Jun 2019, 05:23

Code: Select all

Gui Add, Edit, w200 vv1 gg1
Gui Add, Edit, w200 vv2
Gui Show
Return

g1:
gui, Submit, NoHide
fn("v2", v1)
return

fn(param1, param2) {
    GuiControl,,%param1%, % param2*100
}
ExitApp
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

Re: How to make fn() function work in this simple GUI?

10 Jun 2019, 08:17

Odlanir wrote:
10 Jun 2019, 05:23

Code: Select all

Gui Add, Edit, w200 vv1 gg1
Gui Add, Edit, w200 vv2
Gui Show
Return

g1:
gui, Submit, NoHide
fn("v2", v1)
return

fn(param1, param2) {
    GuiControl,,%param1%, % param2*100
}
ExitApp
Thanks dear Odlanir... Now codes are working... Thanks a lot ... :clap:
I don't normally code as I don't code normally.
User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

Re: How to make fn() function work in this simple GUI?

10 Jun 2019, 08:19

just me wrote:
10 Jun 2019, 04:11
There are several errors in your approach.
  1. Code: Select all

    g1:
    fn(v2, v1)
    return
    If you want to pass the contents of the control variables to the function, you have to get the current contents of the controls by either Gui, Submit, ... or GuiControlGet, ... prior to this.
  2. Code: Select all

    	gui, Submit, NoHide
    This updates the global variables v1 and v2. When used within an assume-local function (default), the function cannot access the variables. And even if it could, ...
  3. Code: Select all

         GuiControl,,param1, % param2*100
    ... you don't use the control variables here. param1 is taken as a literal control name and % param2*100 uses the value passed in param2.


Thanks dear just me for tell my mistakes.... It really helped me understanding concepts.. Thank you sir.. :bravo:
I don't normally code as I don't code normally.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], peter_ahk, PuzzledGreatly and 300 guests