Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class StockForm
- Dim lowValue As Integer
- Dim highValue As Integer
- Dim openValue As Integer
- Dim closeValue As Integer
- Dim nofDataDay As Integer '# of days of data
- Dim stockArray(30, 1) As Integer
- Dim dateArray(30) As Date
- Private Sub AddButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddButton.Click
- Dim isGoodData As Boolean = True
- Dim possibleHigh, possibleLow, possibleOpen, possibleClose, possibleAverage As Integer
- Try
- 'test low value
- possibleLow = Convert.ToInt32(LowBox.Text)
- Catch ex As FormatException
- isGoodData = False
- MessageBox.Show("'" & LowBox.Text & "' is not a valid low value.")
- Catch ex As Exception
- isGoodData = False
- MessageBox.Show(ex.Message)
- End Try
- Try
- ' test the high value
- possibleHigh = Convert.ToInt32(HighBox.Text)
- Catch ex As FormatException
- MessageBox.Show("'" & HighBox.Text & "' is not a valid high value.")
- Catch ex As Exception
- MessageBox.Show(ex.Message)
- End Try
- Try
- ' test the open value
- possibleOpen = Convert.ToInt32(OpenBox.Text)
- Catch ex As FormatException
- MessageBox.Show("'" & OpenBox.Text & "' is not a valid open value.")
- Catch ex As Exception
- MessageBox.Show(ex.Message)
- End Try
- Try
- ' test the close value
- possibleClose = Convert.ToInt32(CloseBox.Text)
- Catch ex As FormatException
- MessageBox.Show("'" & CloseBox.Text & "' is not valid close value.")
- Catch ex As Exception
- MessageBox.Show(ex.Message)
- End Try
- 'add the data to the arrays
- If (isGoodData) Then
- stockArray(nofDataDay, lowValue) = possibleLow
- stockArray(nofDataDay, highValue) = possibleHigh
- stockArray(nofDataDay, openValue) = possibleOpen
- stockArray(nofDataDay, closeValue) = possibleClose
- dateArray(nofDataDay) = Convert.ToDateTime(WeatherDateTimePicker.Text)
- nofDataDay = nofDataDay + 1
- 'display data & clear boxes
- DisplayData()
- ClearData()
- End If
- End Sub
- 'display routine
- Private Sub DisplayData()
- Dim day As Integer
- Dim delimiter As String = vbTab
- 'clear the list box
- StockListBox.Items.Clear()
- 'add the header
- StockLabel.Text = " Date " & delimiter & " Open " & delimiter & "Close " & delimiter & " High " & delimiter & " Low " & delimiter & " Average "
- 'add the data
- For day = 0 To nofDataDay - 1
- StockListBox.Items.Add(dateArray(day).ToShortDateString & _
- delimiter & stockArray(day, openValue).ToString & _
- delimiter & stockArray(day, closeValue).ToString & _
- delimiter & stockArray(day, highValue).ToString & _
- delimiter & stockArray(day, lowValue).ToString & _
- delimiter & AverageStock(stockArray(day, lowValue), stockArray(day, highValue)))
- Next
- End Sub
- Private Sub ClearData()
- 'clear the textboxes
- OpenBox.Text = ""
- CloseBox.Text = ""
- HighBox.Text = ""
- LowBox.Text = ""
- 'set cursor
- OpenBox.Focus()
- End Sub
- Private Function AverageStock(ByVal lowStock As Integer, ByVal highStock As Integer) As Integer
- Return (lowStock + highStock) \ 2
- End Function
- Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
- ClearData()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement