Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 9th, 2008, 11:32 AM
Registered User
 
Join Date: Oct 2008
Location: Glasgow, Scotland, United Kingdom.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?

  #2 (permalink)  
Old October 9th, 2008, 02:15 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

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)%>
  #3 (permalink)  
Old October 10th, 2008, 03:29 AM
Registered User
 
Join Date: Oct 2008
Location: Glasgow, Scotland, United Kingdom.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

  #4 (permalink)  
Old October 10th, 2008, 06:47 AM
Registered User
 
Join Date: Oct 2008
Location: Glasgow, Scotland, United Kingdom.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
        Session("LifeCover") = curPremium
        Session("MonthlyPremium") = lifeAss
        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.

  #5 (permalink)  
Old October 10th, 2008, 01:45 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:23 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.