1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
' Currency Convert
Imports System.IO
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub doCalculate()
' Need the scraping
Dim Str As System.IO.Stream
Dim srRead As System.IO.StreamReader
Dim strAmount As String
strAmount = currencyAmount.Text
' Get values from the textboxes
Dim strFrom() As String = Split(currencyFrom.Text, " - ")
Dim strTo() As String = Split(currencyTo.Text, " - ")
' Web fetching variables
Dim req As System.Net.WebRequest = System.Net.WebRequest.Create("http://www.xe.com/ucc/convert.cgi?Amount=" + strAmount + "&From=" + strFrom(1) + "&To=" + strTo(1) + "YER&image.x=47&image.y=19&image=Submit")
Dim resp As System.Net.WebResponse = req.GetResponse
Str = resp.GetResponseStream
srRead = New System.IO.StreamReader(Str)
' Match the response
Try
Dim myMatches As MatchCollection
Dim myRegExp As New Regex("([0-9]+\.[0-9]+ " + strTo(1) + ")")
myMatches = myRegExp.Matches(srRead.ReadToEnd)
' Search for all the words in the string
Dim sucessfulMatch As Match
For Each sucessfulMatch In myMatches
mainText.Text = sucessfulMatch.Value
Next
Catch ex As Exception
mainText.Text = "Unable to connect to XE"
Finally
' Close the streams
srRead.close()
Str.Close()
End Try
convertToLabel.Text = strAmount + " " + strFrom(0) + " Converts To: "
End Sub
Private Sub convertButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles convertButton.Click
' Check if the currency is a number
If Not IsNumeric(currencyAmount.Text) Then
MsgBox("Please enter a valid amount!", MsgBoxStyle.Information, "Invalid Input")
currencyAmount.Focus()
Return
End If
doCalculate()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
currencyFrom.selectedIndex = 0
currencyTo.SelectedIndex = 1
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox("Simple Currency Converter By Aziz S. Hussain", MsgBoxStyle.Information, "www.AzizSaleh.com")
End Sub
End Class |
Partager