Solved

API works for 1 result, need to make it many

Posted on 2016-09-21
30
52 Views
Last Modified: 2016-09-27
Hi there, I have code for a currency API that gives me a result for 1 value, however i want to modify it so it makes it multiple

current API code
Set oXMLHTTPClient=CreateObject("MSXML2.ServerXMLHTTP")
ClientCurrAPI="http://apilayer.net/api/live?access_key=ACCESSKEY&currencies=AUD&source=USD&format=1"
oXMLHTTPClient.Open "GET",ClientCurrAPI, False
oXMLHTTPClient.Send
If oXMLHTTPClient.Status=200 Then
	GetTextFromUrlClient=oXMLHTTPClient.responseText
	ArrClient1=Split(GetTextFromUrlClient,"USDAUD")
	ArrClient2=Split(ArrClient1(1),":")
	ArrClient3=Split(ArrClient2(1)," ")
	AUD=CDbl(ArrClient3(0))
End If

Open in new window

1 value API output:
{
  "success":true,
  "terms":"https:\/\/currencylayer.com\/terms",
  "privacy":"https:\/\/currencylayer.com\/privacy",
  "timestamp":1474469471,
  "source":"USD",
  "quotes":{
    "USDAUD":1.320992
  }
}

Open in new window

multiple value API output:
{
  "success":true,
  "terms":"https:\/\/currencylayer.com\/terms",
  "privacy":"https:\/\/currencylayer.com\/privacy",
  "timestamp":1474469471,
  "source":"USD",
  "quotes":{
    "USDAUD":1.320992,
    "USDMYR":4.13498,
    "USDAED":3.6726,
    "USDEUR":0.897097,
    "USDGBP":0.77169,
    "USDTHB":34.700001,
    "USDCAD":1.32132,
    "USDMXN":19.848203,
    "USDAZN":1.632602,
    "USDRUB":64.254799,
    "USDSGD":1.35946,
    "USDCNY":6.671101,
    "USDJPY":100.765999,
    "USDNZD":1.3673,
    "USDHKD":7.754969,
    "USDINR":66.957001,
    "USDBRL":3.2368
  }
}

Open in new window


The end result I would like is each particular value to be stand alone, eg

AUD=1.320992
MYR=4.13498
AED=3.6726
etc

these results will then be updated in the local database (Access 2003) in Classic ASP

please feel free to ask for anymore information
0
Comment
Question by:Graeme
  • 16
  • 12
  • 2
30 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 41809108
so you want to store the currency values into a ASP array?
0
 

Author Comment

by:Graeme
ID: 41809118
I think that is what I want to do

basically i want to update the DB every hour with the new rates

(i know you previously mentioned it in another post and the way i originally wanted to do it was very long winded and was adding server load time. I believe this will be much faster. 1 call and all results)
0
 
LVL 32

Assisted Solution

by:Big Monty
Big Monty earned 200 total points
ID: 41809181
you'll want to store the data in a JSON object, I would use the aspJSON class library. Unfortunately the site is down, so here's the code for the library, copy it into it's own asp file:

