Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.


Go Back   Vista Forums > Misc Newsgroups > VB Script

RB

Vista - Function returning a value

Reply
 
07-07-2008   #1
Meat


 
 

Function returning a value

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.

My System SpecsSystem Spec
07-07-2008   #2
Pegasus \(MVP\)


 
 

Re: Function returning a value


"Meat" <Meat@xxxxxx> wrote in message
news:23F81DFD-D722-4560-986D-620D31EC1046@xxxxxx
Quote:

> 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


My System SpecsSystem Spec
07-08-2008   #3
Al Dunbar


 
 

Re: Function returning a value

what he said, but also...

"Pegasus (MVP)" <I.can@xxxxxx> wrote in message
news:O8LEM2F4IHA.4488@xxxxxx
Quote:

>
> "Meat" <Meat@xxxxxx> wrote in message
> news:23F81DFD-D722-4560-986D-620D31EC1046@xxxxxx
Quote:

>> 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?
Quote:
Quote:

>> function = 0
>> Else
>> function = 1
>> End if
missing statement: end function
Quote:
Quote:

>>
>> 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
Quote:

> 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
>
>

My System SpecsSystem Spec
07-08-2008   #4
Meat


 
 

Re: Function returning a value

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:
Quote:

>
> "Meat" <Meat@xxxxxx> wrote in message
> news:23F81DFD-D722-4560-986D-620D31EC1046@xxxxxx
Quote:

> > 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
>
>
>
My System SpecsSystem Spec
07-08-2008   #5
Bob O`Bob


 
 

Re: Function returning a value

Meat wrote:
Quote:

> 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
--
My System SpecsSystem Spec
07-08-2008   #6
Pegasus \(MVP\)


 
 

Re: Function returning a value


"Meat" <Meat@xxxxxx> wrote in message
news:B5DE587E-1B5C-4FFE-967F-EB2BE3C87B2D@xxxxxx
Quote:

> 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!


My System SpecsSystem Spec
07-08-2008   #7
Richard Mueller [MVP]


 
 

Re: Function returning a value


"Meat" <Meat@xxxxxx> wrote in message
news:B5DE587E-1B5C-4FFE-967F-EB2BE3C87B2D@xxxxxx
Quote:

> 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:
>
Quote:

>>
>> "Meat" <Meat@xxxxxx> wrote in message
>> news:23F81DFD-D722-4560-986D-620D31EC1046@xxxxxx
Quote:

>> > 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
--


My System SpecsSystem Spec
Reply

RB


Thread Tools


Similar Threads for: Function returning a value
Thread Forum
Problem in returning an object from a function VB Script
function not returning anything PowerShell
Returning Variables from a Function... PowerShell
Returning from RC2 to RC1 Vista General
BUG: Redirecting function contents to a file truncates function lines at the width of the console PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd