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.
(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?
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.
(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.
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
(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?
What the code above is, is Dims CON as the extracted string. So to show the string into a textbox, simply do:
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
What errors are you getting? The code I gave you might not work 100% it was just an example.