Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default passing a value back to original routine


Hi,

I use a peice of code 7 times (once for each day of the week), to
identify unallocated jobs.
I call this code 7 times from a routine (passing the dayname etc).

How can I add the total resulting unallocated jobs back to the
original routine, so I can use the value in an end message to the
user?

Should I just use a public variable?

Kind regards,
Matt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default passing a value back to original routine

Make it a function:

Function GetUnAllocatedJobs(strDayName As String) As Long

Dim x as Long

'run code here to get unallocated jobs, producing a number x
GetUnAllocatedJobs = x

End Function


RBS


"MJKelly" wrote in message
...

Hi,

I use a peice of code 7 times (once for each day of the week), to
identify unallocated jobs.
I call this code 7 times from a routine (passing the dayname etc).

How can I add the total resulting unallocated jobs back to the
original routine, so I can use the value in an end message to the
user?

Should I just use a public variable?

Kind regards,
Matt


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default passing a value back to original routine

You can also pass a variable by reference

Sub Test1()
Dim a as Integer
a = 1
call Test2(a)
msgbox(a)
End Sub

Sub Test2(ByRef x as Integer)
x = x + 5
End Sub


"RB Smissaert" wrote:

Make it a function:

Function GetUnAllocatedJobs(strDayName As String) As Long

Dim x as Long

'run code here to get unallocated jobs, producing a number x
GetUnAllocatedJobs = x

End Function


RBS


"MJKelly" wrote in message
...

Hi,

I use a peice of code 7 times (once for each day of the week), to
identify unallocated jobs.
I call this code 7 times from a routine (passing the dayname etc).

How can I add the total resulting unallocated jobs back to the
original routine, so I can use the value in an end message to the
user?

Should I just use a public variable?

Kind regards,
Matt



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default passing a value back to original routine

Yes, I know, but I think in this case a function is better as it is clearer
what is going on and less confusing.

RBS

"Joel" wrote in message
...
You can also pass a variable by reference

Sub Test1()
Dim a as Integer
a = 1
call Test2(a)
msgbox(a)
End Sub

Sub Test2(ByRef x as Integer)
x = x + 5
End Sub


"RB Smissaert" wrote:

Make it a function:

Function GetUnAllocatedJobs(strDayName As String) As Long

Dim x as Long

'run code here to get unallocated jobs, producing a number x
GetUnAllocatedJobs = x

End Function


RBS


"MJKelly" wrote in message
...

Hi,

I use a peice of code 7 times (once for each day of the week), to
identify unallocated jobs.
I call this code 7 times from a routine (passing the dayname etc).

How can I add the total resulting unallocated jobs back to the
original routine, so I can use the value in an end message to the
user?

Should I just use a public variable?

Kind regards,
Matt




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default passing a value back to original routine

Thanks for the replies.

Could you just explain how I use the function?

macro1 does a number of things and calls the function 7 times...
At the end of macro1, I want to tell the user the total number of
unallocated jobs (all days added together).

So, would this be msgbox getunallocatedjobs?
I still only see this working by declaring a public variable to hold
the unallocated jobs for Monday, then add Tuesday count to it and so
on. This being the value of x for each time the function is called?


Thanks,
Matt


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default passing a value back to original routine

If the function is called 7 times in the same procedure then you can do
this:

Dim lSum As Long

lSum = lSum + GetUnAllocatedJobs("Monday")
lSum = lSum + GetUnAllocatedJobs("Tuesday")

etc.

If it is called in different procedures then lSum has to be a Public
(applies to whole workbook)
or Private (applies to that module only) variable.


RBS


"MJKelly" wrote in message
...
Thanks for the replies.

Could you just explain how I use the function?

macro1 does a number of things and calls the function 7 times...
At the end of macro1, I want to tell the user the total number of
unallocated jobs (all days added together).

So, would this be msgbox getunallocatedjobs?
I still only see this working by declaring a public variable to hold
the unallocated jobs for Monday, then add Tuesday count to it and so
on. This being the value of x for each time the function is called?


Thanks,
Matt


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Going back to original location Té Excel Discussion (Misc queries) 1 August 27th 09 03:06 AM
Back to original Formating parteegolfer Excel Programming 3 February 28th 06 07:01 PM
Back to original file brook6 Excel Programming 3 April 7th 04 08:06 PM
Passing arguments to a sub routine... Jeff Harbin[_2_] Excel Programming 2 January 29th 04 03:25 AM
using VBA to go back to the original value before the cell was changed mika. Excel Programming 2 September 10th 03 09:09 PM


All times are GMT +1. The time now is 02:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"