add a counting control in current VBScript in Label Expression
I want to add a counting control in current expression so it can do the posting every 2nd or 5th record instead of every single record.
Also, if I add the (TWP) field into the Expression so if can check & post only the odd/even numbers, how do I write the script? Please note (TWP) is in text string; I tried the convert it to numeric by adding a VALUE(TWP) but it replied with the "No features found" error message.
Can you show me both way to do this posting?
Mapping Center Answer:
Instead of trying to find the records you want to label and set the expression all in a single label expression, instead do this in two steps -- 1) create and calculate the values in field to indicate which townships you want to label, and then 2) use a SQL query for the labels to note that you only want to label the records that relate to the townships you want to label (these will have a value of 1 and all other records will have a value of 0).
We wrote out a calculate statement below that you can use to find the even numbered townships. First, add a new field (type = short integer) and call it LabelYN_Even (this will be used to indicate which records have even-numbered townships), then use the Field Calculator and load the .cal file we attached. Replace the word "TOWNSHIP" with the field name in your attribute table that has the number of the townships. Then use the Save option to save this calculate statment -- it will have a .cal extension and be stored in the directory that you specify. Now you are ready to calculate the values. In Label Manager or on the Labels tab for the layer, use the SQL query "LabelYN_Even = 1" to label only the even numbered townships.
To modify this so that it labels every 5th township, change the calculate statement by replacing this line:
If InStr(24680, k) then
with this line:
If InStr(50, k) then
In essence, what the first calculate statement does is find townships whose numbers end in 2, 4, 6, 8, or 0 and calculates a field value of 1, and everything else is 0. In the second statement (the one you would modify as described above) the records that are for townships whose numbers end in either 5 or 0 are selected and they get a value of 1, while everything else is 0.
If you would like to post a comment, please login.