Posts: 14
Threads: 6
Joined: Jun 2019
Hello again, it's me. I'm trying to pass the value between 2 functions I tried using Global variables it works but in QM help mentioned that "Don't use global variables where not necessary. Where possible, use local variables, thread variables, pass variables to functions as arguments." I tried pass variables to functions as arguments but unsuccessfully anyone could give me an example of how to pass variables to functions as arguments. thank you very much
Posts: 1,337
Threads: 61
Joined: Jul 2006
05-26-2021, 01:26 AM
(This post was last modified: 05-26-2021, 05:39 AM by Kevin.)
see https://www.quickmacros.com/help/QM_Help...PS.html#L2
for more information on how to pass and receive
example from qm help
Function Example
lpstr s1="c:\md\t.txt"
str s2
int i
i=sub.fileext(s1 s2)
out "%i %s" i s2
#sub fileext
function lpstr'f str&e
int i=findcr(f '.')
if(i>=0) e.get(f i)
else e=""
ret i
Need more information to to advise further.
Posts: 14
Threads: 6
Joined: Jun 2019
05-26-2021, 04:42 AM
(This post was last modified: 05-26-2021, 04:48 AM by yiifm.)
Thank you. this is my code for some reason I can only install very old version pre-installed can not update so sub function can not be used.
Function Main
;;text input here
str controls = "9"
str e9
str s
if(!ShowDialog("Function9" &Function9 &controls)) ret
Function Function9
;;form input
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
BEGIN DIALOG
0 "" 0x90C80AC8 0x8 0 0 400 200 "Test"
3 Static 0x54000201 0x0 26 20 60 15 "ID"
9 Edit 0x54030080 0x200 100 20 110 15 ""
20 Static 0x54000011 0x20000 222 18 1 143 ""
21 Static 0x54000010 0x20000 212 90 11 1 ""
1 Button 0x54030001 0x0 152 176 48 14 "OK"
2 Button 0x54030000 0x0 216 176 48 14 "Cancel"
END DIALOG
DIALOG EDITOR: "" 0x2030605 "" "" "" ""
ret
messages
sel message
case WM_INITDIALOG
case WM_DESTROY
case WM_COMMAND goto messages2
ret
messages2
sel wParam
case IDOK
mac "Function7"
case IDCANCEL
case 26
mac "Function3"
ret 1
Function Function7
;;dialog start and stop
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
str controls = "3"
str c3Sta
if(!ShowDialog("Function7" &Function7 &controls)) ret
BEGIN DIALOG
0 "" 0x90C80AC4 0x108 0 0 63 46 "CB"
3 Button 0x54013003 0x0 6 6 48 14 "Start"
1 Button 0x54030001 0x0 6 24 48 14 "Back"
END DIALOG
DIALOG EDITOR: "" 0x2030605 "" "" "" ""
ret
messages
sel message
case WM_INITDIALOG
case WM_DESTROY
case WM_COMMAND goto messages2
ret
messages2
sel wParam
case 3
if(but(lParam)) ;;checked
mac "Macro8"
_s="Stop"
else ;;unchecked
shutdown -6 0 "Macro8"
_s="Start"
_s.setwintext(lParam)
case IDOK
mac "UI"
shutdown -6 0 "Macro8"
case IDCANCEL
ret 1
Macro Macro8
;;out text input from main
rep
out e9
Posts: 1,337
Threads: 61
Joined: Jul 2006
05-26-2021, 02:28 PM
(This post was last modified: 05-26-2021, 02:36 PM by Kevin.)
need to change some code
get text input from Function9 and pass to Function7 using mac command argument(1st arg)
Function Function9
,case IDOK
,_s.getwintext(id(9 hDlg))
,mac "Function7" _s
pass command arg to macro8 using received _command variable
Function Function7
,case 3
,if(but(lParam)) ;;checked
,,mac "Macro8" "" _command
,,_s="Stop"
,else ;;unchecked
,,shutdown -6 0 "Macro8"
,,_s="Start"
,_s.setwintext(lParam)
setup macro8 to receive arguments
Macro Macro8
;;out text input from main
function str's
rep
,0.2
,out s
Posts: 14
Threads: 6
Joined: Jun 2019
it works perfectly. thank you very much for your help <3
Posts: 14
Threads: 6
Joined: Jun 2019
05-27-2021, 05:26 PM
(This post was last modified: 05-27-2021, 05:41 PM by yiifm.)
Hello, Kenvin. I followed your example and finished my function it worked perfectly in QM but when I made it into exe(all functions and text were added to exe) but when Function7 should have run and displayed the start button, the software (created from QM) simply disappeared with no error messages. I don't know what happened. can you please help me with this error
p/s: I just thought maybe I need to create a separate exe for each function and instead of using mac "Function7" I will use run command. Now it's almost 1am in my country I'll try it first in the morning. thank you anyway
Posts: 1,337
Threads: 61
Joined: Jul 2006
05-28-2021, 04:13 AM
(This post was last modified: 05-28-2021, 04:18 AM by Kevin.)
make these changes
Function Main
;;text input here
str controls = "9"
str e9
str s
if(!ShowDialog("Function9" &Function9 &controls)) ret
type MyVARIABLES str'idcode
MyVARIABLES x; x.idcode=e9
str controls2 = "3"
str c3Sta
if(!ShowDialog("Function7" &Function7 &controls2 0 0 0 0 &x)) ret
Function Function7
;dialog start and stop
;\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
;BEGIN DIALOG
;0 "" 0x90C80AC4 0x108 0 0 63 46 "CB"
;3 Button 0x54013003 0x0 6 6 48 14 "Start"
;1 Button 0x54030001 0x0 6 24 48 14 "Back"
;END DIALOG
;DIALOG EDITOR: "" 0x2030605 "" "" "" ""
ret
;messages
MyVARIABLES& x=+DT_GetParam(hDlg)
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3
,if(but(lParam)) ;;checked
,,mac "Macro8" "" x.idcode
,,_s="Stop"
,else ;;unchecked
,,shutdown -6 0 "Macro8"
,,_s="Start"
,_s.setwintext(lParam)
,case IDOK
,mac "UI"
,shutdown -6 0 "Macro8"
,case IDCANCEL
ret 1
Function Function9
;;form input
;\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x8 0 0 400 200 "Test"
;3 Static 0x54000201 0x0 26 20 60 15 "ID"
;9 Edit 0x54030080 0x200 100 20 110 15 ""
;20 Static 0x54000011 0x20000 222 18 1 143 ""
;21 Static 0x54000010 0x20000 212 90 11 1 ""
;1 Button 0x54030001 0x0 152 176 48 14 "OK"
;2 Button 0x54030000 0x0 216 176 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2030605 "" "" "" ""
ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
convert Macro8 to a function
Function Macro8
;;out text input from main
function str's
rep
,0.2
,out s
create a folder named Main
place all these functions inside the folder then make exe of folder
Question?? The back button in Function7 dialog Is it suppose to open Function9 dialog?
Posts: 14
Threads: 6
Joined: Jun 2019
thank you kevin. I'll try it right away.
Quote:Question?? The back button in Function7 dialog Is it suppose to open Function9 dialog?
And yes back button in function7 will open function9 my idea is that if you need to change something you just need to click the back button and enter again
Posts: 1,337
Threads: 61
Joined: Jul 2006
change function main to this
Function Main
;;text input here
str controls = "9"
str e9
str s
if(!ShowDialog("Function9" &Function9 &controls)) ret
type MyVARIABLES str'idcode
MyVARIABLES x; x.idcode=e9
str controls2 = "3"
str c3Sta
int retVal=ShowDialog("Function7" &Function7 &controls2 0 0 0 0 &x)
if retVal=1
,goto text input here
and in Function7
change this
,case IDOK
,mac "UI"
,shutdown -6 0 "Macro8"
to this
,case IDOK
,shutdown -6 0 "Macro8"
Posts: 14
Threads: 6
Joined: Jun 2019
05-28-2021, 08:09 AM
(This post was last modified: 05-28-2021, 08:09 AM by yiifm.)
thanks for your example. Sir you're amazing
|