472,355 Members | 1,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,355 software developers and data experts.

How to get a value calculated in a Function

Hi,

I have a function that looks up various values and then results in a
value to a variable:

Function ShouldItBeReferred

If Claim3Date <"" Then
'Do stuff......

TheAnswer = "Yes"
Else
TheAnswer = "No"
End If

'and various other stuf.........

If TheAnswer = "Yes" Then
TheMessage = "Yes, for now." 'real messageto follow..
Else
TheMessage = "No, for now." 'real messageto follow..
End If

End Function

Elsewhere on the page, a number of times, I need to Call the Function
and find out the value of 'TheMessage' to display.

I've tried:

Call ShouldItBeReferred .......... nothing

DisplayMessage = ShouldItBeReferred ..........nothing

Please can you tell me how to call the function 'run it' and find out
the value of 'TheMessage'

Many thanks

Jon

Sep 4 '06 #1
6 1346
"J-P-W" <jo******@gmail.comwrote in news:1157402638.015931.64040@
74g2000cwt.googlegroups.com:
Please can you tell me how to call the function 'run it' and find out
the value of 'TheMessage'

Function runit()
If condition Then
runit = "Answer 1"
Else
runit = "Answer 2"
End If
End Function

Response.Write runit

=========================================

If you intent to call this function several times with the same data being
calculated each time, why not use a sub instead ?

Sep 4 '06 #2

J-P-W wrote:
Hi,

I have a function that looks up various values and then results in a
value to a variable:

Function ShouldItBeReferred

If Claim3Date <"" Then
'Do stuff......

TheAnswer = "Yes"
Else
TheAnswer = "No"
End If

'and various other stuf.........

If TheAnswer = "Yes" Then
TheMessage = "Yes, for now." 'real messageto follow..
Else
TheMessage = "No, for now." 'real messageto follow..
End If

End Function

Elsewhere on the page, a number of times, I need to Call the Function
and find out the value of 'TheMessage' to display.

I've tried:

Call ShouldItBeReferred .......... nothing

DisplayMessage = ShouldItBeReferred ..........nothing

Please can you tell me how to call the function 'run it' and find out
the value of 'TheMessage'

Many thanks

Jon

for the function to return a string value it should be defined as

function ShouldItBeReferred( paraneters-here) as string
............do something
end function

and in this function the function name is treated as a string variable
which is to be returned, so u need to assign the string values to this
ShouldItBeReferred, and it should be called as DisplayMessage =
ShouldItBeReferred(parameters-here), the DisplayMessage variable will
get the returned string value.

Sep 5 '06 #3

"ravichoudhari" <ra***********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>
J-P-W wrote:
Hi,

I have a function that looks up various values and then results in a
value to a variable:

Function ShouldItBeReferred

If Claim3Date <"" Then
'Do stuff......

TheAnswer = "Yes"
Else
TheAnswer = "No"
End If

'and various other stuf.........

If TheAnswer = "Yes" Then
TheMessage = "Yes, for now." 'real messageto follow..
Else
TheMessage = "No, for now." 'real messageto follow..
End If

End Function

Elsewhere on the page, a number of times, I need to Call the Function
and find out the value of 'TheMessage' to display.

I've tried:

Call ShouldItBeReferred .......... nothing

DisplayMessage = ShouldItBeReferred ..........nothing

Please can you tell me how to call the function 'run it' and find out
the value of 'TheMessage'

Many thanks

Jon


for the function to return a string value it should be defined as

function ShouldItBeReferred( paraneters-here) as string
...........do something
end function
As String cannot be used in VBScript it applies to VB6 and VB.NET. All
values in VBScript are of a variant data type which can store various
different types as is needed.
and in this function the function name is treated as a string variable
which is to be returned, so u need to assign the string values to this
ShouldItBeReferred, and it should be called as DisplayMessage =
ShouldItBeReferred(parameters-here), the DisplayMessage variable will
get the returned string value.

Sep 5 '06 #4

Peter wrote:
"J-P-W" <jo******@gmail.comwrote in news:1157402638.015931.64040@
74g2000cwt.googlegroups.com:
Please can you tell me how to call the function 'run it' and find out
the value of 'TheMessage'


Function runit()
If condition Then
runit = "Answer 1"
Else
runit = "Answer 2"
End If
End Function

Response.Write runit

=========================================

If you intent to call this function several times with the same data being
calculated each time, why not use a sub instead ?
Thanks for the reply, I still couldn't get it to work!!! (I'd tried
this also)

I've just repeated the code within the function 4 times on the page -
sloppy I know, I'll come to it later!

Thanks

Jon

Sep 5 '06 #5
J-P-W wrote:
Peter wrote:
>"J-P-W" <jo******@gmail.comwrote in news:1157402638.015931.64040@
74g2000cwt.googlegroups.com:
>>Please can you tell me how to call the function 'run it' and find
out the value of 'TheMessage'


