format.string question how to?
Hello everyone
I am trying to figure out how to use the format.string() function
This is what I have. I have 3 data string inputs of the format as folllows:
pcname bigservername (maybe 20 character max)
ip address ###.###.###.### (ex: 192.168.1.10)
macid ##-##-##-##-##-## hex values for # (ex: 00-23-AF-33-BC-CE)
also the character in above can very on the Macid and the ip address
no filler zeros are used it could only be 1 digit and not 3 (###) or
it could be 3 digits ### patter but a max of 3 and min of 1 in the ip address?
I am trying to run a If Then Else statment using this format.string()
so I can filter the type of search string inputted so depending on the
type of format used in the search string, the data selects a cert display code.
I just need to figure out how to use the fomat.string() for an input box
that takes a string value. so maybe I should have the ip address be a number? and the hex a number and the pc name a string with 20 characters max? I was thinking this but I do not know how nor can I find anything on how to set up say this: (my pseudo code)
Code:
If format.string({"###.###.###.###", txt_searchbox.text) then
goto displayIPAddress()
End If
If format.string({"##-##-##-##-##-##"}, txt_searchbox.text) then
goto displayMacID()
End If
If format.string("cccccccccccccccccccc", txt_searchbox.text) then
goto displayPCname()
End If
I know this is crued but I just dont know how to make the input format string work in vb.net and to find what I need on the NET is daunting..
Can you point me in the right direction..
thanks. All I need is to understand how to do the above code but real code
not my crap above..thank you for your help..:wave:
-itdaddy
Re: format.string question how to?
I would use Regular Expressions to handle this.
Here's an example where I'm checking for an IP Address. (Find a better pattern 999.999.999.999 validates with this one).
Code:
Imports System.Text.RegularExpressions
Public Class Input
Public Enum InputTypes
Invalid = -1
IPAddress
MACAddress
PCName
End Enum
Private Shared InputPatterns As New List(Of String) _
(New String() { _
"\b(?:\d{1,3}\.){3}\d{1,3}\b", _
"MAC Address Pattern", _
"PC Name Pattern"})
Private Shared _inputString As String
Public Shared Function GetInputType(ByVal inputString As String)
Dim InputType As InputTypes = InputTypes.Invalid
_inputString = inputString
InputType = CType(InputPatterns.FindIndex(AddressOf FindPattern), InputTypes)
_inputString = ""
Return InputType
End Function
Private Shared Function FindPattern(ByVal value As String) As Boolean
Return Regex.IsMatch(_inputString, value)
End Function
End Class
Example of calling it.
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim theInputString As String = "192.168.1.10"
Dim InputType As Input.InputTypes = _
Input.GetInputType(theInputString)
Select Case InputType
Case Input.InputTypes.Invalid
MessageBox.Show("Invalid Entry")
Case Input.InputTypes.IPAddress
MessageBox.Show("Valid IP Address")
Case Input.InputTypes.MACAddress
MessageBox.Show("Valid MAC Address")
Case Input.InputTypes.PCName
MessageBox.Show("Valid PC Name")
End Select
End Sub
End Class
Re: format.string question how to?
hey mattp thanks so much
will try it and let you know what I come up with..thanks so much for your guidance..
;)
Re: format.string question how to?
mattp
hey bud I can basically use your class right? and then incorporate it into my calling it code right?
I mean your code looks complete except for the string pattern for mac and pcname right? I just have to
make the reg expression for macid and pcname right and then I could use your class instantiated into my form1 right?
Re: format.string question how to?
I have no problem with you using the code.
You're correct that you'll just need to add the regular expression for each pattern you want to check against. As I said you'll probably want to devise a better expression for the IP Address than the one I provided as it will return valid for impossible IP Addresses.
Re: format.string question how to?
thanks MattP yeah I was reading that it will allow 999.999.999.999
but your structure sure helps..thanks so much for the insight
Re: format.string question how to?
Some better expression patterns to use.
Code:
Private Shared InputPatterns As New List(Of String) _
(New String() { _
"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", _
"^([0-9a-fA-F][0-9a-fA-F](:|-)){5}([0-9a-fA-F][0-9a-fA-F])$", _
"^[0-9a-zA-Z]{1,20}$"})
Re: format.string question how to?
hey mattp
you just made up the patterns. I see how wow thanks did you use the regex prgram to do that?
and is it a good program? the unix one for windows?
thanks
Re: format.string question how to?
HEY MATTp
my ide visual studio 2008 express doesnt like the function getinputtype()
for some reason? do know why? thanks it underlines it in blue sguiggly?
saying it needs and As clause? huh?
Code:
Public Shared Function GetInputType(ByVal inputString As String)
Dim InputType As InputTypes = InputTypes.Invalid
_inputString = inputString
InputType = CType(InputPatterns.FindIndex(AddressOf FindPattern), InputTypes)
_inputString = ""
Return InputType
End Function
Re: format.string question how to?
Code:
Public Shared Function GetInputType(ByVal inputString As String) As InputTypes
Well, it's because I'm lazy and didn't have Option Strict on. Visual Studio with this option on it doesn't like implicitly converting Object to InputTypes.
Re: format.string question how to?
MATTP
what is your background can I ask and who did you get so good at vb.net?
what other languages do you do? and can you point me to some great programming refernces to get as good as you sort of as good as you
probably wont happen in this lifetime but can you point me to some good references you used maybe? thanks