I don' t understand why am getting an index out of range error on line: AssessmentRecord.ToList(RecordPosition).Exams = Val(txtscore.Text) - vb.net-2010

Code for Entering Continuous Assessments
Private Sub bnloadrecords_Click(sender As Object, e As EventArgs) Handles bnloadrecords.Click
If cboclass.Text = "" Or cbostream.Text = "" Or cbosubject.Text = "" Then
MsgBox("Please select a class, stream and subject to proceed!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
Exit Sub
End If
Dim db As New SMSDataContext
Dim AssessmentRecords = From p In db.Assessments
Where p.Class = cboclass.Text And p.Stream = cbostream.Text And p.Subject = cbosubject.Text
Select p
If AssessmentRecords.Count <> 0 Then
Me.AssessmentsTableAdapter.FillByClass(Me.SMS.Assessments, cboclass.Text, cbostream.Text, cbosubject.Text)
Else
Dim StudentRecords = From p In db.Students
Where p.Class = cboclass.Text And p.Stream = cbostream.Text
Select p
If StudentRecords.Count = 0 Then
MsgBox("No student' records in the system that match your criteria!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
Exit Sub
Else
For j = 1 To StudentRecords.Count
Dim NewAssessmentRecord As New Assessment With {.CA = 0, .Class = cboclass.Text, .Full_Name = StudentRecords.ToList(j - 1).Full_Name, .Registration_Number = StudentRecords.ToList(j - 1).Registration_Number, .Stream = cbostream.Text, .Subject = cbosubject.Text}
db.Assessments.InsertOnSubmit(NewAssessmentRecord)
db.SubmitChanges()
Next
Me.AssessmentsTableAdapter.FillByClass(Me.SMS.Assessments, cboclass.Text, cbostream.Text, cbosubject.Text)
lblcurrentStudent.Text = AssessmentRecords.FirstOrDefault.Full_Name
RecordPosition = 0
txtscore.Focus()
End If
End If
End Sub
Dim RecordPosition As Integer
Private Sub bnenter_Click(sender As Object, e As EventArgs) Handles bnenter.Click
If txtscore.Text = "" Then
MsgBox("Continous Assessment cannot be empty!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
Exit Sub
End If
If Not IsNumeric(txtscore.Text) Then
MsgBox("Score must be numeric!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
Exit Sub
End If
If Val(txtscore.Text) > 25 Then
MsgBox("CA Score cannot be above 25 marks!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
Exit Sub
End If
Dim db As New SMSDataContext
Dim AssessmentRecord = From p In db.Assessments
Where p.Class = cboclass.Text And p.Stream = cbostream.Text And p.Subject = cbosubject.Text
Select p
If RecordPosition < (AssessmentRecord.Count - 1) Then
MsgBox("End of Records Reached!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
Exit Sub
End If
AssessmentRecord.ToList(RecordPosition).CA = Val(txtscore.Text)
db.SubmitChanges()
RecordPosition += 1
If RecordPosition = (AssessmentRecord.Count - 1) Then
MsgBox("End of Record Reached!", MsgBoxStyle.Exclamation +MsgBoxStyle.OkOnly)
Exit Sub
End If
txtscore.Clear()
txtscore.Focus()
End Sub
Code for Entering Exams
Private Sub bnloadrecords_Click(sender As Object, e As EventArgs) Handles bnloadrecords.Click
If cboclass.Text = "" Or cbostream.Text = "" Or cbosubject.Text = "" Then
MsgBox("Please select a class, stream and subject to proceed!",MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
Exit Sub
End If
Dim db As New SMSDataContext
Dim AssessmentRecords = From p In db.Assessments
Where p.Class = cboclass.Text And p.Stream = cbostream.Text And p.Subject = cbosubject.Text
Select p
If AssessmentRecords.Count <> 0 Then Me.AssessmentsTableAdapter.FillByClass(Me.SMS.Assessments,cboclass.Text,cbostream.Text, cbosubject.Text)
Else
Dim StudentRecords = From p In db.Students
Where p.Class = cboclass.Text And p.Stream = cbostream.Text
Select p
If StudentRecords.Count = 0 Then
MsgBox("No student' records in the system that match your criteria!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
Exit Sub
Else
For j = 1 To StudentRecords.Count
Dim NewAssessmentRecord As New Assessment With {.Class = cboclass.Text, .Exams = 0, .Full_Name = StudentRecords.ToList(j - 1).Full_Name, .Registration_Number = StudentRecords.ToList(j - 1).Registration_Number, .Stream = cbostream.Text, .Subject = cbosubject.Text}
db.Assessments.InsertOnSubmit(NewAssessmentRecord)
db.SubmitChanges()
Next
Me.AssessmentsTableAdapter.FillByClass(Me.SMS.Assessments, cboclass.Text, cbostream.Text, cbosubject.Text)
lblcurrentStudent.Text = AssessmentRecords.FirstOrDefault.Full_Name
RecordPosition = 0
txtscore.Focus()
End If
End If
End Sub
Dim RecordPosition As Integer
Private Sub bnenter_Click(sender As Object, e As EventArgs) Handles bnenter.Click
If txtscore.Text = "" Then
MsgBox("Exams cannot be empty!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
Exit Sub
End If
If Not IsNumeric(txtscore.Text) Then
MsgBox("Score must be numeric!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
Exit Sub
End If
If Val(txtscore.Text) > 75 Then
MsgBox("Exams Score cannot be above 75 marks!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
Exit Sub
End If
Dim db As New SMSDataContext
Dim AssessmentRecord = From p In db.Assessments
Where p.Class = cboclass.Text And p.Stream = cbostream.Text And p.Subject = cbosubject.Text
Select p
If RecordPosition < (AssessmentRecord.Count - 1) Then
MsgBox("End of Records Reached!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
Exit Sub
End If
AssessmentRecord.ToList(RecordPosition).Exams = Val(txtscore.Text)
db.SubmitChanges()
RecordPosition += 1
If RecordPosition = (AssessmentRecord.Count - 1) Then
MsgBox("End of Record Reached!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
Exit Sub
End If
txtscore.Clear()
txtscore.Focus()
End Sub
Code for Computing both Continuous Assessments & Exams
Private Sub bncomputeresults_Click(sender As Object, e As EventArgs) Handles bncomputeresults.Click
If cboclass.Text = "" Or cbostream.Text = "" Then
MsgBox("Select a class and stream to proceed!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
Exit Sub
End If
Dim db As New SMSDataContext
Dim AssessmentRecords = From p In db.Assessments
Where p.Class = cboclass.Text And p.Stream = cbostream.Text
Select p
If AssessmentRecords.Count = 0 Then
MsgBox("No records found, Please select a new set of options to proceed!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
Exit Sub
End If
For j = 1 To AssessmentRecords.Count
AssessmentRecords.ToList(j - 1).Exams = Val(AssessmentRecords.ToList(j - 1).CA) + Val(AssessmentRecords.ToList(j - 1).Exams)
If Val(AssessmentRecords.ToList(j - 1).Exams) >= 80 Then
AssessmentRecords.ToList(j - 1).Grade = "1"
AssessmentRecords.ToList(j - 1).Remarks = "DISTINCTION"
ElseIf Val(AssessmentRecords.ToList(j - 1).Exams) >= 79 Then
AssessmentRecords.ToList(j - 1).Grade = "2"
AssessmentRecords.ToList(j - 1).Remarks = "MERIT"
ElseIf Val(AssessmentRecords.ToList(j - 1).Exams) >= 69 Then
AssessmentRecords.ToList(j - 1).Grade = "3"
AssessmentRecords.ToList(j - 1).Remarks = "CREDIT"
ElseIf Val(AssessmentRecords.ToList(j - 1).Exams) >= 59 Then
AssessmentRecords.ToList(j - 1).Grade = "4"
AssessmentRecords.ToList(j - 1).Remarks = "PASS"
Else
AssessmentRecords.ToList(j - 1).Grade = "F"
AssessmentRecords.ToList(j - 1).Remarks = "FAIL"
End If
Next
db.SubmitChanges()
Dim TotaledRecords = From p In db.Assessments
Where p.Class = cboclass.Text And p.Stream = cbostream.Text
Select p
Order By p.Total Descending
For j = 1 To TotaledRecords.Count
TotaledRecords.ToList(j - 1).Position = j
Next
db.SubmitChanges()
Me.AssessmentsTableAdapter.FillByClassStream(Me.SMS.Assessments, cboclass.Text, cbostream.Text)
End Sub

I suspect that his block was intended to guarding against RecordPosition being an invalid index, but it is doing the opposite.
If RecordPosition < (AssessmentRecord.Count - 1) Then
MsgBox("End of Records Reached!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
Exit Sub
End If
The first line should probably be using > instead of < so that it stops when RecordPosition goes past the end of the list.
If RecordPosition > (AssessmentRecord.Count - 1) Then

Related

Why won't the variable go up

So since I have put that a variable, even though it says that i=3, it doesn't go on with the questions and I really don't know what else to do, the i goes up but the questions don't..
I know I may be very bad at this but why untill 5 seconds ago it worked, now it doesn't.
Public Class Test1
Dim question(3, 5) As String
Dim i As Integer = 2
Dim correctanswear = 0
Dim a As Integer = 0
Private Sub Test1_Load()
question(1, 0) = "2+2="
question(1, 1) = "1"
question(1, 2) = "2"
question(1, 3) = "3"
question(1, 4) = "4"
question(2, 0) = "How old are you?"
question(2, 1) = "12"
question(2, 2) = "13"
question(2, 3) = "18"
question(2, 4) = "17"
question(3, 0) = "7+14="
question(3, 1) = "23"
question(3, 2) = "21"
question(3, 3) = "34"
question(3, 4) = "22"
Label1.Text = question(i - 1, 0)
nr1.Text = question(i - 1, 1)
nr2.Text = question(i - 1, 2)
nr3.Text = question(i - 1, 3)
nr4.Text = question(i - 1, 4)
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Test1_Load()
Button5.Hide()
Button2.Visible = "True"
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Hide()
MainMenu.Show()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If a > 3 Then
MessageBox.Show("You answered " + correctanswear.ToString() + " questions correctly.")
Else
If i = 2 AndAlso nr4.Checked = True Then
correctanswear += 1
MessageBox.Show("You answered " + correctanswear.ToString() + " questions correctly.")
i = i + 1
MessageBox.Show(i)
ElseIf i = 3 AndAlso nr3.Checked Then
correctanswear += 1
MessageBox.Show("You answered " + correctanswear.ToString() + " questions correctly.")
i = i + 1
MessageBox.Show(i)
End If
If i = 4 AndAlso nr2.Checked = True Then
MessageBox.Show(i)
correctanswear += 1
MessageBox.Show("You answered " + correctanswear.ToString() + " questions correctly.")
Button2.Hide()
Button5.Text = "Retake the test"
Button5.Show()
End If
End If
a = a + 1
End Sub
End Class
Whenever a user enters a correct answer you must call Test1_Load so that the question updates.
Example:
If i = 2 AndAlso nr4.Checked = True Then
correctanswear += 1
MessageBox.Show("You answered " + correctanswear.ToString() + " questions correctly.")
i = i + 1
MessageBox.Show(i)
Test1_Load()
ElseIf i = 3 AndAlso nr3.Checked Then
correctanswear += 1
MessageBox.Show("You answered " + correctanswear.ToString() + " questions correctly.")
i = i + 1
MessageBox.Show(i)
Test1_Load()
End If
On another note, it would probably be worth breaking the question updating code out into its own function (called by Test1_Load and when user gets a correct answer) so that you don't have to re-initialize the array of questions multiple times per test.

How to merge cells in datagridview with equal values and draw line in a cell

This is my dataGridview Result:
and what I expect:
I want to merge cells in first column that are equal. I'm using this code:
Private Sub DataGridView2_CellPainting(sender As Object, e As DataGridViewCellPaintingEventArgs) Handles DataGridView2.CellPainting
If e.RowIndex = 0 Then
If (DataGridView2.Rows(e.RowIndex).Cells(0).Value.ToString() = DataGridView2.Rows(e.RowIndex + 1).Cells(0).Value.ToString()) Then
If (e.ColumnIndex = 0) Then
DataGridView2.Rows(e.RowIndex + 1).Cells(0).Value = ""
e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None
End If
End If
End If
If e.RowIndex > 0 Then
If e.RowIndex < DataGridView2.Rows.Count - 2 Then
If (DataGridView2.Rows(e.RowIndex - 1).Cells(0).Value.ToString() = DataGridView2.Rows(e.RowIndex).Cells(0).Value.ToString()) Then
If (e.ColumnIndex = 0) Then
DataGridView2.Rows(e.RowIndex).Cells(0).Value = ""
e.AdvancedBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.None
End If
End If
If (DataGridView2.Rows(e.RowIndex).Cells(0).Value.ToString() = DataGridView2.Rows(e.RowIndex + 1).Cells(0).Value.ToString()) Then
If (e.ColumnIndex = 0) Then
DataGridView2.Rows(e.RowIndex + 1).Cells(0).Value = ""
e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None
End If
End If
End If
End If
End Sub
It works but when I select a row, becomes corrupted. Also I would like to separate my data for each group by a red line. In addition draw a diagonal in top cell and write the names.

How can i display the last of my code only if the checkbox is checked?

I fixed my syntax,
how can I get the total to show only if checkbox is checked?
Option Strict On
Option Explicit On
Public Class Form1
Private Player1 As String
Private Player2 As String
Private Player1Wins As Integer = 1
Private Player2Wins As Integer = 1
Private Tie As Integer = 1
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub frmMainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Player1 = InputBox("Enter Player 1's Name: ")
lblPlayer1.Text = (Player1 + "'s Score:")
Player2 = InputBox("Enter Player 2's Name:")
lblPlayer2.Text = (Player2 + "'s Score:")
End Sub
Private Sub btnRoll_Click(sender As Object, e As EventArgs) Handles btnRoll.Click
' game of rolling dice
Dim randGen As New Random
Dim intNum1 As Integer
Dim intNum2 As Integer
Dim intNum3 As Integer
Dim intNum4 As Integer
Dim intTotal As Integer
Dim intTotal2 As Integer
' make random integer from 1 through 6
intNum1 = randGen.Next(1, 7)
intNum2 = randGen.Next(1, 7)
intNum3 = randGen.Next(1, 7)
intNum4 = randGen.Next(1, 7)
' display the right image in picDie1
Select Case intNum1
Case 1
picDie1.Image = picOneDot.Image
Case 2
picDie1.Image = picTwoDots.Image
Case 3
picDie1.Image = picThreeDots.Image
Case 4
picDie1.Image = picFourDots.Image
Case 5
picDie1.Image = picFiveDots.Image
Case 6
picDie1.Image = picSixDots.Image
End Select
' display the right image in picDie2
Select Case intNum2
Case 1
picDie2.Image = picOneDot.Image
Case 2
picDie2.Image = picTwoDots.Image
Case 3
picDie2.Image = picThreeDots.Image
Case 4
picDie2.Image = picFourDots.Image
Case 5
picDie2.Image = picFiveDots.Image
Case 6
picDie2.Image = picSixDots.Image
End Select
' display the right image in picDie3
Select Case intNum3
Case 1
picDie3.Image = picOneDot.Image
Case 2
picDie3.Image = picTwoDots.Image
Case 3
picDie3.Image = picThreeDots.Image
Case 4
picDie3.Image = picFourDots.Image
Case 5
picDie3.Image = picFiveDots.Image
Case 6
picDie3.Image = picSixDots.Image
End Select
' display the right image in picDie4
Select Case intNum4
Case 1
picDie4.Image = picOneDot.Image
Case 2
picDie4.Image = picTwoDots.Image
Case 3
picDie4.Image = picThreeDots.Image
Case 4
picDie4.Image = picFourDots.Image
Case 5
picDie4.Image = picFiveDots.Image
Case 6
picDie4.Image = picSixDots.Image
End Select
' calculate and display total number of dots
intTotal = intNum1 + intNum2
lblTotal.Text = intTotal.ToString()
intTotal2 = intNum3 + intNum4
lblTotal2.Text = intTotal2.ToString()
If intTotal > intTotal2 Then
MessageBox.Show("Player1 Wins")
lblWins.Text = CStr(Player1Wins)
Player1Wins = Player1Wins + 1
End If
If intTotal2 > intTotal Then
MessageBox.Show("Player2Wins")
lblWins2.Text = CStr(Player2Wins)
Player2Wins = Player2Wins + 1
End If
If intTotal = intTotal2 Then
MessageBox.Show("Tie")
lblTies.Text = CStr(Tie)
Tie = Tie + 1
End If
End Sub
End Class
Not sure how you're trying to display the results whether that's a message box or a label but here's how I would do it:
Using a Label/Text Box: Keep it calculating and displaying the total and then put this code on the Changed event of the check box.
If CheckBox1.Checked = True Then
lblTotal.Visible = True
Else
lblTotal.Visible = False
If using a message box you would do the same but use MessageBox.Show("Total is: " & MyTotalVariable)

Read, Get, Compare and Count Rows from GridView VB.net?

i have a little problem and actually i can't get out from his.. I have a column called 'Periodicidade' that gives me how many times must a thing get done.
What i want to do is a validation that it will count how many times exists one of them, and if one of them have the radiobutton fill, it will force the user to fill the others of the same type of periocidade, but in the moment he is counting the total gridview rows, and not the type of same periodicidade. My current code is:
Dim todos_items_periocidade_vazios As Boolean = True
Dim todos_items_periocidade_preenchidos As Boolean = False
Dim periocidade_validada As Boolean = False
'quantas linhas tem a grid
Dim n_linha_grid As Integer = GridView_Manutencao.Rows.Count
Dim periocidade_linha As String
Dim contador_preenchido As Integer = 0
Dim contador_linhas As Integer = 0
'para cada linha verificar
For Each row2 As GridViewRow In GridView_Manutencao.Rows
'percorrer tabela e validar a periocidade da linha encontrada
periocidade_linha = (CType(row2.FindControl("Label_Periodicidade"), Label).Text)
For Each row As GridViewRow In GridView_Manutencao.Rows
If ((CType(row.FindControl("Label_Periodicidade"), Label).Text) = periocidade_linha) Then
contador_linhas = contador_linhas + 1
periocidade_validada = True
If periocidade_validada = True Then
'testar se está vazio ou preenchido
If (CType(row.FindControl("RBList"), RadioButtonList).SelectedValue = "") Then
'percorrer a tabela e verificar se todos os itens estão vazios ou não
For Each row1 As GridViewRow In GridView_Manutencao.Rows
If ((CType(row1.FindControl("Label_Periodicidade"), Label).Text) = periocidade_linha) Then
If (CType(row1.FindControl("RBList"), RadioButtonList).SelectedValue = "") Then
todos_items_periocidade_vazios = True
Else
todos_items_periocidade_vazios = False
End If
End If
Next
Else
For Each row1 As GridViewRow In GridView_Manutencao.Rows
If ((CType(row1.FindControl("Label_Periodicidade"), Label).Text) = periocidade_linha) Then
If (CType(row1.FindControl("RBList"), RadioButtonList).SelectedValue <> "") Then
contador_preenchido = contador_preenchido + 1
todos_items_periocidade_preenchidos = True
Else
todos_items_periocidade_preenchidos = False
End If
End If
Next
End If
End If
End If
Next
valida_comentario()
If contador_preenchido = 0 Then
periocidade_validada = False
tudo_validado = False
ElseIf contador_preenchido < contador_linhas Then
periocidade_validada = False
tudo_validado = False
Else
If valida_comentario() = True Then
If ((todos_items_periocidade_vazios = True) And (todos_items_periocidade_preenchidos = True)) Then
periocidade_validada = True
tudo_validado = True
Lbl_Mensagem.Text = "Registo inserido com sucesso!"
ElseIf ((todos_items_periocidade_vazios = False) And (todos_items_periocidade_preenchidos = True)) Then
periocidade_validada = True
tudo_validado = True
Lbl_Mensagem.Text = "Registo inserido com sucesso!"
Else
periocidade_validada = False
tudo_validado = False
Lbl_Mensagem.Text = "Erro"
End If
Else
tudo_validado = False
periocidade_validada = False
Lbl_Mensagem.Text = "Erro"
End If
End If
Next
Return periocidade_validada
I got the answer, hope to be useful to all of you, thanks, here it goes:
Dim texto_periodicidade As String
Dim valor As String
Dim flag_validacao As Boolean = False
Dim contador_falso As Integer
contador_falso = 0
For Each linha As GridViewRow In GridView_Manutencao.Rows
texto_periodicidade = CType(linha.FindControl("Label_Periodicidade"), Label).Text
valor = CType(linha.FindControl("RBList"), RadioButtonList).SelectedValue
For Each row As GridViewRow In GridView_Manutencao.Rows
If (texto_periodicidade = CType(row.FindControl("Label_Periodicidade"), Label).Text) Then
If (valor = CType(row.FindControl("RBList"), RadioButtonList).SelectedValue) Then
flag_validacao = True
Else
contador_falso = contador_falso + 1
flag_validacao = False
End If
End If
Next row
Next linha
If contador_falso > 0 Then
Lbl_Mensagem.Text = "Complete os restantes valores da periocidade!"
contador_falso = 0
Return False
Else
If valida_comentario() = True Then
contador_falso = 0
Return True
End If
End If

How to check whether value of a given field is mon negative (greater than zero) in vb.net

The Condition ( less than zero ) is not working in the below code :
Protected Sub txt_business_revenue_risk_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txt_business_revenue_risk.TextChanged
Dim a As double= 0.0
If IsNumeric(Me.txt_business_revenue_risk.Text) Then
Me.lbl_business_revenue_risk.Text = ""
Me.lbl_rest_risk.Text = CDbl(Me.txt_business_revenue_risk.Text) - CDbl(Me.txt_mitigated_risk.Text)
If CDbl(Me.txt_business_revenue_risk.Text) < CDbl(a) Then
Me.lbl_business_revenue_risk.Text = "Must be a number greater than zero!"
txt_business_revenue_risk.Text = ""
End If
If CDbl(Me.txt_business_revenue_risk.Text) < CDbl(Me.txt_mitigated_risk.Text) Then
Me.lbl_rest_risk.Text = 0
Else
Me.lbl_rest_risk.Text = CDbl(Me.txt_business_revenue_risk.Text) - CDbl(Me.txt_mitigated_risk.Text)
End If
Else
Me.lbl_business_revenue_risk.Text = "Must be a number!"
txt_business_revenue_risk.Text = ""
End If
End Sub
Avoid the usage of VB6 methods such as IsNumeric, and those lot of Double-parsings, try this:
Private Sub txt_business_revenue_risk_TextChanged(sender As Object, e As EventArgs) _
Handles txt_business_revenue_risk.TextChanged
Dim Zero As Double = 0.0
Dim Num1 As Double, Num2 As Double
If Double.TryParse(CStr(sender.text), Num1) _
AndAlso Double.TryParse(CStr(txt_mitigated_risk.Text), Num2) Then
Me.lbl_business_revenue_risk.Text = String.Empty
Me.lbl_rest_risk.Text = CStr(Num1 - Num2)
Select Case Num1
Case Is < Zero
Me.lbl_business_revenue_risk.Text = "Must be a number greater than zero!"
sender.Text = String.Empty
Case Is < Num2
Me.lbl_rest_risk.Text = CStr(Zero)
Case Else
Me.lbl_rest_risk.Text = CStr(Num1 - Num2)
End Select
Else
Me.lbl_business_revenue_risk.Text = "Must be a number!"
txt_business_revenue_risk.Text = String.Empty
End If
End Sub
Try this -- Don't forget to add exception handling
Dim resMsg As String = ""
Dim txtRevRisk As String = Me.txt_business_revenue_risk.Text
Dim txtMitRisk As String = Me.txt_mitigated_risk.Text
Dim dRes As Double = 0
Dim a As Double = 0.0
If IsNumeric(txtRevRisk) AndAlso IsNumeric(txtMitRisk) Then
Dim dRevRisk = CDbl(txtRevRisk)
Dim dMitRisk = CDbl(txtMitRisk)
resMsg = txtRevRisk
dRes = dRevRisk - dMitRisk
If dRevRisk < a Then
resMsg = "Must be a number greater than zero!"
txtRevRisk = ""
End If
If dRevRisk < dMitRisk Then
dRes = 0
'Else
' Me.lbl_rest_risk.Text = dRevRisk - dMitRisk
End If
Else
resMsg = "Must be a number!"
txtRevRisk = ""
End If
Me.lbl_rest_risk.Text = dRes.ToString()
Me.lbl_business_revenue_risk.Text = resMsg.ToString()
Me.txt_business_revenue_risk.Text = txtRevRisk.ToString()