Trying to get this to work , any help would be appreciated.
Want to enter IP Address into Masked Edit Control, check if entry is valid (0-255) and jump to the next section of the mask using the dot (.) as separator, if the section is shorter than 3 digits (such as : 192.168.24.1).
Private Sub MaskedTextBox1_MaskInputRejected(sender As System.Object, e As System.Windows.Forms.MaskInputRejectedEventArgs) Handles MaskedTextBox1.MaskInputRejected
Dim myIPValue As String
End Sub
Private Sub Form_Load()
MaskedTextBox1.Mask = "###.###.###.###"
MaskedTextBox1.PromptChar = Chr(32) 'space character
End Sub
Private Sub MaskEdBox1_KeyPress(KeyAscii As Integer)
Dim mySplit() As String, c As Integer, jumpC As Integer, tmpString As String, tmpSplit As String
If KeyAscii = 46 Then
mySplit = Split(MaskedTextBox1.Text, Chr(46), -1)
For c = 0 To UBound(mySplit)
If IsNumeric(mySplit(c)) Then jumpC = jumpC + 4
If Len(Trim(mySplit(c))) < 3 Then mySplit(c) = Space(3 - Len(Trim(mySplit(c)))) & Trim(mySplit(c))
Next (c)
tmpString = mySplit(0) & "." & mySplit(1) & "." & mySplit(2) & "." & mySplit(3)
MaskedTextBox1.Text = tmpString
MaskedTextBox1.SelStart = jumpC
KeyAscii = 0
End If
End Sub
Private Sub MaskEdBox1_KeyUp(KeyCode As Integer, Shift As Integer)
Dim validSplit() As String, v As Integer, validString As String
validSplit = Split(MaskedTextBox1.Text, Chr(46), -1)
For v = 1 To UBound(validSplit)
If validSplit(v) = "" Or v = UBound(validSplit) Then
If Val(Trim(validSplit(v - 1))) > 255 Or (v = UBound(validSplit) And Val(Trim(validSplit(v))) > 255) Then
MsgBox("Invalid value")
If Val(validSplit(3)) > 0 Then v = v + 1
validSplit(v - 1) = ""
validString = validSplit(0) & "." & validSplit(1) & "." & validSplit(2) & "." & validSplit(3)
MaskedTextBox1.Text = validString
MaskedTextBox1.SelStart = (v - 1) * 4
Exit For
End If
End If
Next (v)
myIPValue = Replace(MaskedTextBox1.Text, " ", "")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles ChangeIPButton.Click
EthernetIPforPLCSLCMicroCom1.IPAddress = MaskedTextBox1.Text
End Sub