Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

difference between SUB and Function in vb scripting

I have a Macro code which starts with Sub Macroname........and in that code I am also having a Function FunctionNmae.......

when I try to run that macro.....should I use two names...I mean should I have to give triggers to run macro on both SUB and Function........

1 Solution

Accepted Solutions
Gysbert_Wassenaar

A function executes code and returns a result, a sub only executes code but doesn't return a result. You should use subs for macros. Subs can call functions (and other subs). Try adding the code below in the macro editor and click the Test button.

Function TimesTwo(X)

   TimesTwo = X+X

end function

Sub Add

  result =  TimesTwo(3)

  msgbox result

end Sub


talk is cheap, supply exceeds demand

View solution in original post

4 Replies
Gysbert_Wassenaar

A function executes code and returns a result, a sub only executes code but doesn't return a result. You should use subs for macros. Subs can call functions (and other subs). Try adding the code below in the macro editor and click the Test button.

Function TimesTwo(X)

   TimesTwo = X+X

end function

Sub Add

  result =  TimesTwo(3)

  msgbox result

end Sub


talk is cheap, supply exceeds demand
Not applicable
Author

Thankyou.....So if I have one Sub and two functions I need to run macro and give sub name and should not worry about the functions......

Gysbert_Wassenaar

Yes, don't worry about the functions. Just use the subs for the run-macro actions


talk is cheap, supply exceeds demand
Not applicable
Author

Thankyou Gysbert....I am still trying to send report after reload as email trough macro....I am not finding exact code.......I went trough community but did not find one........Can you Please help me out........