Advertisement
Guest User

Untitled

a guest
Dec 21st, 2012
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class StockForm
  2.  
  3.  
  4.     Dim lowValue As Integer
  5.     Dim highValue As Integer
  6.     Dim openValue As Integer
  7.     Dim closeValue As Integer
  8.     Dim nofDataDay As Integer '# of days of data
  9.    Dim stockArray(30, 1) As Integer
  10.     Dim dateArray(30) As Date
  11.  
  12.  
  13.     Private Sub AddButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddButton.Click
  14.  
  15.         Dim isGoodData As Boolean = True
  16.         Dim possibleHigh, possibleLow, possibleOpen, possibleClose, possibleAverage As Integer
  17.  
  18.         Try
  19.             'test low value
  20.            possibleLow = Convert.ToInt32(LowBox.Text)
  21.         Catch ex As FormatException
  22.             isGoodData = False
  23.             MessageBox.Show("'" & LowBox.Text & "' is not a valid low value.")
  24.         Catch ex As Exception
  25.             isGoodData = False
  26.             MessageBox.Show(ex.Message)
  27.         End Try
  28.  
  29.  
  30.         Try
  31.             ' test the high value
  32.            possibleHigh = Convert.ToInt32(HighBox.Text)
  33.         Catch ex As FormatException
  34.             MessageBox.Show("'" & HighBox.Text & "' is not a valid high value.")
  35.         Catch ex As Exception
  36.             MessageBox.Show(ex.Message)
  37.         End Try
  38.  
  39.         Try
  40.             ' test the open value
  41.            possibleOpen = Convert.ToInt32(OpenBox.Text)
  42.         Catch ex As FormatException
  43.             MessageBox.Show("'" & OpenBox.Text & "' is not a valid open value.")
  44.         Catch ex As Exception
  45.             MessageBox.Show(ex.Message)
  46.         End Try
  47.  
  48.         Try
  49.             ' test the close value
  50.            possibleClose = Convert.ToInt32(CloseBox.Text)
  51.         Catch ex As FormatException
  52.             MessageBox.Show("'" & CloseBox.Text & "' is not valid close value.")
  53.         Catch ex As Exception
  54.             MessageBox.Show(ex.Message)
  55.         End Try
  56.  
  57.  
  58.  
  59.         'add the data to the arrays
  60.        If (isGoodData) Then
  61.             stockArray(nofDataDay, lowValue) = possibleLow
  62.             stockArray(nofDataDay, highValue) = possibleHigh
  63.             stockArray(nofDataDay, openValue) = possibleOpen
  64.             stockArray(nofDataDay, closeValue) = possibleClose
  65.             dateArray(nofDataDay) = Convert.ToDateTime(WeatherDateTimePicker.Text)
  66.             nofDataDay = nofDataDay + 1
  67.  
  68.  
  69.             'display data & clear boxes
  70.            DisplayData()
  71.             ClearData()
  72.         End If
  73.  
  74.     End Sub
  75.  
  76.     'display routine
  77.    Private Sub DisplayData()
  78.         Dim day As Integer
  79.         Dim delimiter As String = vbTab
  80.  
  81.         'clear the list box
  82.        StockListBox.Items.Clear()
  83.  
  84.         'add the header
  85.        StockLabel.Text = "    Date           " & delimiter & "    Open           " & delimiter & "Close     " & delimiter & "    High        " & delimiter & "  Low       " & delimiter & "  Average    "
  86.  
  87.         'add the data
  88.        For day = 0 To nofDataDay - 1
  89.             StockListBox.Items.Add(dateArray(day).ToShortDateString & _
  90.                 delimiter & stockArray(day, openValue).ToString & _
  91.                 delimiter & stockArray(day, closeValue).ToString & _
  92.                 delimiter & stockArray(day, highValue).ToString & _
  93.                 delimiter & stockArray(day, lowValue).ToString & _
  94.                 delimiter & AverageStock(stockArray(day, lowValue), stockArray(day, highValue)))
  95.  
  96.         Next
  97.  
  98.     End Sub
  99.  
  100.     Private Sub ClearData()
  101.         'clear the textboxes
  102.        OpenBox.Text = ""
  103.         CloseBox.Text = ""
  104.         HighBox.Text = ""
  105.         LowBox.Text = ""
  106.  
  107.         'set cursor
  108.        OpenBox.Focus()
  109.     End Sub
  110.  
  111.     Private Function AverageStock(ByVal lowStock As Integer, ByVal highStock As Integer) As Integer
  112.         Return (lowStock + highStock) \ 2
  113.     End Function
  114.  
  115.     Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
  116.         ClearData()
  117.     End Sub
  118. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement