Wrox Programmer Forums Calculations with a string
 |
 Welcome to the p2p.wrox.com Forums. You are currently viewing the BOOK: Beginning ASP 3.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com

October 9th, 2008, 11:32 AM
 mgeorge Registered User Join Date: Oct 2008 Posts: 3 Thanks: 0 Thanked 0 Times in 0 Posts
Calculations with a string

I've been using Classic ASP for some time, and up to now I've been fairly good, but I've hit a problem.

In chapter 4, Arithmetic Calculations, the figures are based on an integer, but how to convert this to use with a string.

In need to multiply <%=MonthlyCost%> by 2 as the client pays 2 months in advance.

Could the example in the book for a tax calculation be used?

October 9th, 2008, 02:15 PM
 Old Pedant Friend of Wrox Join Date: Jun 2008 Posts: 1,649 Thanks: 3 Thanked 141 Times in 140 Posts

There are various ways to convert data types in the .NET framework, but if you are coding with VB.NET (not C#) then you can use the same functions you have used all along with VBScript:
CINT( )
CDBL( )
CCURR( )
CSTR( )
and so on.

The only difference is that whereas CINT() in VBScript only handled 16 bit numbers (and so was limited to the range -32768 to 32767), CINT() in VB.NET handles full 32 bit number (+/- 2 billion). And CLNG() in VB.NET handles 64 bit numbers. All the other Cxxxx functions remain the same.

So, if MonthlyCost is a string, you should be able to do
<%=2 * CCurr(MonthlyCost)%>
or
<%=2 * CDbl(MonthlyCost)%>

October 10th, 2008, 03:29 AM
 mgeorge Registered User Join Date: Oct 2008 Posts: 3 Thanks: 0 Thanked 0 Times in 0 Posts

The whole site has been done using ASP, so to switch to VBScript will cause the missmatch error to come up.

October 10th, 2008, 06:47 AM
 mgeorge Registered User Join Date: Oct 2008 Posts: 3 Thanks: 0 Thanked 0 Times in 0 Posts

Hi Guys

Managed to solve this little problem, and leave some hair in place.

The systems starts with

<% if Request.Form("submit1") = "GET QUOTE NOW" then
Session("Age") = intAge
Session("Gender") = txtGender
Session("NonSmoker") = bNonSmoker
Response.Redirect "quotes201.asp"
end if
%>

All I had to do was add a futher line "Session("SinglePremium") = lifeAss*2. The new session object is carried through the system.

October 10th, 2008, 01:45 PM
 Old Pedant Friend of Wrox Join Date: Jun 2008 Posts: 1,649 Thanks: 3 Thanked 141 Times in 140 Posts

> The whole site has been done using ASP, so to switch to VBScript will cause the missmatch error to come up.

Ummm...I hate to tell you this, but you *ARE* coding in VBScript. ASP is *NOT* a language; it's a framework. And you can code in ASP in VBScript or JScript or (if you can still find it) PerlScript. 96% or more of ASP is indeed done in VBScript.

And my answer was correct for VBScript. I misread the forum you posted in as being ASP.NET 3.0, but the answer I gave you works equally well in VBScript, honest.

Yes, you can simply multiply in VBS to force the conversion (to DOUBLE, by the way, if you care...same as using CDBL( ) that is).

 Similar Threads Thread Thread Starter Forum Replies Last Post Chapter 4 calculations zenixcomp BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 November 3rd, 2008 05:18 PM Date Calculations edove ASP.NET 2.0 Basics 0 March 30th, 2007 07:05 AM Positioning Calculations rit01 ASP.NET 1.x and 2.0 Application Design 3 February 22nd, 2006 03:10 PM Query Calculations Kaladar Access 3 August 17th, 2005 11:59 AM Access Calculations bjackman Access 3 December 15th, 2003 09:44 PM