excel - VBA: Calling a Function -


i'm trying clean coding overall. that, want turn lot of code functions.

in java, worked (exactly?) how have code below.

the line originatedateitems() execute following function:

function originatedateitems()  currentmonth = format(date, "mmmm") 'july currentdate = format(date, "mm-dd-yy") '06-09-15 currentyear2char = format(date, "yy") '15 currentyear4char = format(date, "yyyy") '2015 currentfiscalmonth = format(dateadd("m", 1, date), "mm") '08 wsdate = currentfiscalmonth & currentyear4char '082015  end function 

would able explain how call function without using = or of sort?

thank much.

a function returns value. it's meant used something = originatedateitems()

now sub meant run something.

if write function sub:

sub originatedateitems()      currentmonth = format(date, "mmmm") 'july     vcurrentdate = format(date, "mm-dd-yy") '06-09-15     currentyear2char = format(date, "yy") '15     currentyear4char = format(date, "yyyy") '2015     currentfiscalmonth = format(dateadd("m", 1, date), "mm") '08     wsdate = currentfiscalmonth & currentyear4char '082015  end sub 

then vars (currentmonth, currentyear, etc) must global (outside sub), otherwise not visible.

just call like

call originatedateitems 

if want sub return them code called it, can pass parameters byref:

sub originatedateitems(byref currentmonth, byref vcurrentdate, .....)      currentmonth = format(date, "mmmm") 'july     vcurrentdate = format(date, "mm-dd-yy") '06-09-15     currentyear2char = format(date, "yy") '15     currentyear4char = format(date, "yyyy") '2015     currentfiscalmonth = format(dateadd("m", 1, date), "mm") '08     wsdate = currentfiscalmonth & currentyear4char '082015  end sub 

then call like:

 call originatedateitems(currentmonth, vcurrentdate, currentyeartochar......) 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -