I am working with a list of vlan ranges. Some of these will be ranges: "101-120" or individual numbers: "150,158,201" or even a combination: "101-120,150,158,201,300-450,2000-2500".
What I needed to do is break this up into an array that contains every number that is part of the whole listed group. That array is used to compare if a number from something else is a match; part of the listed range.
In the numbers above, 105, 150, 302,2000,2499 or 2500 would match. But, 121, 155, 210, 1999, 2501 would not match.
The source data comes from a Cisco switch configuration file, obtained with 'show run'. Within that text file will be an area similar to this:
I open the text file into an array, where each element of the array is loaded with the text file with the appropriate vbLf (or vbCrLf - I have a way to be sure).
When the array is loaded (has more than -1 elements) I can use Application.Match to find the line that has the interface line I'm using.
I will use:
If 't' is an error, it wasn't found and I can go do stuff. If the string is found, it will be a number that is an index within the array to the next line.
In this example, sDataArray(t) will be " switchport". I will use a do-loop until I find the trailing "!".
During that loop, I will add the numeric parts to an intermediate string until I have every line.
The code for that, looks like this:
The variable VLANList will wind up with this (from the above example):
"1-1316,1318-1334,1336-3371,3376-3415,3420-3423,3428-3465,3468-3483,3500-3539,3576-3587,3600-4094"
When that variable is set, I do this:
When this is done, VLANArray will contain all the individual numbers that are within the skipping lists of numbers. I realise there is a potential glitch here, if the VLANList has no 'ranges', but is instead only a 'skip-list' (I believe I figured that out).
I then use Application.Match to find the values I need to confirm.
I have two questions: 1) is this horribly clunky? 2) Can I confirm that only exact matches will be found? I don't want to be looking for 310 and get a false match because the list has something like 3101.
Bookmarks