Posts: 120
Threads: 11
Joined: Jan 2011
Reputation:
0
08-14-2011, 03:40 AM
(This post was last modified: 08-14-2011, 03:41 AM by w00pz.)
Alright, so I tried to make a currency converter, that connects to http://www.xe.com/ and using xe.com's currency rates.
I can't seem to find a way to get it working.
Any advice or help is appreciated.
Thanks.
Posts: 3,538
Threads: 348
Joined: Mar 2010
Reputation:
57
What have you got so far?
The URL is very straight forward, for example:
http://www.xe.com/ucc/convert/?Amount=10...EUR&To=USD
This means all you need to do, is replace the values in the URL, download the page, and extract the results.
Posts: 120
Threads: 11
Joined: Jan 2011
Reputation:
0
(08-14-2011, 04:35 AM)Fragma Wrote: What have you got so far?
The URL is very straight forward, for example:
http://www.xe.com/ucc/convert/?Amount=10...EUR&To=USD
This means all you need to do, is replace the values in the URL, download the page, and extract the results.
Only the layout, I don't know how I would go about getting the converted number into a textbox.
I guess I would need to use webrequests right?
Posts: 3,538
Threads: 348
Joined: Mar 2010
Reputation:
57
Yep, and you will need to use a GetBetween function in order to extract the specific string you need.
Credits go to whoever coded this function. I've forgotten his username.
Code: Public Function GetBetween(ByRef strSource As String, ByRef strStart As String, ByRef strEnd As String, _
Optional ByRef startPos As Integer = 0) As String
Dim iPos As Integer, iEnd As Integer, lenStart As Integer = strStart.Length
Dim strResult As String
strResult = String.Empty
iPos = strSource.IndexOf(strStart, startPos)
iEnd = strSource.IndexOf(strEnd, iPos + lenStart)
If iPos <> -1 AndAlso iEnd <> -1 Then
strResult = strSource.Substring(iPos + lenStart, iEnd - (iPos + lenStart))
End If
Return strResult
End Function
If you need anymore help just let me know.
Posts: 120
Threads: 11
Joined: Jan 2011
Reputation:
0
(08-14-2011, 07:25 AM)Fragma Wrote: Yep, and you will need to use a GetBetween function in order to extract the specific string you need.
Credits go to whoever coded this function. I've forgotten his username.
Code: Public Function GetBetween(ByRef strSource As String, ByRef strStart As String, ByRef strEnd As String, _
Optional ByRef startPos As Integer = 0) As String
Dim iPos As Integer, iEnd As Integer, lenStart As Integer = strStart.Length
Dim strResult As String
strResult = String.Empty
iPos = strSource.IndexOf(strStart, startPos)
iEnd = strSource.IndexOf(strEnd, iPos + lenStart)
If iPos <> -1 AndAlso iEnd <> -1 Then
strResult = strSource.Substring(iPos + lenStart, iEnd - (iPos + lenStart))
End If
Return strResult
End Function
If you need anymore help just let me know.
I don't really understand that code, would you mind explaining what each line does?
I would really appreciate it.
Posts: 3,538
Threads: 348
Joined: Mar 2010
Reputation:
57
That function will find 2 strings, and read the text in between both of those strings.
For example...
Code: Dim myWebClient As New WebClient()
Dim myDatabuffer As Byte() = myWebClient.DownloadData("http://www.xe.com/ucc/convert/?Amount=" & NUMBER & "&From=" &EUR&To=USD")
Dim download As String = Encoding.ASCII.GetString(myDatabuffer)
Dim CON As String = GetBetween(download, _
"<td align="right">", "</td>", 0)
That will download the webpage with the results from your search, and extract the string between "<td align="right">" and "</td>", which in this example would be 1 EUR = 1.42440 USD
Posts: 120
Threads: 11
Joined: Jan 2011
Reputation:
0
(08-14-2011, 07:39 AM)Fragma Wrote: That function will find 2 strings, and read the text in between both of those strings.
For example...
Code: Dim myWebClient As New WebClient()
Dim myDatabuffer As Byte() = myWebClient.DownloadData("http://www.xe.com/ucc/convert/?Amount=" & NUMBER & "&From=" &EUR&To=USD")
Dim download As String = Encoding.ASCII.GetString(myDatabuffer)
Dim CON As String = GetBetween(download, _
"<td align="right">", "</td>", 0)
That will download the webpage with the results from your search, and extract the string between "<td align="right">" and "</td>", which in this example would be 1 EUR = 1.42440 USD And where will it extract it to?
Is it possible to make it extact to texbox3?
Posts: 3,538
Threads: 348
Joined: Mar 2010
Reputation:
57
What the code above is, is Dims CON as the extracted string. So to show the string into a textbox, simply do:
Posts: 120
Threads: 11
Joined: Jan 2011
Reputation:
0
08-14-2011, 08:12 AM
(This post was last modified: 08-14-2011, 08:13 AM by w00pz.)
I'm getting some errors.
Do you happen to know why I get these errors.
This is what I have in the lines:
Code: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myWebClient As New WebClient()
Dim myDatabuffer As Byte() = myWebClient.DownloadData("http://www.xe.com/ucc/convert/?Amount=" & amount.text & "&From=" & combobox1.text & "&to=" & combobox2.Text ")
Dim download As String = Encoding.ASCII.GetString(myDatabuffer)
Dim CON As String = GetBetween(download, _
"<td align="right">", "</td>", 0)
End Sub
Posts: 3,538
Threads: 348
Joined: Mar 2010
Reputation:
57
What errors are you getting? The code I gave you might not work 100% it was just an example.
|