SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    conversion rates and vat

    I want my site to show prices including VAT. How do I calculate this with vbscript.

    I also want users to be able to click on a button to convert the price to Euro/dollar/yen - how do I do this and can I use a live conversion rate without having to change it myself (eg get the current rate from a site to use tin the equations)?

    monkey
    monkey - the rest is history

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation

    Well VAT, you can use this script i've just wrote:

    <%

    Dim Total
    Total = 15.99

    Dim Vat_Perc
    Vat_Perc = 17.5

    sub calculate_Vat(sum)

    vat = (Total * Vat_Perc) / 100
    response.write(replace(FormatCurrency(Total + vat,2),"$","") & "<BR>")

    end sub

    call calculate_Vat(Total)

    %>
    as you can see, all you need to do is call <% call calculate_Vat(session("total")) %> or <% call calulate_Vat("15.99") %> and it will calculate the vat to the nearest penny.

    As for the currency conversion, I will work on that now.

    Gav

  3. #3
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well i've kinda got somewhere.

    What you need to do now is find some way of getting the value from the page,

    Code:
    <%
    
    	Dim Total
    		Total = 15.99
    		
    	Dim Vat_Perc
    		Vat_Perc = 17.5
    		
    	sub calculate_Vat(sum)
    	
    		vat = (Total * Vat_Perc) / 100
    		response.write(replace(FormatCurrency(Total + vat,2),"$","") & "<BR>")
    		
    	end sub
    	
    	function calc_vat(sum)
    		
    		vat = (Total * Vat_Perc) / 100
    		calc_vat = replace(replace(FormatCurrency(Total + vat,2),"$",""),"?","")
    		
    	end function
    		
    	Function ConvertBold(strBOLD)
    	
    		Set oRE = New RegExp
    		oRE.IgnoreCase = True
    		oRE.Global = True
    		oRE.Pattern = "<B>[0-9./]+\</B>"
    		
    		ConvertBold = "$1"
    
    		set ORE = nothing
    
    	End Function
    	
    	sub convert_currency(howmuch, vat)
    	
    		if vat = 1 then
    		
    			howmuch = replace(calc_vat(howmuch),"","")
    			
    		end if
    	
    		dim pull_results
    		set pull_results = server.createobject("Microsoft.XMLHTTP")
    			pull_results.Open "GET", "http://money.cnn.com/markets/currencies/index.html?howmany=" & howmuch & "&currfrom=" & Request.Form("select") & "&currto=" & Request.Form("select2") & "&calculate=true&btn_calculate.x=45&btn_calculate.y=12", false
    			pull_results.send
    	
    			results = pull_results.responseText
    			results = ConvertBold(results)
    				
    			
    			response.write results & "<BR>" & howmuch
    			
    	end sub
    	
    	if request.querystring("convert") = "yes" then
    	
    		call convert_currency("15.99",1)
    		
    	end if
    	
    %>
    <form name="form1" method="post" action="?convert=yes">
      <select style="font-family:verdana;font-size:11px;width:157px;" name="select">
        <option value="126274" SELECTED>US Dollar</option>
        <option value="127354" >Euro</option>
        <option value="126279" >Australian Dollar</option>
        <option value="126323" >Brazilian Real</option>
        <option value="126268" >British Pound</option>
        <option value="126275" >Canadian Dollar</option>
        <option value="126349" >Czech Koruna</option>
        <option value="126308" >Danish Krone</option>
        <option value="126287" >Hong Kong Dollar</option>
        <option value="126341" >Hungarian Forint</option>
        <option value="126327" >Japanese Yen</option>
        <option value="126300" >Mexican Peso</option>
        <option value="126282" >New Zealand Dollar</option>
        <option value="126312" >Norwegian Kroner</option>
        <option value="126268" >UK Pound Sterling</option>
        <option value="126289" >Singapore Dollar</option>
        <option value="126296" >South African Rand</option>
        <option value="126315" >Swedish Krona</option>
        <option value="126328" >Swiss Franc</option>
      </select>
      <select style="font-family:verdana;font-size:11px;width:157px;" name="select2">
        <option value="126274" >US Dollar</option>
        <option value="127354" selected>Euro</option>
        <option value="126279" >Australian Dollar</option>
        <option value="126323" >Brazilian Real</option>
        <option value="126268" >British Pound</option>
        <option value="126275" >Canadian Dollar</option>
        <option value="126349" >Czech Koruna</option>
        <option value="126308" >Danish Krone</option>
        <option value="126287" >Hong Kong Dollar</option>
        <option value="126341" >Hungarian Forint</option>
        <option value="126327" >Japanese Yen</option>
        <option value="126300" >Mexican Peso</option>
        <option value="126282" >New Zealand Dollar</option>
        <option value="126312" >Norwegian Kroner</option>
        <option value="126268" >UK Pound Sterling</option>
        <option value="126289" >Singapore Dollar</option>
        <option value="126296" >South African Rand</option>
        <option value="126315" >Swedish Krona</option>
        <option value="126328" >Swiss Franc</option>
      </select>
      <input type="submit" name="Submit" value="Submit">
    </form>
    When trying this, it will only get the first number, instead of the whole exchange rate, obviously, once you have the rate, you will need to then times the price by the exchange rate to get the price.

    Hope this helps...

    Gav

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    infact, sorry what this script does it takes the whole price before or after vat, then converts it into the currency chosen, then should ouput the different price. trying to get that price is the issue.

    Gav

  5. #5
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gRoberts
    infact, sorry what this script does it takes the whole price before or after vat, then converts it into the currency chosen, then should ouput the different price. trying to get that price is the issue.

    Gav
    thanks for your help.

    I have found a script which can grab the html for a whole page - hopefully I would be able to isolate the conversion rates - does that sound feasable.

    monkey
    monkey - the rest is history

  6. #6
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation

    The script above does actually pull the whole page back,

    although I added something that would only pull back the numbers that were in bold. which on that page, only the converted numbers were in bold.

    If you remove the function convertbold and remove the link it will show the whole page.

    Code:
    <%
    
    	Dim Total
    		Total = 15.99
    		
    	Dim Vat_Perc
    		Vat_Perc = 17.5
    		
    	sub calculate_Vat(sum)
    	
    		vat = (Total * Vat_Perc) / 100
    		response.write(replace(FormatCurrency(Total + vat,2),"$","") & "<BR>")
    		
    	end sub
    	
    	function calc_vat(sum)
    		
    		vat = (Total * Vat_Perc) / 100
    		calc_vat = replace(replace(FormatCurrency(Total + vat,2),"$",""),"?","")
    		
    	end function
    		
    	Function ConvertBold(strBOLD)
    	
    		Set oRE = New RegExp
    		oRE.IgnoreCase = True
    		oRE.Global = True
    		oRE.Pattern = "<B>[0-9./]+\</B>"
    		
    		ConvertBold = "$1"
    
    		set ORE = nothing
    
    	End Function
    	
    	sub convert_currency(howmuch, vat)
    	
    		if vat = 1 then
    		
    			howmuch = replace(calc_vat(howmuch),"","")
    			
    		end if
    	
    		dim pull_results
    		set pull_results = server.createobject("Microsoft.XMLHTTP")
    			pull_results.Open "GET", "http://money.cnn.com/markets/currencies/index.html?howmany=" & howmuch & "&currfrom=" & Request.Form("select") & "&currto=" & Request.Form("select2") & "&calculate=true&btn_calculate.x=45&btn_calculate.y=12", false
    			pull_results.send
    	
    			results = pull_results.responseText
    			' This is the removed coding!
    'results = ConvertBold(results)
    				
    			
    			response.write results & "<BR>" & howmuch
    			
    	end sub
    	
    	if request.querystring("convert") = "yes" then
    	
    		call convert_currency("15.99",1)
    		
    	end if
    	
    %>
    <form name="form1" method="post" action="?convert=yes">
      <select style="font-family:verdana;font-size:11px;width:157px;" name="select">
        <option value="126274" SELECTED>US Dollar</option>
        <option value="127354" >Euro</option>
        <option value="126279" >Australian Dollar</option>
        <option value="126323" >Brazilian Real</option>
        <option value="126268" >British Pound</option>
        <option value="126275" >Canadian Dollar</option>
        <option value="126349" >Czech Koruna</option>
        <option value="126308" >Danish Krone</option>
        <option value="126287" >Hong Kong Dollar</option>
        <option value="126341" >Hungarian Forint</option>
        <option value="126327" >Japanese Yen</option>
        <option value="126300" >Mexican Peso</option>
        <option value="126282" >New Zealand Dollar</option>
        <option value="126312" >Norwegian Kroner</option>
        <option value="126268" >UK Pound Sterling</option>
        <option value="126289" >Singapore Dollar</option>
        <option value="126296" >South African Rand</option>
        <option value="126315" >Swedish Krona</option>
        <option value="126328" >Swiss Franc</option>
      </select>
      <select style="font-family:verdana;font-size:11px;width:157px;" name="select2">
        <option value="126274" >US Dollar</option>
        <option value="127354" selected>Euro</option>
        <option value="126279" >Australian Dollar</option>
        <option value="126323" >Brazilian Real</option>
        <option value="126268" >British Pound</option>
        <option value="126275" >Canadian Dollar</option>
        <option value="126349" >Czech Koruna</option>
        <option value="126308" >Danish Krone</option>
        <option value="126287" >Hong Kong Dollar</option>
        <option value="126341" >Hungarian Forint</option>
        <option value="126327" >Japanese Yen</option>
        <option value="126300" >Mexican Peso</option>
        <option value="126282" >New Zealand Dollar</option>
        <option value="126312" >Norwegian Kroner</option>
        <option value="126268" >UK Pound Sterling</option>
        <option value="126289" >Singapore Dollar</option>
        <option value="126296" >South African Rand</option>
        <option value="126315" >Swedish Krona</option>
        <option value="126328" >Swiss Franc</option>
      </select>
      <input type="submit" name="Submit" value="Submit">
    </form>
    Now it will show the whole page including the convertion, the only issue is trying to get the price conversion after the page has created it, Usually what you would try and do is find something that would be unique to that effect so we can use regular expressions to fish out the text between those tags. But since the site is dynamically created, this won't have any special text.

    Hope it helps, i'll keep on trying,

    Gav


Bookmarks

Posting Permissions

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