473,503 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1395
"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
4610
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
2065
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
7012
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
2916
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
2136
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
2318
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
4733
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
5336
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
2566
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
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5572
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4667
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.