...

View Full Version : Include text file data in coding



werosen
08-31-2004, 07:17 PM
Hi:

I'm trying to include a value from a text file for the txRate variable in the code below. I tried using the include function as shown, but the double quotes are of course killing it. I don't want to use a data base to get this value, I just want the info from a text file. Can anyone suggest a solution?

Thanks for your help.

<%
Dim sales, salesnoship, txRate, notaxrate, salesplustax, justtax, grandtotal, grandnotax, statename, statecode
sales = FormatNumber(sTotal,2) ' All items plus shipping and no tax
salesnoship = ((sTotal) - sShipping) ' All items without shipping nor tax
txRate = <!--#include file="salestaxrate.asp"--> ' ****tax
notaxrate = 0.00 ' No tax
salesplustax = (((salesnoship/100) * txRate) + salesnoship) ' This is sales plus tax
justtax = ((salesnoship/100) * txRate) ' This is the tax on all items in cart
grandtotal = ((salesplustax) + sShipping) ' This is sales plus tax plus shipping
grandnotax = ((salesnoship) + sShipping) ' This is sales plus shipping
statename = "cStateFullName" ' ****state1
statecode = "cStateAbbreviation"' ' ****state2 %>

Roy Sinclair
08-31-2004, 07:46 PM
Use the FileSystemObject to open the file with the tax rate and then read the date into the variable. Include files don't work the way you're trying to use them.

werosen
08-31-2004, 08:18 PM
Thank you Roy. This makes sense, but I'm having a little trouble getting it to work, as I'm a bit new at this language.

Could you send me a code example to plug into the script? :D

miranda
08-31-2004, 08:57 PM
You don't even need to use the file system object. If you have the include file saved as .asp or .inc you can name the variable on that page and then reference it anywhere on another page

salestaxrate.asp


dim txRate
txRate = .0825

the next page


<!--#include file="salestaxrate.asp"-->
<%
Dim sales, salesnoship, notaxrate, salesplustax, justtax, grandtotal, grandnotax, statename, statecode
sales = FormatNumber(sTotal,2) ' All items plus shipping and no tax
salesnoship = ((sTotal) - sShipping) ' All items without shipping nor tax
notaxrate = 0.00 ' No tax
salesplustax = (((salesnoship/100) * txRate) + salesnoship) ' This is sales plus tax
justtax = ((salesnoship/100) * txRate) ' This is the tax on all items in cart
grandtotal = ((salesplustax) + sShipping) ' This is sales plus tax plus shipping
grandnotax = ((salesnoship) + sShipping) ' This is sales plus shipping
statename = "cStateFullName" ' ****state1
statecode = "cStateAbbreviation"' ' ****state2 %>


note that the include file DOES NOT go within the asp delimiters (<% %>)

Roy Sinclair
08-31-2004, 09:25 PM
That will work as long as the file can be made to contain the appropriate VBscript but not if all the file contains is just the value. Assuming there's no easy way to change that file to be VB code the following code should do the trick:



Dim fso ' File System Object
Dim ts ' TextStream object

Set fso = System.CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(Server.MapPath("salestaxrate.asp"),1)
txRate = CDbl(ts.ReadLine) ' Make sure it's put into a "Double" numeric field
Set ts = nothing ' Release the Textstream object
Set fso = nothing ' Release the FileSystem object


I haven't tested this code so....

whammy
09-01-2004, 03:11 AM
Roy's solution should work...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum