VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Verify a given port. This is good if the user enters a port, and you want to verify it before conne

by DamageCase (3 Submissions)
Category: Internet/HTML
Compatability: Visual Basic 4.0 (32-bit)
Difficulty: Unknown Difficulty
Originally Published: Thu 28th October 1999
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Verify a given port. This is good if the user enters a port, and you want to verify it before connecting, cutting back on errors.

Rate Verify a given port. This is good if the user enters a port, and you want to verify it before conne



'Put this in a module, or change "Public" to 
'"Private" and put it in a form.

Trim(PortStr)

'If there's nothing in the box assume the
'user has cleared it and return no errors.
If Len(PortStr) = 0 Then
    VerifyPort = False
    Exit Function
End If

'Check to see if the string can be converted
'to an integer.
If IsNumeric(PortStr) = False Then
    MsgBox "Error: Integer values only.", vbInformation, "Error!"
    VerifyPort = False
    Exit Function
End If

'IsNumeric doesn't search for commas, so check
'if the user entered a comma.
For i = 1 To Len(PortStr)
    If InStr(i, PortStr, ",") Then
        MsgBox "Error: Integer values only.", vbInformation, "Error!"
        VerifyPort = False
        Exit Function
    End If
Next i

'If the port is or starts with a zero, return
'an error.
If Val(PortStr) = 0 Then
    MsgBox "Error: Ports 1 - 65535 Only.", vbInformation, "Error!"
    VerifyPort = False
    Exit Function
End If
If Left(PortStr, 1) = "0" Then
    MsgBox "Error: Ports 1 - 65535 Only.", vbInformation, "Error!"
    VerifyPort = False
    Exit Function
End If

'Check if the port exceeds the maximum range.
If Val(txtRemotePort.Text) > 65535 Then
    MsgBox "Error: Ports 1 - 65535 only.", vbInformation, "Error!"
    txtLocalPort.Text = "65535"
    VerifyPort = False
    Exit Function
End If

VerifyPort = True
End Function

Download this snippet    Add to My Saved Code

Verify a given port. This is good if the user enters a port, and you want to verify it before conne Comments

No comments have been posted about Verify a given port. This is good if the user enters a port, and you want to verify it before conne. Why not be the first to post a comment about Verify a given port. This is good if the user enters a port, and you want to verify it before conne.

Post your comment

Subject:
Message:
0/1000 characters