The first problem is I have written a program that will allow users to enter any number of rainfall amounts. I need it to calculate and display the total rainfall amount and the average rainfall amount. I have to break it down into 2 seperate functions.
This is what I have so far:
Option Explicit On
Option Strict On
Public Class MainForm
Private Function CalcAverage(ByRef raincounter As Integer, ByRef rainAccum As Integer, ByVal avgRain As Integer)
' Calculates average rainfall amount
avgRain = (rainAccum + raincounter) / 2
Return avgRain
Call CalcAverage(rainAccum, raincounter)
End Function
Private Function CalcTotal(ByVal rainCounter As Decimal, ByVal rainAccum As Decimal) As Decimal
' calculates the total
rainAccum = rainCounter + rainAccum
Return rainAccum
Call CalcTotal(rainCounter, rainAccum)
End Function
Private Sub xExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xExitButton.Click
Me.Close()
End Sub
Private Sub xMonthlyTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles xMonthlyTextBox.KeyPress
' accept numbers, the period, and the Backspace
If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
AndAlso e.KeyChar <> "." AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub xMonthlyTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles xMonthlyTextBox.TextChanged
Me.xTotalLabel.Text = String.Empty
Me.xAverageLabel.Text = String.Empty
End Sub
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub xCalcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xCalcButton.Click
Dim rainAccum As Decimal
Dim avgRain As Decimal
Me.xTotalLabel.Text = rainAccum.ToString("n2")
Me.xAverageLabel.Text = avgRain.ToString("n2")
End Sub
End Class
The next one I have to write a program that will allow users to enter in a 5 digit number with the 5th digit being the check digit. What needs to happen is the user enters in the 5 digit code...every other number is multiplied by 2...then add the numbers together, take the last digit and add it to the end of the first number set to check if it is the correct number...then I need it to display if it is correct or incorrect.
I know it sounds confusing..here is an example
Original number: 1357
multiply every other number by 2: 1 3 5 7
*2 *2
Results: 1 6 5 14
Add the numbers together: 1+6+5+14 = 26
new number: 13576
six would be my check digit.
Here is what I have so far:
Option Explicit On
Option Strict On
Public Class MainForm
Private Sub xExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xExitButton.Click
Me.Close()
End Sub
Private Sub xNumberTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles xNumberTextBox.Enter
Me.xNumberTextBox.SelectAll()
End Sub
Private Sub xNumberTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles xNumberTextBox.KeyPress
If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub xNumberTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles xNumberTextBox.TextChanged
Me.xMessageLabel.Text = String.Empty
End Sub
End Class





Reply With Quote