-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm3.vb
181 lines (150 loc) · 6.18 KB
/
Form3.vb
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
Public Class Form3
Dim bigarray(100, 200) As String 'declare array large enough for dataset
Dim icount As Integer
Dim linesInFile As Integer = 0
Dim columns As Integer
Dim sr As New System.IO.StreamReader("C:\presac1\shopdata.csv")
Dim x, y As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Prompt for search entries
MsgBox("Loading file")
'(columns, rows)
'Load the whole database into a 2 dimension array - bigarray
Do Until sr.EndOfStream = True
linesInFile = linesInFile + 1 ' indicates the number of rows, j
Label2.Text = sr.ReadLine & vbNewLine
'the test array splits the label2 into array items seperated by a comma
Dim testArray() As String = Split(Label2.Text, Delimiter:=",")
'MsgBox(testArray.Length) ' 7 columns in 1 row. testArray.length=7
For columns = 0 To (testArray.Length - 1)
bigarray(columns, linesInFile) = testArray(columns)
Next
Loop
x = columns
y = linesInFile
'Test if data sucessfully saved
'MsgBox(bigarray(0, 2)) ' understanding silicon life
'MsgBox(bigarray(0, 1)) ' This is the title row (not data)
MsgBox("Let's find our entry")
Dim textbooktofind, purchasertofind As String
textbooktofind = InputBox("What is the Name of the book?")
purchasertofind = InputBox("What is the first name Of the purchaser?")
Dim bfound As Boolean
MsgBox(linesInFile)
For icount = 0 To linesInFile
MsgBox(icount)
If bigarray(0, icount) = textbooktofind And bigarray(4, icount) = purchasertofind Then
MsgBox(icount)
bfound = True
MsgBox("Book found!")
lblTitle.Text = bigarray(0, icount)
lblSubject.Text = bigarray(1, icount)
lblSeller.Text = bigarray(2, icount)
lblPPrice.Text = bigarray(3, icount)
lblPurchaser.Text = bigarray(4, icount)
lblSalePrice.Text = bigarray(5, icount)
lblRating.Text = bigarray(6, icount)
MsgBox("Click button on right to rate book")
Button2.Enabled = True
'rate the book
Else
MsgBox("Book not found!")
'icount = icount + 1
'Exit For
End If
Next
End Sub
Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Button2.Enabled = False
Button3.Enabled = False
RadioButton1.Enabled = False
RadioButton2.Enabled = False
RadioButton3.Enabled = False
RadioButton4.Enabled = False
RadioButton5.Enabled = False
RadioButton6.Enabled = False
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
MsgBox("Enter a new rating for the book on the right!")
RadioButton1.Enabled = True
RadioButton2.Enabled = True
RadioButton3.Enabled = True
RadioButton4.Enabled = True
RadioButton5.Enabled = True
RadioButton6.Enabled = True
End Sub
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked = True Then ' NA Rating
bigarray(6, icount) = "NA"
Else
bigarray(6, icount) = "-"
End If
lblRating.Text = bigarray(6, icount)
MsgBox(bigarray(6, icount))
Button3.Enabled = True
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
If RadioButton2.Checked = True Then
bigarray(6, icount) = "1"
Else
bigarray(6, icount) = "-"
End If
lblRating.Text = bigarray(6, icount)
MsgBox(bigarray(6, icount))
Button3.Enabled = True
End Sub
Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton3.CheckedChanged
If RadioButton3.Checked = True Then
bigarray(6, icount) = "2"
Else
bigarray(6, icount) = "-"
End If
lblRating.Text = bigarray(6, icount)
MsgBox(bigarray(6, icount))
Button3.Enabled = True
End Sub
Private Sub RadioButton4_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton4.CheckedChanged
If RadioButton4.Checked = True Then
bigarray(6, icount) = "3"
Else
bigarray(6, icount) = "-"
End If
lblRating.Text = bigarray(6, icount)
MsgBox(bigarray(6, icount))
Button3.Enabled = True
End Sub
Private Sub RadioButton5_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton5.CheckedChanged
If RadioButton5.Checked = True Then
bigarray(6, icount) = "4"
Else
bigarray(6, icount) = "-"
End If
lblRating.Text = bigarray(6, icount)
MsgBox(bigarray(6, icount))
Button3.Enabled = True
End Sub
Private Sub RadioButton6_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton6.CheckedChanged
If RadioButton6.Checked = True Then
bigarray(6, icount) = "5"
Else
bigarray(6, icount) = "-"
End If
lblRating.Text = bigarray(6, icount)
MsgBox(bigarray(6, icount))
Button3.Enabled = True
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
'this code will save the entire array in a new CSV file
Dim file As System.IO.StreamWriter
file = My.Computer.FileSystem.OpenTextFileWriter("C:\presac1\newfile.csv", True)
For linesInFile = 0 To (y - 1)
For columns = 0 To (x - 1)
file.Write(bigarray(columns, linesInFile) + ",")
Next
'write an if else so that at the written line, a comma is not written
'there is a small bug here. Please correct it.
Next
file.Close()
MsgBox("Finished writing to file!")
End Sub
End Class