![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| | |||||||
| | Vista - Function returning a value |
| |
| 07-07-2008 | #1 |
| | 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 Specs |
| 07-07-2008 | #2 |
| | 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. 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 Specs |
| 07-08-2008 | #3 |
| | 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 Quote: Quote: >> function = 0 >> Else >> function = 1 >> End if 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. "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 Specs |
| 07-08-2008 | #4 |
| | 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 Specs |
| 07-08-2008 | #5 |
| | 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 Specs |
| 07-08-2008 | #6 |
| | 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. > anywhere. You must post the real thing! |
| My System Specs |
| 07-08-2008 | #7 |
| | 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 >> >> >> 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 Specs |
![]() |
| 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 | |||