<%
'Februari 2014 - Version 1.17 by Gerrit van Kuipers
Class aspJSON
	Public data
	Private p_JSONstring
	private aj_in_string, aj_in_escape, aj_i_tmp, aj_char_tmp, aj_s_tmp, aj_line_tmp, aj_line, aj_lines, aj_currentlevel, aj_currentkey, aj_currentvalue, aj_newlabel, aj_XmlHttp, aj_RegExp, aj_colonfound

	Private Sub Class_Initialize()
		Set data = Collection()

	    Set aj_RegExp = new regexp
	    aj_RegExp.Pattern = "\s{0,}(\S{1}[\s,\S]*\S{1})\s{0,}"
	    aj_RegExp.Global = False
	    aj_RegExp.IgnoreCase = True
	    aj_RegExp.Multiline = True
	End Sub

	Private Sub Class_Terminate()
		Set data = Nothing
	    Set aj_RegExp = Nothing
	End Sub

	Public Sub loadJSON(inputsource)
		inputsource = aj_MultilineTrim(inputsource)
		If Len(inputsource) = 0 Then Err.Raise 1, "loadJSON Error", "No data to load."
		
		select case Left(inputsource, 1)
			case "{", "["
			case else
				Set aj_XmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
				aj_XmlHttp.open "GET", inputsource, False
				aj_XmlHttp.setRequestHeader "Content-Type", "text/json"
				aj_XmlHttp.setRequestHeader "CharSet", "UTF-8"
				aj_XmlHttp.Send
				inputsource = aj_XmlHttp.responseText
				set aj_XmlHttp = Nothing
		end select

		p_JSONstring = CleanUpJSONstring(inputsource)
		aj_lines = Split(p_JSONstring, Chr(13) & Chr(10))

		Dim level(99)
		aj_currentlevel = 1
		Set level(aj_currentlevel) = data
		For Each aj_line In aj_lines
			aj_currentkey = ""
			aj_currentvalue = ""
			If Instr(aj_line, ":") > 0 Then
				aj_in_string = False
				aj_in_escape = False
				aj_colonfound = False
				For aj_i_tmp = 1 To Len(aj_line)
					If aj_in_escape Then
						aj_in_escape = False
					Else
						Select Case Mid(aj_line, aj_i_tmp, 1)
							Case """"
								aj_in_string = Not aj_in_string
							Case ":"
								If Not aj_in_escape And Not aj_in_string Then
									aj_currentkey = Left(aj_line, aj_i_tmp - 1)
									aj_currentvalue = Mid(aj_line, aj_i_tmp + 1)
									aj_colonfound = True
									Exit For
								End If
							Case "\"
								aj_in_escape = True
						End Select
					End If
				Next
				if aj_colonfound then
					aj_currentkey = aj_Strip(aj_JSONDecode(aj_currentkey), """")
					If Not level(aj_currentlevel).exists(aj_currentkey) Then level(aj_currentlevel).Add aj_currentkey, ""
				end if
			End If
			If right(aj_line,1) = "{" Or right(aj_line,1) = "[" Then
				If Len(aj_currentkey) = 0 Then aj_currentkey = level(aj_currentlevel).Count
				Set level(aj_currentlevel).Item(aj_currentkey) = Collection()
				Set level(aj_currentlevel + 1) = level(aj_currentlevel).Item(aj_currentkey)
				aj_currentlevel = aj_currentlevel + 1
				aj_currentkey = ""
			ElseIf right(aj_line,1) = "}" Or right(aj_line,1) = "]" or right(aj_line,2) = "}," Or right(aj_line,2) = "]," Then
				aj_currentlevel = aj_currentlevel - 1
			ElseIf Len(Trim(aj_line)) > 0 Then
				if Len(aj_currentvalue) = 0 Then aj_currentvalue = aj_line
				aj_currentvalue = getJSONValue(aj_currentvalue)

				If Len(aj_currentkey) = 0 Then aj_currentkey = level(aj_currentlevel).Count
				level(aj_currentlevel).Item(aj_currentkey) = aj_currentvalue
			End If
		Next
	End Sub

	Public Function Collection()
		set Collection = Server.CreateObject("Scripting.Dictionary")
	End Function

	Public Function AddToCollection(dictobj)
		if TypeName(dictobj) <> "Dictionary" then Err.Raise 1, "AddToCollection Error", "Not a collection."
		aj_newlabel = dictobj.Count
		dictobj.Add aj_newlabel, Collection()
		set AddToCollection = dictobj.item(aj_newlabel)
	end function

	Private Function CleanUpJSONstring(aj_originalstring)
		aj_originalstring = Replace(aj_originalstring, Chr(13) & Chr(10), "")
		aj_originalstring = Mid(aj_originalstring, 2, Len(aj_originalstring) - 2)
		aj_in_string = False : aj_in_escape = False : aj_s_tmp = ""
		For aj_i_tmp = 1 To Len(aj_originalstring)
			aj_char_tmp = Mid(aj_originalstring, aj_i_tmp, 1)
			If aj_in_escape Then
				aj_in_escape = False
				aj_s_tmp = aj_s_tmp & aj_char_tmp
			Else
				Select Case aj_char_tmp
					Case "\" : aj_s_tmp = aj_s_tmp & aj_char_tmp : aj_in_escape = True
					Case """" : aj_s_tmp = aj_s_tmp & aj_char_tmp : aj_in_string = Not aj_in_string
					Case "{", "["
						aj_s_tmp = aj_s_tmp & aj_char_tmp & aj_InlineIf(aj_in_string, "", Chr(13) & Chr(10))
					Case "}", "]"
						aj_s_tmp = aj_s_tmp & aj_InlineIf(aj_in_string, "", Chr(13) & Chr(10)) & aj_char_tmp
					Case "," : aj_s_tmp = aj_s_tmp & aj_char_tmp & aj_InlineIf(aj_in_string, "", Chr(13) & Chr(10))
					Case Else : aj_s_tmp = aj_s_tmp & aj_char_tmp
				End Select
			End If
		Next

		CleanUpJSONstring = ""
		aj_s_tmp = split(aj_s_tmp, Chr(13) & Chr(10))
		For Each aj_line_tmp In aj_s_tmp
			aj_line_tmp = replace(replace(aj_line_tmp, chr(10), ""), chr(13), "")
			CleanUpJSONstring = CleanUpJSONstring & aj_Trim(aj_line_tmp) & Chr(13) & Chr(10)
		Next
	End Function

	Private Function getJSONValue(ByVal val)
		val = Trim(val)
		If Left(val,1) = ":"  Then val = Mid(val, 2)
		If Right(val,1) = "," Then val = Left(val, Len(val) - 1)
		val = Trim(val)

		Select Case val
			Case "true"  : getJSONValue = True
			Case "false" : getJSONValue = False
			Case "null" : getJSONValue = Null
			Case Else
				If (Instr(val, """") = 0) Then
					If IsNumeric(val) Then
						getJSONValue = CDbl(val)
					Else
						getJSONValue = val
					End If
				Else
					If Left(val,1) = """" Then val = Mid(val, 2)
					If Right(val,1) = """" Then val = Left(val, Len(val) - 1)
					getJSONValue = aj_JSONDecode(Trim(val))
				End If
		End Select
	End Function

	Private JSONoutput_level
	Public Function JSONoutput()
		dim wrap_dicttype, aj_label
		JSONoutput_level = 1
		wrap_dicttype = "[]"
		For Each aj_label In data
			 If Not aj_IsInt(aj_label) Then wrap_dicttype = "{}"
		Next
		JSONoutput = Left(wrap_dicttype, 1) & Chr(13) & Chr(10) & GetDict(data) & Right(wrap_dicttype, 1)
	End Function

	Private Function GetDict(objDict)
		dim aj_item, aj_keyvals, aj_label, aj_dicttype
		For Each aj_item In objDict
			Select Case TypeName(objDict.Item(aj_item))
				Case "Dictionary"
					GetDict = GetDict & Space(JSONoutput_level * 4)
					
					aj_dicttype = "[]"
					For Each aj_label In objDict.Item(aj_item).Keys
						 If Not aj_IsInt(aj_label) Then aj_dicttype = "{}"
					Next
					If aj_IsInt(aj_item) Then
						GetDict = GetDict & (Left(aj_dicttype,1) & Chr(13) & Chr(10))
					Else
						GetDict = GetDict & ("""" & aj_JSONEncode(aj_item) & """" & ": " & Left(aj_dicttype,1) & Chr(13) & Chr(10))
					End If
					JSONoutput_level = JSONoutput_level + 1
					
					aj_keyvals = objDict.Keys
					GetDict = GetDict & (GetSubDict(objDict.Item(aj_item)) & Space(JSONoutput_level * 4) & Right(aj_dicttype,1) & aj_InlineIf(aj_item = aj_keyvals(objDict.Count - 1),"" , ",") & Chr(13) & Chr(10))
				Case Else
					aj_keyvals =  objDict.Keys
					GetDict = GetDict & (Space(JSONoutput_level * 4) & aj_InlineIf(aj_IsInt(aj_item), "", """" & aj_JSONEncode(aj_item) & """: ") & WriteValue(objDict.Item(aj_item)) & aj_InlineIf(aj_item = aj_keyvals(objDict.Count - 1),"" , ",") & Chr(13) & Chr(10))
			End Select
		Next
	End Function

	Private Function aj_IsInt(val)
		aj_IsInt = (TypeName(val) = "Integer" Or TypeName(val) = "Long")
	End Function

	Private Function GetSubDict(objSubDict)
		GetSubDict = GetDict(objSubDict)
		JSONoutput_level= JSONoutput_level -1
	End Function

	Private Function WriteValue(ByVal val)
		Select Case TypeName(val)
			Case "Double", "Integer", "Long": WriteValue = val
			Case "Null"						: WriteValue = "null"
			Case "Boolean"					: WriteValue = aj_InlineIf(val, "true", "false")
			Case Else						: WriteValue = """" & aj_JSONEncode(val) & """"
		End Select
	End Function

	Private Function aj_JSONEncode(ByVal val)
		val = Replace(val, "\", "\\")
		val = Replace(val, """", "\""")
		'val = Replace(val, "/", "\/")
		val = Replace(val, Chr(8), "\b")
		val = Replace(val, Chr(12), "\f")
		val = Replace(val, Chr(10), "\n")
		val = Replace(val, Chr(13), "\r")
		val = Replace(val, Chr(9), "\t")
		aj_JSONEncode = Trim(val)
	End Function

	Private Function aj_JSONDecode(ByVal val)
		val = Replace(val, "\""", """")
		val = Replace(val, "\\", "\")
		val = Replace(val, "\/", "/")
		val = Replace(val, "\b", Chr(8))
		val = Replace(val, "\f", Chr(12))
		val = Replace(val, "\n", Chr(10))
		val = Replace(val, "\r", Chr(13))
		val = Replace(val, "\t", Chr(9))
		aj_JSONDecode = Trim(val)
	End Function

	Private Function aj_InlineIf(condition, returntrue, returnfalse)
		If condition Then aj_InlineIf = returntrue Else aj_InlineIf = returnfalse
	End Function

	Private Function aj_Strip(ByVal val, stripper)
		If Left(val, 1) = stripper Then val = Mid(val, 2)
		If Right(val, 1) = stripper Then val = Left(val, Len(val) - 1)
		aj_Strip = val
	End Function

	Private Function aj_MultilineTrim(TextData)
		aj_MultilineTrim = aj_RegExp.Replace(TextData, "$1")
	End Function

	private function aj_Trim(val)
		aj_Trim = Trim(val)
		Do While Left(aj_Trim, 1) = Chr(9) : aj_Trim = Mid(aj_Trim, 2) : Loop
		Do While Right(aj_Trim, 1) = Chr(9) : aj_Trim = Left(aj_Trim, Len(aj_Trim) - 1) : Loop
		aj_Trim = Trim(aj_Trim)
	end function
End Class
%>

Open in new window


now include that file into your API code, and in that code, you can do:

Set oXMLHTTPClient=CreateObject("MSXML2.ServerXMLHTTP")
ClientCurrAPI="http://apilayer.net/api/live?access_key=ACCESSKEY&currencies=AUD&source=USD&format=1"
oXMLHTTPClient.Open "GET",ClientCurrAPI, False
oXMLHTTPClient.Send
If oXMLHTTPClient.Status=200 Then
	GetTextFromUrlClient = oXMLHTTPClient.responseText
	dim oJSON       :       Set oJSON = New aspJSON
        oJSON.loadJSON( GetTextFromUrlClient )
End If

Open in new window


you now have a nice json object which you can access properties from, like so:

dim USDAUD : USDAUD = oJSON.data("quotes").item( "USDAUD" )(0)

(was just popping in for a sec and saw this. I just did something very similar, so thought I'd save you from the struggles of manually parsing the data :) )
0
 

Author Comment

by:Graeme
ID: 41810036
Ryan, how did you go with this?

BigMonty - is the site up?
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 41810135
@Graeme,

what BigMonty provided should do the trick, like:

....
oJSON.loadJSON( GetTextFromUrlClient )
   
    USDAUD = oJSON.data("quotes").item( "USDAUD" )
    USDMYR = oJSON.data("quotes").item( "USDMYR" )
    USDAED = oJSON.data("quotes").item( "USDAED" )
    USDEUR = oJSON.data("quotes").item( "USDEUR" )
    USDGBP = oJSON.data("quotes").item( "USDGBP" )
    USDTHB = oJSON.data("quotes").item( "USDTHB" )
    USDCAD = oJSON.data("quotes").item( "USDCAD" )
    USDMXN = oJSON.data("quotes").item( "USDMXN" )
    USDAZN = oJSON.data("quotes").item( "USDAZN" )
    USDRUB = oJSON.data("quotes").item( "USDRUB" )
    USDSGD = oJSON.data("quotes").item( "USDSGD" )
    USDCNY = oJSON.data("quotes").item( "USDCNY" )
    USDJPY = oJSON.data("quotes").item( "USDJPY" )
    USDNZD = oJSON.data("quotes").item( "USDNZD" )
    USDHKD = oJSON.data("quotes").item( "USDHKD" )
    USDINR = oJSON.data("quotes").item( "USDINR" )
    USDBRL = oJSON.data("quotes").item( "USDBRL" )
    
    response.write "<br>USDAUD = " & USDAUD
    response.write "<br>USDMYR = " & USDMYR
    response.write "<br>USDAED = " & USDAED
    response.write "<br>USDEUR = " & USDEUR
    response.write "<br>USDGBP = " & USDGBP
    response.write "<br>USDTHB = " & USDTHB
    response.write "<br>USDCAD = " & USDCAD
    response.write "<br>USDMXN = " & USDMXN
    response.write "<br>USDAZN = " & USDAZN
    response.write "<br>USDRUB = " & USDRUB
    response.write "<br>USDSGD = " & USDSGD
    response.write "<br>USDCNY = " & USDCNY
    response.write "<br>USDJPY = " & USDJPY
    response.write "<br>USDNZD = " & USDNZD
    response.write "<br>USDHKD = " & USDHKD
    response.write "<br>USDINR = " & USDINR
    response.write "<br>USDBRL = " & USDBRL

Open in new window

You can directly refer to the dictionary object if you wish to do looping instead, like;
keys = oJSON.data("quotes").Keys
    values = oJSON.data("quotes").Items
    for i = 0 to oJSON.data("quotes").count - 1
        response.write("<br>" & keys(i) & " = " & values(i) )
    next

Open in new window

0
 

Author Comment

by:Graeme
ID: 41810156
thanks guys, I will give it a whirl and get back to you both

Cheers!
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 41810616
I take it you mean the site I did this on? Yes but it's a pw protected site.
0
 

Author Comment

by:Graeme
ID: 41812020
Sorry I am a little confused... how do I use all the Currencies in yours BigMonty?

Ryan, sorry I am a little lost with yours, of where it goes and how to apply it
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 41812033
@Graeme,

try this example: (just amend GetTextFromUrlClient  to the real API response when necessary)
<%
    

    dim oJSON
    Set oJSON = New aspJSON

    GetTextFromUrlClient = "{" & _
                           "   ""success"":true," & _
                           "  ""terms"":""https:\/\/currencylayer.com\/terms""," & _
                           "   ""privacy"":""https:\/\/currencylayer.com\/privacy""," & _
                           "   ""timestamp"":1474469471," & _
                           "   ""source"":""USD""," & _
                           "   ""quotes"":{" & _
                           "     ""USDAUD"":1.320992," & _
                           "     ""USDMYR"":4.13498," & _
                           "     ""USDAED"":3.6726," & _
                           "     ""USDEUR"":0.897097," & _
                           "     ""USDGBP"":0.77169," & _
                           "     ""USDTHB"":34.700001," & _
                           "     ""USDCAD"":1.32132," & _
                           "     ""USDMXN"":19.848203," & _
                           "     ""USDAZN"":1.632602," & _
                           "     ""USDRUB"":64.254799," & _
                           "     ""USDSGD"":1.35946," & _
                           "     ""USDCNY"":6.671101," & _
                           "     ""USDJPY"":100.765999," & _
                           "     ""USDNZD"":1.3673," & _
                           "     ""USDHKD"":7.754969," & _
                           "     ""USDINR"":66.957001," & _
                           "     ""USDBRL"":3.2368" & _
                           "   }" & _
                           " }"
    oJSON.loadJSON( GetTextFromUrlClient )
   
    'a=oJSON.data("quotes").Keys
    'for i=0 to oJSON.data("quotes").Count-1
    '  Response.Write(a(i))
    '  Response.Write("<br>")
    'next
    'response.End
    keys = oJSON.data("quotes").Keys
    values = oJSON.data("quotes").Items
    for i = 0 to oJSON.data("quotes").count - 1
        response.write("<br>" & keys(i) & " = " & values(i) )
    next


'Februari 2014 - Version 1.17 by Gerrit van Kuipers
Class aspJSON
	Public data
	Private p_JSONstring
	private aj_in_string, aj_in_escape, aj_i_tmp, aj_char_tmp, aj_s_tmp, aj_line_tmp, aj_line, aj_lines, aj_currentlevel, aj_currentkey, aj_currentvalue, aj_newlabel, aj_XmlHttp, aj_RegExp, aj_colonfound

	Private Sub Class_Initialize()
		Set data = Collection()

	    Set aj_RegExp = new regexp
	    aj_RegExp.Pattern = "\s{0,}(\S{1}[\s,\S]*\S{1})\s{0,}"
	    aj_RegExp.Global = False
	    aj_RegExp.IgnoreCase = True
	    aj_RegExp.Multiline = True
	End Sub

	Private Sub Class_Terminate()
		Set data = Nothing
	    Set aj_RegExp = Nothing
	End Sub

	Public Sub loadJSON(inputsource)
		inputsource = aj_MultilineTrim(inputsource)
		If Len(inputsource) = 0 Then Err.Raise 1, "loadJSON Error", "No data to load."
		
		select case Left(inputsource, 1)
			case "{", "["
			case else
				Set aj_XmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
				aj_XmlHttp.open "GET", inputsource, False
				aj_XmlHttp.setRequestHeader "Content-Type", "text/json"
				aj_XmlHttp.setRequestHeader "CharSet", "UTF-8"
				aj_XmlHttp.Send
				inputsource = aj_XmlHttp.responseText
				set aj_XmlHttp = Nothing
		end select

		p_JSONstring = CleanUpJSONstring(inputsource)
		aj_lines = Split(p_JSONstring, Chr(13) & Chr(10))

		Dim level(99)
		aj_currentlevel = 1
		Set level(aj_currentlevel) = data
		For Each aj_line In aj_lines
			aj_currentkey = ""
			aj_currentvalue = ""
			If Instr(aj_line, ":") > 0 Then
				aj_in_string = False
				aj_in_escape = False
				aj_colonfound = False
				For aj_i_tmp = 1 To Len(aj_line)
					If aj_in_escape Then
						aj_in_escape = False
					Else
						Select Case Mid(aj_line, aj_i_tmp, 1)
							Case """"
								aj_in_string = Not aj_in_string
							Case ":"
								If Not aj_in_escape And Not aj_in_string Then
									aj_currentkey = Left(aj_line, aj_i_tmp - 1)
									aj_currentvalue = Mid(aj_line, aj_i_tmp + 1)
									aj_colonfound = True
									Exit For
								End If
							Case "\"
								aj_in_escape = True
						End Select
					End If
				Next
				if aj_colonfound then
					aj_currentkey = aj_Strip(aj_JSONDecode(aj_currentkey), """")
					If Not level(aj_currentlevel).exists(aj_currentkey) Then level(aj_currentlevel).Add aj_currentkey, ""
				end if
			End If
			If right(aj_line,1) = "{" Or right(aj_line,1) = "[" Then
				If Len(aj_currentkey) = 0 Then aj_currentkey = level(aj_currentlevel).Count
				Set level(aj_currentlevel).Item(aj_currentkey) = Collection()
				Set level(aj_currentlevel + 1) = level(aj_currentlevel).Item(aj_currentkey)
				aj_currentlevel = aj_currentlevel + 1
				aj_currentkey = ""
			ElseIf right(aj_line,1) = "}" Or right(aj_line,1) = "]" or right(aj_line,2) = "}," Or right(aj_line,2) = "]," Then
				aj_currentlevel = aj_currentlevel - 1
			ElseIf Len(Trim(aj_line)) > 0 Then
				if Len(aj_currentvalue) = 0 Then aj_currentvalue = aj_line
				aj_currentvalue = getJSONValue(aj_currentvalue)

				If Len(aj_currentkey) = 0 Then aj_currentkey = level(aj_currentlevel).Count
				level(aj_currentlevel).Item(aj_currentkey) = aj_currentvalue
			End If
		Next
	End Sub

	Public Function Collection()
		set Collection = Server.CreateObject("Scripting.Dictionary")
	End Function

	Public Function AddToCollection(dictobj)
		if TypeName(dictobj) <> "Dictionary" then Err.Raise 1, "AddToCollection Error", "Not a collection."
		aj_newlabel = dictobj.Count
		dictobj.Add aj_newlabel, Collection()
		set AddToCollection = dictobj.item(aj_newlabel)
	end function

	Private Function CleanUpJSONstring(aj_originalstring)
		aj_originalstring = Replace(aj_originalstring, Chr(13) & Chr(10), "")
		aj_originalstring = Mid(aj_originalstring, 2, Len(aj_originalstring) - 2)
		aj_in_string = False : aj_in_escape = False : aj_s_tmp = ""
		For aj_i_tmp = 1 To Len(aj_originalstring)
			aj_char_tmp = Mid(aj_originalstring, aj_i_tmp, 1)
			If aj_in_escape Then
				aj_in_escape = False
				aj_s_tmp = aj_s_tmp & aj_char_tmp
			Else
				Select Case aj_char_tmp
					Case "\" : aj_s_tmp = aj_s_tmp & aj_char_tmp : aj_in_escape = True
					Case """" : aj_s_tmp = aj_s_tmp & aj_char_tmp : aj_in_string = Not aj_in_string
					Case "{", "["
						aj_s_tmp = aj_s_tmp & aj_char_tmp & aj_InlineIf(aj_in_string, "", Chr(13) & Chr(10))
					Case "}", "]"
						aj_s_tmp = aj_s_tmp & aj_InlineIf(aj_in_string, "", Chr(13) & Chr(10)) & aj_char_tmp
					Case "," : aj_s_tmp = aj_s_tmp & aj_char_tmp & aj_InlineIf(aj_in_string, "", Chr(13) & Chr(10))
					Case Else : aj_s_tmp = aj_s_tmp & aj_char_tmp
				End Select
			End If
		Next

		CleanUpJSONstring = ""
		aj_s_tmp = split(aj_s_tmp, Chr(13) & Chr(10))
		For Each aj_line_tmp In aj_s_tmp
			aj_line_tmp = replace(replace(aj_line_tmp, chr(10), ""), chr(13), "")
			CleanUpJSONstring = CleanUpJSONstring & aj_Trim(aj_line_tmp) & Chr(13) & Chr(10)
		Next
	End Function

	Private Function getJSONValue(ByVal val)
		val = Trim(val)
		If Left(val,1) = ":"  Then val = Mid(val, 2)
		If Right(val,1) = "," Then val = Left(val, Len(val) - 1)
		val = Trim(val)

		Select Case val
			Case "true"  : getJSONValue = True
			Case "false" : getJSONValue = False
			Case "null" : getJSONValue = Null
			Case Else
				If (Instr(val, """") = 0) Then
					If IsNumeric(val) Then
						getJSONValue = CDbl(val)
					Else
						getJSONValue = val
					End If
				Else
					If Left(val,1) = """" Then val = Mid(val, 2)
					If Right(val,1) = """" Then val = Left(val, Len(val) - 1)
					getJSONValue = aj_JSONDecode(Trim(val))
				End If
		End Select
	End Function

	Private JSONoutput_level
	Public Function JSONoutput()
		dim wrap_dicttype, aj_label
		JSONoutput_level = 1
		wrap_dicttype = "[]"
		For Each aj_label In data
			 If Not aj_IsInt(aj_label) Then wrap_dicttype = "{}"
		Next
		JSONoutput = Left(wrap_dicttype, 1) & Chr(13) & Chr(10) & GetDict(data) & Right(wrap_dicttype, 1)
	End Function

	Private Function GetDict(objDict)
		dim aj_item, aj_keyvals, aj_label, aj_dicttype
		For Each aj_item In objDict
			Select Case TypeName(objDict.Item(aj_item))
				Case "Dictionary"
					GetDict = GetDict & Space(JSONoutput_level * 4)
					
					aj_dicttype = "[]"
					For Each aj_label In objDict.Item(aj_item).Keys
						 If Not aj_IsInt(aj_label) Then aj_dicttype = "{}"
					Next
					If aj_IsInt(aj_item) Then
						GetDict = GetDict & (Left(aj_dicttype,1) & Chr(13) & Chr(10))
					Else
						GetDict = GetDict & ("""" & aj_JSONEncode(aj_item) & """" & ": " & Left(aj_dicttype,1) & Chr(13) & Chr(10))
					End If
					JSONoutput_level = JSONoutput_level + 1
					
					aj_keyvals = objDict.Keys
					GetDict = GetDict & (GetSubDict(objDict.Item(aj_item)) & Space(JSONoutput_level * 4) & Right(aj_dicttype,1) & aj_InlineIf(aj_item = aj_keyvals(objDict.Count - 1),"" , ",") & Chr(13) & Chr(10))
				Case Else
					aj_keyvals =  objDict.Keys
					GetDict = GetDict & (Space(JSONoutput_level * 4) & aj_InlineIf(aj_IsInt(aj_item), "", """" & aj_JSONEncode(aj_item) & """: ") & WriteValue(objDict.Item(aj_item)) & aj_InlineIf(aj_item = aj_keyvals(objDict.Count - 1),"" , ",") & Chr(13) & Chr(10))
			End Select
		Next
	End Function

	Private Function aj_IsInt(val)
		aj_IsInt = (TypeName(val) = "Integer" Or TypeName(val) = "Long")
	End Function

	Private Function GetSubDict(objSubDict)
		GetSubDict = GetDict(objSubDict)
		JSONoutput_level= JSONoutput_level -1
	End Function

	Private Function WriteValue(ByVal val)
		Select Case TypeName(val)
			Case "Double", "Integer", "Long": WriteValue = val
			Case "Null"						: WriteValue = "null"
			Case "Boolean"					: WriteValue = aj_InlineIf(val, "true", "false")
			Case Else						: WriteValue = """" & aj_JSONEncode(val) & """"
		End Select
	End Function

	Private Function aj_JSONEncode(ByVal val)
		val = Replace(val, "\", "\\")
		val = Replace(val, """", "\""")
		'val = Replace(val, "/", "\/")
		val = Replace(val, Chr(8), "\b")
		val = Replace(val, Chr(12), "\f")
		val = Replace(val, Chr(10), "\n")
		val = Replace(val, Chr(13), "\r")
		val = Replace(val, Chr(9), "\t")
		aj_JSONEncode = Trim(val)
	End Function

	Private Function aj_JSONDecode(ByVal val)
		val = Replace(val, "\""", """")
		val = Replace(val, "\\", "\")
		val = Replace(val, "\/", "/")
		val = Replace(val, "\b", Chr(8))
		val = Replace(val, "\f", Chr(12))
		val = Replace(val, "\n", Chr(10))
		val = Replace(val, "\r", Chr(13))
		val = Replace(val, "\t", Chr(9))
		aj_JSONDecode = Trim(val)
	End Function

	Private Function aj_InlineIf(condition, returntrue, returnfalse)
		If condition Then aj_InlineIf = returntrue Else aj_InlineIf = returnfalse
	End Function

	Private Function aj_Strip(ByVal val, stripper)
		If Left(val, 1) = stripper Then val = Mid(val, 2)
		If Right(val, 1) = stripper Then val = Left(val, Len(val) - 1)
		aj_Strip = val
	End Function

	Private Function aj_MultilineTrim(TextData)
		aj_MultilineTrim = aj_RegExp.Replace(TextData, "$1")
	End Function

	private function aj_Trim(val)
		aj_Trim = Trim(val)
		Do While Left(aj_Trim, 1) = Chr(9) : aj_Trim = Mid(aj_Trim, 2) : Loop
		Do While Right(aj_Trim, 1) = Chr(9) : aj_Trim = Left(aj_Trim, Len(aj_Trim) - 1) : Loop
		aj_Trim = Trim(aj_Trim)
	end function
End Class
%>

Open in new window

0
 

Author Comment

by:Graeme
ID: 41812036
cheers for that

Question ?
the currencies that I will be changing all the time (query from a DB), so who do i account for that?
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 41812040
>>the currencies that I will be changing all the time (query from a DB), so who do i account for that?
in the loop, just execute the Update SQL statement accordingly...

you can tell us your targeted table's name, as well as fields to be updated.
for i = 0 to oJSON.data("quotes").count - 1
         'Update your records here...
    next

Open in new window

0
 

Author Comment

by:Graeme
ID: 41812062
So Ryan as you can see (from the Q I just asked), this is the Query to get the Currencies I need to update:

SELECT ticket_curr FROM tickets WHERE ticket_from>Now() AND ticket_live=TRUE AND ticket_soldout=FALSE Group By ticket_curr Order By ticket_curr

Open in new window

Result:
curr=AED,AUD,EUR,GBP,JPY,MYR,SGD,USD

Open in new window

which goes into the API query like:
http://apilayer.net/api/live?access_key=ACCESSSKEY&currencies="&Curr&"&source=USD&format=1

Open in new window

from here I just want to update each of them in the DB
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 41812089
so you want to update the rates to table: tickets? what field in table: tickets need to be updated?
0
 

Author Comment

by:Graeme
ID: 41812090
I would like to update the results to a different table

table: IATA_Country
feild: curr_rate
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 41812092
i see, so in table: IATA_Country do you have a field called as ticket_curr or similar?

you can try something like this:

....
connstr = "<your Connection String>"

Set conn = Server.CreateObject("ADODB.Connection")
conn.open connstr

keys = oJSON.data("quotes").Keys
values = oJSON.data("quotes").Items

for i = 0 to oJSON.data("quotes").count - 1
         SQLstr = "Update IATA_Country set curr_rate = " & values(i) & " where ticket_curr = '" & right(keys(i), 3) & "' "
        conn.execute SQLstr

    next
conn.close
set conn = nothing

Open in new window

0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Graeme
ID: 41814763
Hi Ryan, just trying this out

what are the 4 dots at the top of previous post?
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 41814769
>>what are the 4 dots at the top of previous post?
just to mean that before that it got codes that already been shown in previous comments, so that I will not repeat again in that particular comment.
0
 

Author Comment

by:Graeme
ID: 41814805
Sorry, I am completely lost what goes where :(

Can we start the code fresh please?
0
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 300 total points
ID: 41815254
so... perhaps you need to customize this accordingly:
<%
    

    dim oJSON
    Set oJSON = New aspJSON

    Set oXMLHTTPClient=CreateObject("MSXML2.ServerXMLHTTP")
    ClientCurrAPI="http://apilayer.net/api/live?access_key=ACCESSKEY&currencies=AUD&source=USD&format=1"
    oXMLHTTPClient.Open "GET",ClientCurrAPI, False
    oXMLHTTPClient.Send
    If oXMLHTTPClient.Status=200 Then
	    GetTextFromUrlClient=oXMLHTTPClient.responseText
    
        oJSON.loadJSON( GetTextFromUrlClient )
   
        connstr = "<your Connection String>"
        Set conn = Server.CreateObject("ADODB.Connection")
        conn.open connstr

        keys = oJSON.data("quotes").Keys
        values = oJSON.data("quotes").Items
        for i = 0 to oJSON.data("quotes").count - 1
            response.write("<br>" & keys(i) & " = " & values(i) )

            SQLstr = "Update IATA_Country set curr_rate = " & values(i) & " where ticket_curr = '" & right(keys(i), 3) & "' "
            conn.execute SQLstr
        next

        conn.close
        set conn = nothing

        response.write "Done: " & Now()
    End If

'Februari 2014 - Version 1.17 by Gerrit van Kuipers
Class aspJSON
	Public data
	Private p_JSONstring
	private aj_in_string, aj_in_escape, aj_i_tmp, aj_char_tmp, aj_s_tmp, aj_line_tmp, aj_line, aj_lines, aj_currentlevel, aj_currentkey, aj_currentvalue, aj_newlabel, aj_XmlHttp, aj_RegExp, aj_colonfound

	Private Sub Class_Initialize()
		Set data = Collection()

	    Set aj_RegExp = new regexp
	    aj_RegExp.Pattern = "\s{0,}(\S{1}[\s,\S]*\S{1})\s{0,}"
	    aj_RegExp.Global = False
	    aj_RegExp.IgnoreCase = True
	    aj_RegExp.Multiline = True
	End Sub

	Private Sub Class_Terminate()
		Set data = Nothing
	    Set aj_RegExp = Nothing
	End Sub

	Public Sub loadJSON(inputsource)
		inputsource = aj_MultilineTrim(inputsource)
		If Len(inputsource) = 0 Then Err.Raise 1, "loadJSON Error", "No data to load."
		
		select case Left(inputsource, 1)
			case "{", "["
			case else
				Set aj_XmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
				aj_XmlHttp.open "GET", inputsource, False
				aj_XmlHttp.setRequestHeader "Content-Type", "text/json"
				aj_XmlHttp.setRequestHeader "CharSet", "UTF-8"
				aj_XmlHttp.Send
				inputsource = aj_XmlHttp.responseText
				set aj_XmlHttp = Nothing
		end select

		p_JSONstring = CleanUpJSONstring(inputsource)
		aj_lines = Split(p_JSONstring, Chr(13) & Chr(10))

		Dim level(99)
		aj_currentlevel = 1
		Set level(aj_currentlevel) = data
		For Each aj_line In aj_lines
			aj_currentkey = ""
			aj_currentvalue = ""
			If Instr(aj_line, ":") > 0 Then
				aj_in_string = False
				aj_in_escape = False
				aj_colonfound = False
				For aj_i_tmp = 1 To Len(aj_line)
					If aj_in_escape Then
						aj_in_escape = False
					Else
						Select Case Mid(aj_line, aj_i_tmp, 1)
							Case """"
								aj_in_string = Not aj_in_string
							Case ":"
								If Not aj_in_escape And Not aj_in_string Then
									aj_currentkey = Left(aj_line, aj_i_tmp - 1)
									aj_currentvalue = Mid(aj_line, aj_i_tmp + 1)
									aj_colonfound = True
									Exit For
								End If
							Case "\"
								aj_in_escape = True
						End Select
					End If
				Next
				if aj_colonfound then
					aj_currentkey = aj_Strip(aj_JSONDecode(aj_currentkey), """")
					If Not level(aj_currentlevel).exists(aj_currentkey) Then level(aj_currentlevel).Add aj_currentkey, ""
				end if
			End If
			If right(aj_line,1) = "{" Or right(aj_line,1) = "[" Then
				If Len(aj_currentkey) = 0 Then aj_currentkey = level(aj_currentlevel).Count
				Set level(aj_currentlevel).Item(aj_currentkey) = Collection()
				Set level(aj_currentlevel + 1) = level(aj_currentlevel).Item(aj_currentkey)
				aj_currentlevel = aj_currentlevel + 1
				aj_currentkey = ""
			ElseIf right(aj_line,1) = "}" Or right(aj_line,1) = "]" or right(aj_line,2) = "}," Or right(aj_line,2) = "]," Then
				aj_currentlevel = aj_currentlevel - 1
			ElseIf Len(Trim(aj_line)) > 0 Then
				if Len(aj_currentvalue) = 0 Then aj_currentvalue = aj_line
				aj_currentvalue = getJSONValue(aj_currentvalue)

				If Len(aj_currentkey) = 0 Then aj_currentkey = level(aj_currentlevel).Count
				level(aj_currentlevel).Item(aj_currentkey) = aj_currentvalue
			End If
		Next
	End Sub

	Public Function Collection()
		set Collection = Server.CreateObject("Scripting.Dictionary")
	End Function

	Public Function AddToCollection(dictobj)
		if TypeName(dictobj) <> "Dictionary" then Err.Raise 1, "AddToCollection Error", "Not a collection."
		aj_newlabel = dictobj.Count
		dictobj.Add aj_newlabel, Collection()
		set AddToCollection = dictobj.item(aj_newlabel)
	end function

	Private Function CleanUpJSONstring(aj_originalstring)
		aj_originalstring = Replace(aj_originalstring, Chr(13) & Chr(10), "")
		aj_originalstring = Mid(aj_originalstring, 2, Len(aj_originalstring) - 2)
		aj_in_string = False : aj_in_escape = False : aj_s_tmp = ""
		For aj_i_tmp = 1 To Len(aj_originalstring)
			aj_char_tmp = Mid(aj_originalstring, aj_i_tmp, 1)
			If aj_in_escape Then
				aj_in_escape = False
				aj_s_tmp = aj_s_tmp & aj_char_tmp
			Else
				Select Case aj_char_tmp
					Case "\" : aj_s_tmp = aj_s_tmp & aj_char_tmp : aj_in_escape = True
					Case """" : aj_s_tmp = aj_s_tmp & aj_char_tmp : aj_in_string = Not aj_in_string
					Case "{", "["
						aj_s_tmp = aj_s_tmp & aj_char_tmp & aj_InlineIf(aj_in_string, "", Chr(13) & Chr(10))
					Case "}", "]"
						aj_s_tmp = aj_s_tmp & aj_InlineIf(aj_in_string, "", Chr(13) & Chr(10)) & aj_char_tmp
					Case "," : aj_s_tmp = aj_s_tmp & aj_char_tmp & aj_InlineIf(aj_in_string, "", Chr(13) & Chr(10))
					Case Else : aj_s_tmp = aj_s_tmp & aj_char_tmp
				End Select
			End If
		Next

		CleanUpJSONstring = ""
		aj_s_tmp = split(aj_s_tmp, Chr(13) & Chr(10))
		For Each aj_line_tmp In aj_s_tmp
			aj_line_tmp = replace(replace(aj_line_tmp, chr(10), ""), chr(13), "")
			CleanUpJSONstring = CleanUpJSONstring & aj_Trim(aj_line_tmp) & Chr(13) & Chr(10)
		Next
	End Function

	Private Function getJSONValue(ByVal val)
		val = Trim(val)
		If Left(val,1) = ":"  Then val = Mid(val, 2)
		If Right(val,1) = "," Then val = Left(val, Len(val) - 1)
		val = Trim(val)

		Select Case val
			Case "true"  : getJSONValue = True
			Case "false" : getJSONValue = False
			Case "null" : getJSONValue = Null
			Case Else
				If (Instr(val, """") = 0) Then
					If IsNumeric(val) Then
						getJSONValue = CDbl(val)
					Else
						getJSONValue = val
					End If
				Else
					If Left(val,1) = """" Then val = Mid(val, 2)
					If Right(val,1) = """" Then val = Left(val, Len(val) - 1)
					getJSONValue = aj_JSONDecode(Trim(val))
				End If
		End Select
	End Function

	Private JSONoutput_level
	Public Function JSONoutput()
		dim wrap_dicttype, aj_label
		JSONoutput_level = 1
		wrap_dicttype = "[]"
		For Each aj_label In data
			 If Not aj_IsInt(aj_label) Then wrap_dicttype = "{}"
		Next
		JSONoutput = Left(wrap_dicttype, 1) & Chr(13) & Chr(10) & GetDict(data) & Right(wrap_dicttype, 1)
	End Function

	Private Function GetDict(objDict)
		dim aj_item, aj_keyvals, aj_label, aj_dicttype
		For Each aj_item In objDict
			Select Case TypeName(objDict.Item(aj_item))
				Case "Dictionary"
					GetDict = GetDict & Space(JSONoutput_level * 4)
					
					aj_dicttype = "[]"
					For Each aj_label In objDict.Item(aj_item).Keys
						 If Not aj_IsInt(aj_label) Then aj_dicttype = "{}"
					Next
					If aj_IsInt(aj_item) Then
						GetDict = GetDict & (Left(aj_dicttype,1) & Chr(13) & Chr(10))
					Else
						GetDict = GetDict & ("""" & aj_JSONEncode(aj_item) & """" & ": " & Left(aj_dicttype,1) & Chr(13) & Chr(10))
					End If
					JSONoutput_level = JSONoutput_level + 1
					
					aj_keyvals = objDict.Keys
					GetDict = GetDict & (GetSubDict(objDict.Item(aj_item)) & Space(JSONoutput_level * 4) & Right(aj_dicttype,1) & aj_InlineIf(aj_item = aj_keyvals(objDict.Count - 1),"" , ",") & Chr(13) & Chr(10))
				Case Else
					aj_keyvals =  objDict.Keys
					GetDict = GetDict & (Space(JSONoutput_level * 4) & aj_InlineIf(aj_IsInt(aj_item), "", """" & aj_JSONEncode(aj_item) & """: ") & WriteValue(objDict.Item(aj_item)) & aj_InlineIf(aj_item = aj_keyvals(objDict.Count - 1),"" , ",") & Chr(13) & Chr(10))
			End Select
		Next
	End Function

	Private Function aj_IsInt(val)
		aj_IsInt = (TypeName(val) = "Integer" Or TypeName(val) = "Long")
	End Function

	Private Function GetSubDict(objSubDict)
		GetSubDict = GetDict(objSubDict)
		JSONoutput_level= JSONoutput_level -1
	End Function

	Private Function WriteValue(ByVal val)
		Select Case TypeName(val)
			Case "Double", "Integer", "Long": WriteValue = val
			Case "Null"						: WriteValue = "null"
			Case "Boolean"					: WriteValue = aj_InlineIf(val, "true", "false")
			Case Else						: WriteValue = """" & aj_JSONEncode(val) & """"
		End Select
	End Function

	Private Function aj_JSONEncode(ByVal val)
		val = Replace(val, "\", "\\")
		val = Replace(val, """", "\""")
		'val = Replace(val, "/", "\/")
		val = Replace(val, Chr(8), "\b")
		val = Replace(val, Chr(12), "\f")
		val = Replace(val, Chr(10), "\n")
		val = Replace(val, Chr(13), "\r")
		val = Replace(val, Chr(9), "\t")
		aj_JSONEncode = Trim(val)
	End Function

	Private Function aj_JSONDecode(ByVal val)
		val = Replace(val, "\""", """")
		val = Replace(val, "\\", "\")
		val = Replace(val, "\/", "/")
		val = Replace(val, "\b", Chr(8))
		val = Replace(val, "\f", Chr(12))
		val = Replace(val, "\n", Chr(10))
		val = Replace(val, "\r", Chr(13))
		val = Replace(val, "\t", Chr(9))
		aj_JSONDecode = Trim(val)
	End Function

	Private Function aj_InlineIf(condition, returntrue, returnfalse)
		If condition Then aj_InlineIf = returntrue Else aj_InlineIf = returnfalse
	End Function

	Private Function aj_Strip(ByVal val, stripper)
		If Left(val, 1) = stripper Then val = Mid(val, 2)
		If Right(val, 1) = stripper Then val = Left(val, Len(val) - 1)
		aj_Strip = val
	End Function

	Private Function aj_MultilineTrim(TextData)
		aj_MultilineTrim = aj_RegExp.Replace(TextData, "$1")
	End Function

	private function aj_Trim(val)
		aj_Trim = Trim(val)
		Do While Left(aj_Trim, 1) = Chr(9) : aj_Trim = Mid(aj_Trim, 2) : Loop
		Do While Right(aj_Trim, 1) = Chr(9) : aj_Trim = Left(aj_Trim, Len(aj_Trim) - 1) : Loop
		aj_Trim = Trim(aj_Trim)
	end function
End Class
%>

Open in new window

0
 

Author Comment

by:Graeme
ID: 41815342
and this goes in a completely different ASP file?
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 41815348
>>and this goes in a completely different ASP file?
yes, a better approach is you can save it as a test asp file first. Test it before deploy it into your actual asp file.
0
 

Assisted Solution

by:Graeme
Graeme earned 0 total points
ID: 41815361
OK, I have put this into a new file

And saw this line:
SQLstr = "Update IATA_Country set curr_rate = " & values(i) & " where ticket_curr = '" & right(keys(i), 3) & "' "

Open in new window


fixed it to:
SQLstr = "Update IATA_Country set curr_rate = " & values(i) & " where curr_link = '" & right(keys(i), 3) & "' "

Open in new window


and also added in the Query for getting the currently used Currencies for the API

Set Currencies=oConn.Execute("SELECT ticket_curr FROM tickets WHERE ticket_from>Now() AND ticket_live=TRUE AND ticket_soldout=FALSE Group By ticket_curr Order By ticket_curr")
CurrCount=0
Do Until Currencies.EOF
If CurrCount=0 Then
	Curr=Currencies("ticket_curr")
Else
	Curr=Curr&","&Currencies("ticket_curr")
End If
CurrCount=CurrCount+1
Currencies.MoveNext
	Loop

Open in new window


API:
ClientCurrAPI="http://apilayer.net/api/live?access_key=ACCESSKEY&currencies="&Curr&"&source=USD&format=1"

Open in new window


Looks to be working so far! :)
0
 

Author Comment

by:Graeme
ID: 41816220
OK, so I have been moving it over into my page, and Im getting an error

Microsoft VBScript compilation error '800a03ea'

Syntax error

/home.asp, line 142

Class aspJSON
^

Open in new window

The start of the Function?

It works perfectly fine in its own file, just not integrated... strange

Identical code too, made sure everything was clean prior to moving over
0
 

Author Comment

by:Graeme
ID: 41816240
http://dev.gptouring.com.au/testing.asp
with the user and pw i sent you previously
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 41817148
hi, found that there's output on 27 Sep 11:42am GMT + 8
SnapShot1.pngis everything fine now?
0
 

Author Comment

by:Graeme
ID: 41817244
yeah this page works fine, however when I copy and paste it to the page I want to put it on, errors come up on Class aspJSON
0
 
LVL 49

Assisted Solution

by:Ryan Chong
Ryan Chong earned 300 total points
ID: 41817261
you can put Class aspJSON at the most bottom of your page or you can put it into a new .asp file and then include it into your existing asp page.

<!--#include file="yourClass.asp"-->

Open in new window

0
 

Author Comment

by:Graeme
ID: 41817266
Oh right!

with the include, does that go within <% %> or out side them?
0
 

Author Comment

by:Graeme
ID: 41817278
Figured it!

cheers mate!
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 41817283
>>with the include, does that go within <% %> or out side them?

outside of it

and glad you resolved the issue, cheers
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now