Codes and Design
Codes and Design
pH_Box.Clear()
Temp_Box.Clear()
TDS_Box.Clear()
Ca2_Box.Clear()
CaCo_Box.Clear()
LSI_Box.Clear()
pHs_Box.Clear()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
If isInputValid() Then
pHs = getPHS(getA, getB, getC, getD)
LSI = getLSI(Val(pH_Box.Text), pHs)
pHs_Box.Text = pHs
LSI_Box.Text = LSI
ShowMsg(LSI)
Else
MsgBox("Warning : Only numbers are allowed!", MsgBoxStyle.Exclamation +
MsgBoxStyle.OkOnly, "Incorrect input")
End If
End Sub
Private Sub pH_Box_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles pH_Box.KeyPress
If e.KeyChar = Chr(13) Then
Temp_Box.Focus()
End If
End Sub
Private Sub Temp_Box_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles Temp_Box.KeyPress
If e.KeyChar = Chr(13) Then
TDS_Box.Focus()
End If
End Sub
Private Sub TDS_Box_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TDS_Box.KeyPress
If e.KeyChar = Chr(13) Then
Ca2_Box.Focus()
End If
End Sub
Private Sub Ca2_Box_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles Ca2_Box.KeyPress
If e.KeyChar = Chr(13) Then
CaCo_Box.Focus()
End If
End Sub
Private Sub CaCo_Box_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles CaCo_Box.KeyPress
If e.KeyChar = Chr(13) Then
Button1.PerformClick()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button3.Click
ClearPrevData()
End Sub
End Class
End Function
Public Sub ClearPrevData()
pH_Box.Clear()
Temp_Box.Clear()
TDS_Box.Clear()
Ca2_Box.Clear()
CaCo_Box.Clear()
RI_Box.Clear()
pHs_Box.Clear()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
If isInputValid() Then
pHs = getPHS(getA, getB, getC, getD)
LSI = getLSI(Val(pH_Box.Text), pHs)
RI = getRI(Val(pH_Box.Text), LSI)
pHs_Box.Text = pHs
RI_Box.Text = RI
ShowMsg(RI)
Else
MsgBox("Warning : Only numbers are allowed!", MsgBoxStyle.Exclamation +
MsgBoxStyle.OkOnly, "Incorrect input")
End If
End Sub
Private Sub pH_Box_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles pH_Box.KeyPress
If e.KeyChar = Chr(13) Then
Temp_Box.Focus()
End If
End Sub
Private Sub Temp_Box_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles Temp_Box.KeyPress
If e.KeyChar = Chr(13) Then
TDS_Box.Focus()
End If
End Sub
Private Sub TDS_Box_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TDS_Box.KeyPress
If e.KeyChar = Chr(13) Then
Ca2_Box.Focus()
End If
End Sub
Private Sub Ca2_Box_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles Ca2_Box.KeyPress
If e.KeyChar = Chr(13) Then
CaCo_Box.Focus()
End If
End Sub
Private Sub CaCo_Box_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles CaCo_Box.KeyPress
If e.KeyChar = Chr(13) Then
Button1.PerformClick()
End If
End Sub
Dim MolerMass() As Double = {23.0, 39.0, 40.0, 24.0, 131.0, 87.6, 35.5, 19.0, 61.0, 97.0}
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click
Me.Close()
End Sub
Public Sub ClearPrevData()
Box1.Clear()
Box1On1.Clear()
Box2.Clear()
Box2On2.Clear()
Box3.Clear()
Box3On3.Clear()
Box4.Clear()
Box4On4.Clear()
Box5.Clear()
Box5On5.Clear()
Box6.Clear()
Box6On6.Clear()
Box7.Clear()
Box7On7.Clear()
Box8.Clear()
Box8On8.Clear()
Box9.Clear()
Box9On9.Clear()
Box10.Clear()
Box10On10.Clear()
Box11.Clear()
Box12.Clear()
Box13.Clear()
Box14.Clear()
K_Box.Clear()
pHs_Box.Clear()
SDSI_Box.Clear()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button3.Click
ClearPrevData()
End Sub
Case 3
Box3On3.Text = Mol_per_L
Case 4
Box4On4.Text = Mol_per_L
Case 5
Box5On5.Text = Mol_per_L
Case 6
Box6On6.Text = Mol_per_L
Case 7
Box7On7.Text = Mol_per_L
Case 8
Box8On8.Text = Mol_per_L
Case 9
Box9On9.Text = Mol_per_L
Case 10
Box10On10.Text = Mol_per_L
Case Else
MsgBox("Error : Please check all input are correct")
End Select
End Sub
Private Function getTotalCZ2() As Double
Dim TotalCZ2 As Double = 0.0
TotalCZ2 += Val(Box1On1.Text) * Math.Pow(ionsChargeNumbers(0), 2)
TotalCZ2 += Val(Box2On2.Text) * Math.Pow(ionsChargeNumbers(1), 2)
TotalCZ2 += Val(Box3On3.Text) * Math.Pow(ionsChargeNumbers(2), 2)
TotalCZ2 += Val(Box4On4.Text) * Math.Pow(ionsChargeNumbers(3), 2)
TotalCZ2 += Val(Box5On5.Text) * Math.Pow(ionsChargeNumbers(4), 2)
TotalCZ2 += Val(Box6On6.Text) * Math.Pow(ionsChargeNumbers(5), 2)
TotalCZ2 += Val(Box7On7.Text) * Math.Pow(ionsChargeNumbers(6), 2)
TotalCZ2 += Val(Box8On8.Text) * Math.Pow(ionsChargeNumbers(7), 2)
TotalCZ2 += Val(Box9On9.Text) * Math.Pow(ionsChargeNumbers(8), 2)
TotalCZ2 += Val(Box10On10.Text) * Math.Pow(ionsChargeNumbers(9), 2)
Return TotalCZ2
End Function
Private Function getI() As Double
Return 0.5 * getTotalCZ2()
End Function
Private Function getK(ByVal I As Double) As Double
Dim K As Double = 0.0
If (I < 1.2) Then
K = 2.022 * Math.E * ((Math.Pow((Math.Log(I) + 7.544), 2)) / 102.6) - 0.0002 *
Math.Pow(Val(Box12.Text), 2) + 0.00097 * Val(Box12.Text) + 0.262
ElseIf I > 1.2 Then
K = (0.1 * I) - (0.0002 * Math.Pow(Val(Box12.Text), 2)) - (0.00097 * Val(Box12.Text)) +
3.887
End If
Return K
End Function
Private Function getpCa()
Return Math.Log(1 / Val(Box3On3.Text))
End Function
Private Function getPalk()
Return Math.Log(1 / Val(Box13.Text))
End Function
Private Function getSI()
Return Val(Box11.Text) - getpCa() - getPalk() - getK(getI)
End Function
Private Function getpHs()
Return getpCa() - getPalk()
End Function
Private Sub ShowMsg(ByVal SI As Double)
Dim Msg As String = ""
If SI >= 0.0 Then
Msg = "The water is SuperSaturated and scale is expected to precipitate"
ElseIf SI < 0.0 Then
Msg = "The scaling is Unlikely"
End If
MsgBox(Msg, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Results")
End Sub
Private Sub Box1_KeyUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Box1.KeyUp
Convert_To_Mol_per_L(Val(Box1.Text), 1)
End Sub
Private Sub Box2_KeyUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Box2.KeyUp
Convert_To_Mol_per_L(Val(Box2.Text), 2)
End Sub
Private Sub Box3_KeyUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Box3.KeyUp
Convert_To_Mol_per_L(Val(Box3.Text), 3)
End Sub
Private Sub Box4_KeyUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Box4.KeyUp
Convert_To_Mol_per_L(Val(Box4.Text), 4)
End Sub
Private Sub Box5_KeyUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Box5.KeyUp
Convert_To_Mol_per_L(Val(Box5.Text), 5)
End Sub
Private Sub Box6_KeyUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Box6.KeyUp
Convert_To_Mol_per_L(Val(Box6.Text), 6)
End Sub
Private Sub Box7_KeyUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Box7.KeyUp
Convert_To_Mol_per_L(Val(Box7.Text), 7)
End Sub
Private Sub Box8_KeyUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Box8.KeyUp
Convert_To_Mol_per_L(Val(Box8.Text), 8)
End Sub
Private Sub Box9_KeyUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Box9.KeyUp
Convert_To_Mol_per_L(Val(Box9.Text), 9)
End Sub
Private Sub Box10_KeyUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Box10.KeyUp
Convert_To_Mol_per_L(Val(Box10.Text), 10)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
If isInputValid() Then
Box14.Text = Math.Round(getI(), 5)
K_Box.Text = Math.Round(getK(getI), 5)
pHs_Box.Text = Math.Round(getpHs(), 5)
SDSI_Box.Text = Math.Round(getSI(), 5)
ShowMsg(getSI)
Else
MsgBox("Warning : Only numbers are allowed !please check your inputs")
End If
End Sub
Private Sub Box1_KeyPress(ByVal sender As System.Object, ByVal
System.Windows.Forms.KeyPressEventArgs) Handles Box1.KeyPress
If e.KeyChar = Chr(13) Then
Box2.Focus()
End If
End Sub
Private Sub Box2_KeyPress(ByVal sender As System.Object, ByVal
System.Windows.Forms.KeyPressEventArgs) Handles Box2.KeyPress
If e.KeyChar = Chr(13) Then
Box3.Focus()
End If
End Sub
Private Sub Box3_KeyPress(ByVal sender As System.Object, ByVal
System.Windows.Forms.KeyPressEventArgs) Handles Box3.KeyPress
If e.KeyChar = Chr(13) Then
Box4.Focus()
End If
End Sub
Private Sub Box4_KeyPress(ByVal sender As System.Object, ByVal
System.Windows.Forms.KeyPressEventArgs) Handles Box4.KeyPress
If e.KeyChar = Chr(13) Then
Box5.Focus()
End If
End Sub
Private Sub Box5_KeyPress(ByVal sender As System.Object, ByVal
System.Windows.Forms.KeyPressEventArgs) Handles Box5.KeyPress
If e.KeyChar = Chr(13) Then
Box6.Focus()
End If
End Sub
Private Sub Box6_KeyPress(ByVal sender As System.Object, ByVal
System.Windows.Forms.KeyPressEventArgs) Handles Box6.KeyPress
If e.KeyChar = Chr(13) Then
Box7.Focus()
End If
End Sub
e As
e As
e As
e As
e As
e As
Box9.Focus()
End If
End Sub
Private Sub Box9_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles Box9.KeyPress
If e.KeyChar = Chr(13) Then
Box10.Focus()
End If
End Sub
Private Sub Box10_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles Box10.KeyPress
If e.KeyChar = Chr(13) Then
Box11.Focus()
End If
End Sub
Private Sub Box11_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles Box11.KeyPress
If e.KeyChar = Chr(13) Then
Box12.Focus()
End If
End Sub
Private Sub Box12_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles Box12.KeyPress
If e.KeyChar = Chr(13) Then
Box13.Focus()
End If
End Sub
Private Sub Box13_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles Box13.KeyPress
If e.KeyChar = Chr(13) Then
Button1.PerformClick()
End If
End Sub
Private Function isInputValid() As Boolean
Dim validFlag As Boolean = True
If Not IsNumeric(Box1.Text) Then
Box1.Clear()
Box1.Focus()
validFlag = False
End If
If Not IsNumeric(Box2.Text) Then
Box2.Clear()
Box2.Focus()
validFlag = False
End If
End If
If Not IsNumeric(Box5.Text) Then
Box5.Clear()
Box5.Focus()
validFlag = False
End If
If Not IsNumeric(Box6.Text) Then
Box6.Clear()
Box6.Focus()
validFlag = False
End If
If Not IsNumeric(Box7.Text) Then
Box7.Clear()
Box7.Focus()
validFlag = False
End If
If Not IsNumeric(Box8.Text) Then
Box8.Clear()
Box8.Focus()
validFlag = False
End If
If Not IsNumeric(Box9.Text) Then
Box9.Clear()
Box9.Focus()
validFlag = False
End If
If Not IsNumeric(Box10.Text) Then
Box10.Clear()
Box10.Focus()
validFlag = False
End If
If Not IsNumeric(Box11.Text) Then
Box11.Clear()
Box11.Focus()
validFlag = False
End If
If Not IsNumeric(Box12.Text) Then
Box12.Clear()
Box12.Focus()
validFlag = False
End If
If Not IsNumeric(Box13.Text) Then
Box13.Clear()
Box13.Focus()
validFlag = False
End If
Return validFlag
End Function
End Class