[RESOLVED] need help checking string is formatted correctly as mac address
hey guys
i have a listbox that imports a text file full of mac address's like so
00:00:00:00:00:00
ff:ff:ff:00:ff:ff
the issue is when someone imports the list like this
000000000000 blah blah
ffffffffffff blah blah
ff:ff:ff:ff:ff:ff blah blah
id there an easy way to recognise this issue and rectify it whilst loading each line into the textbox :)
Re: need help checking string is formatted correctly as mac address
Quote:
Originally Posted by
gerble1000
id there an easy way to recognise this issue and rectify it whilst loading each line into the textbox :)
Yes. You'll probably like the Like operator:
Code:
Const MAC_ADDR_FORMAT = "[0-9A-F][0-9A-F]:" & _
"[0-9A-F][0-9A-F]:" & _
"[0-9A-F][0-9A-F]:" & _
"[0-9A-F][0-9A-F]:" & _
"[0-9A-F][0-9A-F]:" & _
"[0-9A-F][0-9A-F]"
If UCase$("01:23:45:67:89:AB") Like MAC_ADDR_FORMAT Then
'Input string matched MAC address format
Else
'Input string didn't matched MAC address format
End If
Re: need help checking string is formatted correctly as mac address
im liking this method but i cannot get it to work
here i my code
Const MAC_ADDR_FORMAT = "[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]"
open filename for input as #1
do while not eof(1)
line input #1, variable8
variable8 = left(variable8, 17)
if (variable8) like MAC_ADDR_FORMAT then
list2.additem variable8
else
msgbox(variable8 & " is the incorrect format")
exit do
end if
loop
close#1
i taken the UCase out as it does not matter about it being upper or lower case.
can you see where i have gone wrong
i just get the msgbox popup with the correct mac address format
also the mac address's i am using is all uppercase
Re: need help checking string is formatted correctly as mac address
Can you post a sample of the text file? The UCase$ function may be left out if you can be absolutely sure that the MAC addresses will always be uppercase.
Re: need help checking string is formatted correctly as mac address
Quote:
Originally Posted by
Bonnie West
Can you post a sample of the text file? The UCase$ function may be left out if you can be absolutely sure that the MAC addresses will always be uppercase.
sure
00:11:E6:99:41:A7 01/05/2013
00:44:FE:FE:A1:22 02/03/2013
pretty much like that
the list may also have lowercase but i would allow lowercase to go through so does that mean i have to change the MAC_ADDR_FORMAT to [0-9a-fA-F]
Re: need help checking string is formatted correctly as mac address
Quote:
Originally Posted by
gerble1000
sure
00:11:E6:99:41:A7 01/05/2013
00:44:FE:FE:A1:22 02/03/2013
pretty much like that
Your code and sample text works fine for me. Have you tried stepping through your code and verifying that you're getting the expected text from the file?
Quote:
Originally Posted by
gerble1000
the list may also have lowercase but i would allow lowercase to go through so does that mean i have to change the MAC_ADDR_FORMAT to [0-9a-fA-F]
You can do it that way or you can instruct the Like operator to use case-insensitive comparisons by specifying Option Compare Text.
Re: need help checking string is formatted correctly as mac address
my bad
i had
if (vairable8)
when it should of been
if (variable)
:)
Re: need help checking string is formatted correctly as mac address
Hmm, it looks like you don't have Option Explicit enabled. Now you know what happens when you don't use it. ;)
If you have no more issues, you may now mark this thread :check: Resolved!