- Jan 3, 2006
- 8,436
- 1,037
- 136
I need a little help validating that the value entered into a textbox by a user is an integer. I've highlighted the area in red. Any help would be greatly appreciated!
Code:
Public Class Form1
Private Sub btnInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInfo.Click
'declare arrays
Dim strMonth() As String = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
Dim decRain() As Decimal
Try
lstInput.Items.Add("Monthly Rainfall:")
lstInput.Items.Add(" ")
'get rainfall amounts
decRain = GetRain(strMonth)
'display the gather months and rainfall
DisplayValues(strMonth, decRain)
'display total
TotalRainfall(decRain)
'display average
AverageRainfall(decRain)
'display highest rainfall
HighRain(decRain, strMonth)
'display lowest rainfall
LowRain(decRain, strMonth)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
'clear the form
ClearValues()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
'close it all out
Me.Close()
End Sub
[COLOR="Red"]Private Function GetRain(ByVal strMonths() As String) As Decimal()
'declare array/variables
Dim decRain(strMonths.Length - 1) As Decimal
Dim intIndex As Integer
'get amount of rain
For intIndex = 0 To decRain.Length - 1
decRain(intIndex) = CDec(InputBox("Please input rainfall for " & strMonths(intIndex), "Input rainfall"))
Next
'return rainfall values
Return decRain
End Function[/COLOR]
Private Sub DisplayValues(ByVal strMonths() As String, ByVal decRain() As Decimal)
'declare variables
Dim intIndex As Integer
'display month with specified rainfall in the listbox
For intIndex = 0 To strMonths.Length - 1
lstInput.Items.Add(strMonths(intIndex) & " has a total rainfall of: " & (decRain(intIndex).ToString) & " inches.")
Next
End Sub
Private Sub TotalRainfall(ByVal decRain() As Decimal)
'declare variables
Dim decTotal As Decimal
'calculate the total
decTotal = decRain.Sum
'display total
lblTotal.Text = CStr(decTotal) & " inches."
End Sub
Private Sub AverageRainfall(ByVal decRain() As Decimal)
'declare variables
Dim decAverage As Decimal
'calculate average
decAverage = decRain.Average
'display average
lblAverage.Text = decAverage.ToString("n") & " inches."
End Sub
Private Sub HighRain(ByVal decRain() As Decimal, ByVal strMonth() As String)
'declare variables
Dim decHighestRainfall As Decimal
Dim strMonthNames As String
'calulate highest rainfall
decHighestRainfall = decRain.Max
'Find month with highest rainfall
strMonthNames = String.Empty
'Display salesperson with the largest sales value
For intIndex As Integer = 0 To decRain.Length - 1
'Find the largest sales values
If decRain(intIndex) = decHighestRainfall Then
strMonthNames = strMonthNames & " " & strMonth(intIndex)
End If
Next
'Display month with highest rainfall
lblHigh.Text = strMonthNames & ", with " & decHighestRainfall.ToString & " inches of rainfall."
End Sub
Private Sub LowRain(ByVal decRain() As Decimal, ByVal strMonth() As String)
'declare variables
Dim decLowestRainfall As Decimal
Dim strMonthNames As String
'calulate highest rainfall
decLowestRainfall = decRain.Min
'Find month with highest rainfall
strMonthNames = String.Empty
'Display salesperson with the largest sales value
For intIndex As Integer = 0 To decRain.Length - 1
'Find the largest sales values
If decRain(intIndex) = decLowestRainfall Then
strMonthNames = strMonthNames & " " & strMonth(intIndex)
End If
Next
'Display month with highest rainfall
lblLow.Text = strMonthNames & ", with " & decLowestRainfall.ToString & " inches of rainfall."
End Sub
Private Sub ClearValues()
'clear all data from the form
lstInput.Items.Clear()
lblAverage.Text = ""
lblHigh.Text = ""
lblLow.Text = ""
lblTotal.Text = ""
End Sub
End Class
Last edited:
