Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27404

VS 2010 Program Works But Wont Display/Calculate Data.. Trying To Add Arrays

$
0
0
Hi, okay im working on a program to calculate the avg, total, minimum and maximum rainfall. Ive Got everything working but cant seem to get the calculations right all im getting is 0 and min and max months as january. Ive tried a couple different ways but all give me the same output. Heres the Code, Thanks


Public Class Form1


'array for the months adn their names
Dim strMonths() As String = {"January", "February", "March", "April", _
"May", "June", "July", "August", "September", "October", "November", _
"December (aka The Best)"}

Dim intMonths(11) As Integer


Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

'calculate and display monthly rainfall

Dim intCounter As Integer 'Loop for the couter
Dim intRain As Integer 'the ammount of rain


ListBox1.Items.Add("Monthly Rainfall Input")
ListBox1.Items.Add("_______________________")



'getting the rain for each month
For intCounter = 0 To 11
intRain = CInt(Val(InputBox("Enter The Inches Of Rainfall For " & strMonths(intCounter))))
ListBox1.Items.Add((intRain).ToString() & " for " & strMonths(intCounter))
intRain = Val(intRain)

'Making sure there are no negatives nums or symbols
If intRain < 0 Then
MessageBox.Show("Please Enter A Positive Number For The Rainfall Amount ", "Text Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
Return

End If
Next intCounter


End Sub

Public Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


'Creating Variables for the program to calculate
Dim intCounter As Integer
Dim intMax As Integer = intMonths(0)
Dim intMin As Integer = intMonths(0)
Dim dblMonthlyavg As Double
Dim intTotal As Integer
Dim minIndex As Integer
Dim maxIndex As Integer

'calculate the maximum month and rainfall

For intCounter = 0 To (intMonths.Length - 1)
If intMonths(intCounter) > intMax Then
intMax = intMonths(intCounter)
maxIndex = intCounter
End If
Next intCounter

'calculate the minimum montha and rainfall
For intCounter = 0 To (strMonths.Length - 1)
If intMonths(intCounter) < intMin Then
intMin = intMonths(intCounter)
minIndex = intCounter
End If
Next intCounter

'calculate the total rainfall

Dim i As Integer = 0
For i = 0 To intMonths.Count - 1
intTotal = intTotal + intMonths(i)
i += 1
Next

'Calculate the rainfall
dblMonthlyavg = (intTotal / strMonths.Length)
TextBox1.Visible = True
TextBox2.Visible = True
TextBox3.Visible = True
TextBox4.Visible = True

'Puting the variables with the text boxes
TextBox1.Text = "The Total Annual Rainfall Was: " & intTotal
TextBox2.Text = "The Average Monthly Rainfall Was: " & dblMonthlyavg.ToString("r1")
TextBox3.Text = "The Minimum Monthly Rainfall Was: " & intMin & " (" & strMonths(minIndex) & ")"
TextBox4.Text = "The Maximum Monthly Rainfall Was: " & intMax & " (" & strMonths(maxIndex) & ")"

End Sub

Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged

End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

'Clearing the Text Box Lines
TextBox1.Text = "The Total Annual Rainfall Was: N/A"
TextBox2.Text = "The Average Monthly Rainfall Was: N/A"
TextBox3.Text = "The Minimum Monthly Rainfall Was: N/A"
TextBox4.Text = "The Maximum Monthly Rainfall Was: N/A"

End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click

'To Close The Program
Me.Close()
End Sub
End Class

Viewing all articles
Browse latest Browse all 27404

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>