Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 132,226 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,038 people online right now. Registration is fast and FREE... Join Now!




HELP WITH SERVER SIDE SCRIPT

 
Reply to this topicStart new topic

HELP WITH SERVER SIDE SCRIPT

MarineDrillInstructor29
post 22 Feb, 2008 - 03:07 PM
Post #1


New D.I.C Head

*
Joined: 7 Dec, 2007
Posts: 17


My Contributions


Good Morning,
I'm having a small problem. I'm supposed to create a web page that calculates an arithmetic expression using server-side script. When I run the script I get an error. I'm using IIS to run this script and the error I get is a mismatch error. Here is the code. Thanks.
CODE

<% @language="vbscript" %>
<%
const bkName="Chancy's Bookstore"
const bkEmail="info@chancybooks.com"
dim bk1, bk2, bk3, total, today
bk1="$1.99"
bk2="$2.99"
bk3="$3.99"
total= bk1 + bk2 + bk3
today=WeekdayName(Weekday(Date)) & "," & _
MonthName(Month(Date)) & " " & _
Day(Date) & ", " & Year(Now()) %>
<html><head><title>Shopping Cart</title></head>
<body bgColor="#CCCCFF">
<font color="#000080"</font>
<div align="center">
<h2><% = bkName %></h2>
<h3><% = bkEmail %></h3>
<h3>Your Shopping Cart</h3>
You purchased your products on <br><br>
<% response.write WeekdayName(Weekday(Date)) & ", " & _
    MonthName(Month(Date)) & " " & _
    Day(Date) & ", " & Year(Now()) %><br><br>
<% if Total <> 0 then %>
   <table align ="center" width="150">
   <tr><td>Book 1 </td><td align="right">
   <% = formatCurrency(bk1) %>
   </td></tr>
   <tr><td>Book 2</td><td align="right">
   <% = formatCurrency(bk2) %>
   </td></tr>
   <tr><td>Book 3</td><td align="right">
   <% = formatCurrency(bk3) %>
   </td></tr>
   <tr><td> Total </td><td align="right">
   <% = formatCurrency(total) %>
   </td></tr>
<% else %>
    You have nothing in your shopping cart!
<% end if %>
</body></html>

User is offlineProfile CardPM

Go to the top of the page

Martyr2
post 22 Feb, 2008 - 03:17 PM
Post #2


Programming Theoretician

Group Icon
Joined: 18 Apr, 2007
Posts: 5,012



Thanked 171 times

Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions


Where you define your three variables, you have to define them to be decimal numbers and not strings.

Instead of using...

CODE

bk1="$1.99"
bk2="$2.99"
bk3="$3.99"


You should use....

CODE

bk1=1.99
bk2=2.99
bk3=3.99


Then your script will work fine. It is just that you can't add strings together and later compare it to a number (like you do when you use if total <> 0) because strings and numbers are two different types of data. Hence the mismatch.

But by changing the variables to numbers, you can add them and compare the result to a number just fine. Then you formatted it and the page will work as intended.

Enjoy!

"At DIC we be data type mismatching eliminating code ninjas!" decap.gif
User is online!Profile CardPM

Go to the top of the page

PsychoCoder
post 22 Feb, 2008 - 04:22 PM
Post #3


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,923



Thanked 117 times

Dream Kudos: 8475

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


The following code is going to give a type mismatch error because you're trying to add strings, which cannot be done


vb

dim bk1, bk2, bk3, total, today
bk1="$1.99"
bk2="$2.99"
bk3="$3.99"
total= bk1 + bk2 + bk3



You're going to need Double or Decimal data types for this, not string


vb

dim bk1, bk2, bk3 As Double
Dim total, today
bk1= 1.99
bk2= 2.99
bk3= 3.99
total= bk1 + bk2 + bk3


Thats the path you're going to have to take, you cant perform mathematical operations on strings. Hope that helps a little smile.gif

EDIT: Whoops, guess I should refresh before posting, sorry Marty didnt even see your post blush.gif

This post has been edited by PsychoCoder: 22 Feb, 2008 - 04:23 PM
User is online!Profile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/21/08 09:03PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month