-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirst project
More file actions
61 lines (50 loc) · 2.12 KB
/
first project
File metadata and controls
61 lines (50 loc) · 2.12 KB
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
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 vriables
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) + "&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 successfulMatch As Match
For Each successfulMatch In myMatches
Maintext.Text = successfulMatch.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 convertbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles convertbtn.Click
' Check if the currency is anumber
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
End Class