Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 260
Default Function variables

hey guys I have a function and need to preserve its value
once the function ends. I need to store this value as a
variable in another module. Is this possible?


Todd Huttenstine
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Function variables

Hi
just call your function from the other fucntion/procedure and store the
result in a variable. e.g.

Sub foo()
dim ret_value
ret_value = do_calculate(5)
msgbox ret_value
end sub

function do_calculate(i)
do_calculate = i*2
end function

--
Regards
Frank Kabel
Frankfurt, Germany

"Todd Huttenstine" schrieb im
Newsbeitrag ...
hey guys I have a function and need to preserve its value
once the function ends. I need to store this value as a
variable in another module. Is this possible?


Todd Huttenstine


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Function variables

Can't you just run the function again?

If not, save the result as a Module scope variable.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Todd Huttenstine" wrote in message
...
hey guys I have a function and need to preserve its value
once the function ends. I need to store this value as a
variable in another module. Is this possible?


Todd Huttenstine



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 260
Default Function variables

I cant get this to work. heres what I did...

Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" ( _
ByVal lpBuffer As String, nSize As Long) As Long

Public Sub WindowsUserName()
Dim UName As String * 255
Dim nn
Dim L As Long: L = 255
Dim Res As Long
Res = GetUserName(UName, L)
UName = Left$(UName, L - 1)
nn = Trim(UName)
End Sub



-----Original Message-----
Can't you just run the function again?

If not, save the result as a Module scope variable.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Todd Huttenstine"

wrote in message
...
hey guys I have a function and need to preserve its

value
once the function ends. I need to store this value as a
variable in another module. Is this possible?


Todd Huttenstine



.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Function variables

Hi
and what's your problem. 'nn' contains the Windows user name which you
could check with an added statement like
msgbox nn


--
Regards
Frank Kabel
Frankfurt, Germany

"Todd Huttenstine" schrieb im
Newsbeitrag ...
I cant get this to work. heres what I did...

Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" ( _
ByVal lpBuffer As String, nSize As Long) As Long

Public Sub WindowsUserName()
Dim UName As String * 255
Dim nn
Dim L As Long: L = 255
Dim Res As Long
Res = GetUserName(UName, L)
UName = Left$(UName, L - 1)
nn = Trim(UName)
End Sub



-----Original Message-----
Can't you just run the function again?

If not, save the result as a Module scope variable.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Todd Huttenstine"

wrote in message
...
hey guys I have a function and need to preserve its

value
once the function ends. I need to store this value as a
variable in another module. Is this possible?


Todd Huttenstine



.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Function variables

Because the username function is in another module and I
need to reference variable nn.
-----Original Message-----
Hi
and what's your problem. 'nn' contains the Windows user

name which you
could check with an added statement like
msgbox nn


--
Regards
Frank Kabel
Frankfurt, Germany

"Todd Huttenstine"

schrieb im
Newsbeitrag ...
I cant get this to work. heres what I did...

Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" ( _
ByVal lpBuffer As String, nSize As Long) As Long

Public Sub WindowsUserName()
Dim UName As String * 255
Dim nn
Dim L As Long: L = 255
Dim Res As Long
Res = GetUserName(UName, L)
UName = Left$(UName, L - 1)
nn = Trim(UName)
End Sub



-----Original Message-----
Can't you just run the function again?

If not, save the result as a Module scope variable.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the

Purbecks
(remove nothere from the email address if mailing

direct)

"Todd Huttenstine"


wrote in message
...
hey guys I have a function and need to preserve its

value
once the function ends. I need to store this value

as a
variable in another module. Is this possible?


Todd Huttenstine


.


.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Function variables

Hi Todd
why not create an additional function like

Public Function Get_Str_UserName()
Dim UName As String * 255
Dim nn
Dim L As Long: L = 255
Dim Res As Long
Res = GetUserName(UName, L)
UName = Left$(UName, L - 1)
nn = Trim(UName)
Get_Str_UserName = nn
End Function

Now call this function from your other module.
Another option would be to create a public variable and initialize this
variable in the workbook_open event. But I'd prefer using a function
like shjown above for this

--
Regards
Frank Kabel
Frankfurt, Germany

"Todd Htutenstine" schrieb im
Newsbeitrag ...
Because the username function is in another module and I
need to reference variable nn.
-----Original Message-----
Hi
and what's your problem. 'nn' contains the Windows user

name which you
could check with an added statement like
msgbox nn


--
Regards
Frank Kabel
Frankfurt, Germany

"Todd Huttenstine"

schrieb im
Newsbeitrag ...
I cant get this to work. heres what I did...

Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" ( _
ByVal lpBuffer As String, nSize As Long) As Long

Public Sub WindowsUserName()
Dim UName As String * 255
Dim nn
Dim L As Long: L = 255
Dim Res As Long
Res = GetUserName(UName, L)
UName = Left$(UName, L - 1)
nn = Trim(UName)
End Sub



-----Original Message-----
Can't you just run the function again?

If not, save the result as a Module scope variable.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the

Purbecks
(remove nothere from the email address if mailing

direct)

"Todd Huttenstine"


wrote in message
...
hey guys I have a function and need to preserve its
value
once the function ends. I need to store this value

as a
variable in another module. Is this possible?


Todd Huttenstine


.


.


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Function variables

Hi Todd

Like this ?

Function MyL(FinalDigit As Long) As Long
MyL = Second(Now) * 1000 + FinalDigit
End Function

Sub test()
Dim L As Long
L = MyL(3)
MsgBox L
MsgBox "Other things inbetween"
MsgBox L, , "Still here :-)"
End Sub

HTH. Best wishes Harald

"Todd Huttenstine" skrev i melding
...
hey guys I have a function and need to preserve its value
once the function ends. I need to store this value as a
variable in another module. Is this possible?


Todd Huttenstine



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
using =IF function with 12 variables swell estimator[_2_] Excel Discussion (Misc queries) 4 September 8th 08 12:09 AM
COUNTIF Function with variables TJ Excel Worksheet Functions 6 September 5th 08 03:16 AM
DDE function with variables Toledo Excel Worksheet Functions 0 November 30th 07 06:12 AM
Can I use variables in a Range function? André - Brazil Excel Discussion (Misc queries) 2 May 5th 05 10:39 PM
Countif function with variables SMANDA Excel Worksheet Functions 0 February 7th 05 10:46 PM


All times are GMT +1. The time now is 09:44 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"