Function runit()
If condition Then
runit = "Answer 1"
Else
runit = "Answer 2"
End If
End Function

Response.Write runit

=========================================

If you intent to call this function several times with the same data
being calculated each time, why not use a sub instead ?

Thanks for the reply, I still couldn't get it to work!!! (I'd tried
this also)
Please describe symptoms rather than the meaningless "doesn't work".
Verify that you have followed the above example exactly. I.E., verify
that you have assigned the value you wish the function to return to the
name of the function.
If you still can't get it to work, strip out everything that is not
needed to demonstrate the problem and show us the exact code that
"doesn't work". We need to be able to run the code ourselves, so "air"
code that somewhat resembles your code will not do it. For example, the
above example code cannot be run as-is. Here is a better example that
will work if you place it in a blank asp page:

<%
response.write runit("A")
function runit(parm)
runit = "Answer " & parm
end function
%>

This code works. I've just finished testing it. Try it out yourself and
verify that it works. If it does not work, let us know and describe the
symptoms. If it does work, check to see where the difference is in your
code. If you can't figure out the difference, post the code.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Sep 5 '06 #6

Bob Barrows [MVP] wrote:
J-P-W wrote:
Peter wrote:
"J-P-W" <jo******@gmail.comwrote in news:1157402638.015931.64040@
74g2000cwt.googlegroups.com:

Please can you tell me how to call the function 'run it' and find
out the value of 'TheMessage'
Function runit()
If condition Then
runit = "Answer 1"
Else
runit = "Answer 2"
End If
End Function

Response.Write runit

=========================================

If you intent to call this function several times with the same data
being calculated each time, why not use a sub instead ?
Thanks for the reply, I still couldn't get it to work!!! (I'd tried
this also)

Please describe symptoms rather than the meaningless "doesn't work".
Verify that you have followed the above example exactly. I.E., verify
that you have assigned the value you wish the function to return to the
name of the function.
If you still can't get it to work, strip out everything that is not
needed to demonstrate the problem and show us the exact code that
"doesn't work". We need to be able to run the code ourselves, so "air"
code that somewhat resembles your code will not do it. For example, the
above example code cannot be run as-is. Here is a better example that
will work if you place it in a blank asp page:

<%
response.write runit("A")
function runit(parm)
runit = "Answer " & parm
end function
%>

This code works. I've just finished testing it. Try it out yourself and
verify that it works. If it does not work, let us know and describe the
symptoms. If it does work, check to see where the difference is in your
code. If you can't figure out the difference, post the code.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Hi Bob,

Sorry that I didn't give a full run down, I was running late on
deploying the web page that needed this function, I really appreciate
the help I get from time to time on this group, from you and others,
this time I decided that I needed to quit learning and deploy!!! I've
acutally overwritten the failing function with the repetative code that
works fine!!!

I know I should know better.....

And yes your code worked fine, thanks, it must have been the way I
transposed my data into Peters example

Jon

Sep 7 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jack | last post by:
Hi, I have a checkbox the value which goes to a database via a asp page that builds the sql string. In the front end asp page, the checkbox code is written as follows: <i><input...
0
by: Henry | last post by:
Hi Is there any good ideas how to update form vb code always after some values are changed / added by vb (not user). I have some code behind subforms vb and there are calculations behind...
3
by: Bill Clark | last post by:
I have about 20,000 records pulled from Excel that I need to update. What I need to do is run an update query that bascially says: If a field is null, update it with the previous record value of...
5
by: Richard Holliingsworth | last post by:
Hello: Thanks for reading this post. I need to create a metrics (form or report - I don't care which) to display calculated fields about the database (A2002 front end to SQL Server 2K) 1) I...
13
by: Sara | last post by:
I have a query that pulls data for the month, using the Month End Date from a form (user enters) as criteria. It works. I want to use the same query to pull "month to date" data, on a weekly...
1
by: Marek | last post by:
Hi I need to call a native function in a C++ dll from my C#. The C++ function declaration is shown below. The C# code that I have been trying to perform the call is also shown below. All it is...
3
by: kelley.l.turner | last post by:
Hi all, I am very new to MS Access so please bear with me! I have created a simple calculated field in my data entry form, yet when I view my data table or try to generate a report based on...
2
by: PowerLifter1450 | last post by:
Hi all, I have fields in my tables which get updated to the UserName when someone inserts/updates records through a form. However, I have created append queries that are importing records to the...
9
by: JCCDEVEL | last post by:
Hi All, I'm trying to do the following: 1) ON a php page, calculate fees based upon user entires. I'm calculating it in a javascript function and that is working well. However, I need to take...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.