Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
converting split result to integer
Old 04-21-2007, 07:10 AM converting split result to integer
aeuden's Avatar
Novice Talker

Posts: 14
Trades: 0
Hi

I am using the following code to try and convert the result of a split to an integer in order to add the values together to give a running balance.

The split code

details=Request.Cookies("cart_contents")
Response.Write("details:<br>"&details&"<p>")
detail_split=Split(details,"<br>")

detail_count=Ubound(detail_split)
Response.Write("detail_count="&detail_count&"<br>" )
detail_lbound=Lbound(detail_split)
Response.Write("detail_lbound="&detail_lbound&"<br >")

FOR count=1 TO detail_count-1
product_name=Split(detail_split(count),"£")
product_tmp=product_name(1)
product_pricetmp=Split(product_tmp,"Q")
product_price=product_pricetmp(0)
product_qty=product_pricetmp(1)

Response.Write("<p>count="&count&"<br>")
Response.Write("product_name="&product_name(0)&"<b r>")
Response.Write("product_tmp="&product_tmp&"<br>")
Response.Write("product_pricetmp="&product_pricetm p(0)&"<br>")
Response.Write("product_price="&product_price&"<br >")
Response.Write("product_qty=QTY&nbsp;"&product_qty &"<p>")

The for the display

Response.Write(product_price&"<br>")
price=product_price
IF IsNumeric(price) THEN
price_temp=CInt(price)
Response.Write("price_temp"&price_temp&"<br>")
ELSE
Response.Write("xnumeric<br>")
END IF
IF IsNumeric(product_qty) THEN
price_qty=CInt(product_qty)
Response.Write("price_qty"&price_qty&"<br>")
ELSE
Response.Write("xnumeric")
END IF
price=price_tmp*price_qty
Response.Write("£"&price&"<br>")

The output shown that price is a non numeric value and as a result will not convert it to an integer but there is no problem with price_qty.

The values returned are

count=1
product_name=(L200-030 HFEF) 3.00 kW 7.80 AMP 3ph
product_tmp=484 Q1
product_pricetmp=484
product_price=484
product_qty=QTY 1



This has been driving me nuts.

Thanks in advance

Alun
aeuden is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-21-2007, 08:10 AM Re: converting split result to integer
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
cint(string_value)
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-21-2007, 08:17 AM Re: converting split result to integer
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
and of course there is;

Clng() for Long Integer type
CDbl() for Double type
cCur() for Currency type


http://www.w3schools.com/vbscript/vb...asp#conversion
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-21-2007, 08:26 AM Re: converting split result to integer
aeuden's Avatar
Novice Talker

Posts: 14
Trades: 0
IF IsNumeric(price) THEN
I've tried that here

price=product_price
price_temp=CInt(price)
Response.Write("price_temp"&price_temp&"<br>")
ELSE
Response.Write("xnumeric<br>")
END IF

but it tells me that price_temp isn't a numeric value the value is derived from tis line further up the code

product_pricetmp=Split(product_tmp,"Q")
product_price=product_pricetmp(0)


Cheers Al
aeuden is offline
Reply With Quote
View Public Profile
 
Old 04-21-2007, 10:22 AM Re: converting split result to integer
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
I'd guess you have some spaces in the array value. use trim() to remove them.

What I don't see the reason for is having "<br>"s in the cookie.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-21-2007, 12:02 PM Re: converting split result to integer
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
I've precompiled functions for this specific purpose:

http://www.walkonmypath.com/integer-...version-in-asp

If you don't have a numeric value, either function will output 0. If you do, it will be converted to a number.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 04-21-2007, 01:15 PM Re: converting split result to integer
aeuden's Avatar
Novice Talker

Posts: 14
Trades: 0
I have placed the function at the start of the file.

And then called it in the following

Response.Write("p_p="&product_price&"<br>")
price=IntConverter(product_price)
response.Write("p="&price&"<br>")


The results are

p_p=115
p=0

So it still doesn't appear to be picking up the price variable as a numerical field.

Alun

aeuden is offline
Reply With Quote
View Public Profile
 
Old 04-21-2007, 06:39 PM Re: converting split result to integer
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
115 & 0 look like numerics to me

what exactly are you trying to do???

because I suspect the answer will be

response.write FormatCurrency(price)
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-23-2007, 07:57 AM Re: converting split result to integer
aeuden's Avatar
Novice Talker

Posts: 14
Trades: 0
Iam in the process of building a shopping cart using a flat file database - hence the reason for the <br> in the cookie - on the request of a customer.

The integration of the database into the pages for product selection has worked OK as has adding the item to the cart with the exception of the product_price has decided it is not going to be a numeric.

I want to split the string into product_code product_price and product_qty

I then wan't to multiply product_price by product_qty and display the result in the price column on the output.

I also want to have a running balance column next to this that will take the price of the second item in the list and add it it to the first and so on add the user adds items.

Al
aeuden is offline
Reply With Quote
View Public Profile
 
Old 04-23-2007, 07:59 AM Re: converting split result to integer
aeuden's Avatar
Novice Talker

Posts: 14
Trades: 0
take a look at http://www.lowestoft-business.co.uk/projects/scs
aeuden is offline
Reply With Quote
View Public Profile
 
Old 04-23-2007, 08:02 AM Re: converting split result to integer
aeuden's Avatar
Novice Talker

Posts: 14
Trades: 0
(and before you ask i'm re-writing someone elses Frontpage code!!)
aeuden is offline
Reply With Quote
View Public Profile
 
Old 04-23-2007, 12:24 PM Re: converting split result to integer
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
No, it's definitely not picking up the price variable as a numeric field.

The question I have is twofold: 1) why a flat-file database and 2) why not an Access database? The server supports ASP, so it should support Access; the only reason it wouldn't is if it's an NT server.

Also, if that function returns a 0 when a non-0 numeric value is passed to it, it's usually a sign that your server needs to be restarted since it can't pick up numeric values.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 04-23-2007, 01:19 PM Re: converting split result to integer
aeuden's Avatar
Novice Talker

Posts: 14
Trades: 0
Personally I would use an access database - but the customer would not know where to start when editing etc - the general idea is I set it up and they maintain - and also don't want the expenditure af me writing a backend for them.

And seeing as they are paying the bill......
aeuden is offline
Reply With Quote
View Public Profile
 
Old 04-23-2007, 03:21 PM Re: converting split result to integer
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
I guess that means you can't build forms for them, eh? Ah well. Such is life.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Reply     « Reply to converting split result to integer
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.38152 seconds with 12 queries