Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Include text file data in coding

    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 %>

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #3
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Thanks

    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?

  • #4
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,072
    Thanks
    4
    Thanked 8 Times in 8 Posts
    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
    Code:
    dim txRate
    txRate = .0825
    the next page
    Code:
    <!--#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 (<% %>)

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    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....
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Roy's solution should work...
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •