Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pass variables to functions as arguments
#1
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
#2
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
Code:
Copy      Help
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.
#3
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
Code:
Copy      Help
;;text input here
str controls = "9"
str e9
str s
if(!ShowDialog("Function9" &Function9 &controls)) ret
Function Function9
Code:
Copy      Help
;;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
Code:
Copy      Help
;;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
Code:
Copy      Help
;;out text input from main
rep
    out e9
#4
need to change some code
get text input from Function9 and pass to Function7 using mac command argument(1st arg)
Function Function9
Code:
Copy      Help
,case IDOK
,_s.getwintext(id(9 hDlg))
,mac "Function7" _s

pass command arg to macro8 using received _command variable
Function Function7
Code:
Copy      Help
,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
Code:
Copy      Help
;;out text input from main
function str's
rep 
,0.2
,out s
#5
it works perfectly. thank you very much for your help <3
#6
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
#7
make these changes

Function Main
Code:
Copy      Help
;;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
Code:
Copy      Help
;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
Code:
Copy      Help
;;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
Code:
Copy      Help
;;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?
#8
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
#9
change function main to this

Function Main
Code:
Copy      Help
;;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
Code:
Copy      Help
,case IDOK
,mac "UI"
,shutdown -6 0 "Macro8"
to this
Code:
Copy      Help
,case IDOK
,shutdown -6 0 "Macro8"
#10
thanks for your example. Sir you're amazing


Forum Jump:


Users browsing this thread: 1 Guest(s)