Hello,

I want to return a value with a function. I call the function like this :

NameVar = function(NameVar2)

The code of the function looks like this :

function(NameVar2)

If NameVar2 = statement Then
function = 0
Else
function = 1
End if

After I called the function, the variable NameVar contains absolutelly
nothing. What am I doing wrong?

Thank you.

Re: Function returning a value by Pegasus

Pegasus
Mon Jul 07 13:16:18 CDT 2008


"Meat" <Meat@discussions.microsoft.com> wrote in message
news:23F81DFD-D722-4560-986D-620D31EC1046@microsoft.com...
> Hello,
>
> I want to return a value with a function. I call the function like this :
>
> NameVar = function(NameVar2)
>
> The code of the function looks like this :
>
> function(NameVar2)
>
> If NameVar2 = statement Then
> function = 0
> Else
> function = 1
> End if
>
> After I called the function, the variable NameVar contains absolutelly
> nothing. What am I doing wrong?
>
> Thank you.

"function" is a reserved name. Furthermore it is not a good
idea to use the same variable name in the main program
and in the function. Try this:

NameVar = Test(NameVar2)

function Test(MyString)
If MyString = "some string" Then
Test = 0
Else
Test = 1
End if
end function



Re: Function returning a value by Meat

Meat
Tue Jul 08 07:21:00 CDT 2008

Yes, that's what I did, I'm sorry for the error in this post.

I don't know why but the function returns absolutely nothing.

"Pegasus (MVP)" wrote:

>
> "Meat" <Meat@discussions.microsoft.com> wrote in message
> news:23F81DFD-D722-4560-986D-620D31EC1046@microsoft.com...
> > Hello,
> >
> > I want to return a value with a function. I call the function like this :
> >
> > NameVar = function(NameVar2)
> >
> > The code of the function looks like this :
> >
> > function(NameVar2)
> >
> > If NameVar2 = statement Then
> > function = 0
> > Else
> > function = 1
> > End if
> >
> > After I called the function, the variable NameVar contains absolutelly
> > nothing. What am I doing wrong?
> >
> > Thank you.
>
> "function" is a reserved name. Furthermore it is not a good
> idea to use the same variable name in the main program
> and in the function. Try this:
>
> NameVar = Test(NameVar2)
>
> function Test(MyString)
> If MyString = "some string" Then
> Test = 0
> Else
> Test = 1
> End if
> end function
>
>
>

Re: Function returning a value by Bob

Bob
Tue Jul 08 09:54:11 CDT 2008

Meat wrote:
> Yes, that's what I did, I'm sorry for the error in this post.
>
> I don't know why but the function returns absolutely nothing.
>


It's hard to supply actual help
unless you post actual code.

Typing in something similar
will get you something "like" help.
Often it won't be of any more use
than what you typed in.



Bob
--

Re: Function returning a value by Pegasus

Pegasus
Tue Jul 08 10:08:19 CDT 2008


"Meat" <Meat@discussions.microsoft.com> wrote in message
news:B5DE587E-1B5C-4FFE-967F-EB2BE3C87B2D@microsoft.com...
> Yes, that's what I did, I'm sorry for the error in this post.
>
> I don't know why but the function returns absolutely nothing.
>

Posting your interpretation of what you did won't get you
anywhere. You must post the real thing!



Re: Function returning a value by Richard

Richard
Tue Jul 08 11:25:12 CDT 2008


"Meat" <Meat@discussions.microsoft.com> wrote in message
news:B5DE587E-1B5C-4FFE-967F-EB2BE3C87B2D@microsoft.com...
> Yes, that's what I did, I'm sorry for the error in this post.
>
> I don't know why but the function returns absolutely nothing.
>
> "Pegasus (MVP)" wrote:
>
>>
>> "Meat" <Meat@discussions.microsoft.com> wrote in message
>> news:23F81DFD-D722-4560-986D-620D31EC1046@microsoft.com...
>> > Hello,
>> >
>> > I want to return a value with a function. I call the function like
>> > this :
>> >
>> > NameVar = function(NameVar2)
>> >
>> > The code of the function looks like this :
>> >
>> > function(NameVar2)
>> >
>> > If NameVar2 = statement Then
>> > function = 0
>> > Else
>> > function = 1
>> > End if
>> >
>> > After I called the function, the variable NameVar contains absolutelly
>> > nothing. What am I doing wrong?
>> >
>> > Thank you.
>>
>> "function" is a reserved name. Furthermore it is not a good
>> idea to use the same variable name in the main program
>> and in the function. Try this:
>>
>> NameVar = Test(NameVar2)
>>
>> function Test(MyString)
>> If MyString = "some string" Then
>> Test = 0
>> Else
>> Test = 1
>> End if
>> end function
>>
>>
>>

Just to clarify, you don't need to post your actual code. It may be very
long or have confidential information. But you should be able to post code
that duplicates the problem, so we can run it. If you cannot duplicate the
problem in a short snippet, then most likely there is something else wrong
in your program. For example, you may be using "On Error Resume Next" and an
error earlier in the program is messing things up. If we cannot duplicate
the problem, the only recourse is for you post the actual code.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--



Re: Function returning a value by Al

Al
Tue Jul 08 00:51:10 CDT 2008

what he said, but also...

"Pegasus (MVP)" <I.can@fly.com.oz> wrote in message
news:O8LEM2F4IHA.4488@TK2MSFTNGP03.phx.gbl...
>
> "Meat" <Meat@discussions.microsoft.com> wrote in message
> news:23F81DFD-D722-4560-986D-620D31EC1046@microsoft.com...
>> Hello,
>>
>> I want to return a value with a function. I call the function like this
>> :
>>
>> NameVar = function(NameVar2)
>>
>> The code of the function looks like this :
>>
>> function(NameVar2)
>>
>> If NameVar2 = statement Then

where is the variable whose name is "statement" defined?

>> function = 0
>> Else
>> function = 1
>> End if

missing statement: end function

>>
>> After I called the function, the variable NameVar contains absolutelly
>> nothing. What am I doing wrong?
>>
>> Thank you.
>
> "function" is a reserved name.

... but to return a value to a function you use a variable whose name is not
"function" but the same as the name of the function - as Pegasus illustrates
below.

/Al

> Furthermore it is not a good
> idea to use the same variable name in the main program
> and in the function. Try this:
>
> NameVar = Test(NameVar2)
>
> function Test(MyString)
> If MyString = "some string" Then
> Test = 0
> Else
> Test = 1
> End if
> end function
>
>