1

I am trying to do some advanced labeling with VBScript and need some help getting to the finish line. I have never scripted anything prior to last week so I am definitely a newbie when it comes to VBScripting.

Here is my problem- I have hundreds of soil borings at which several samples have been collected at varying depths. The number of samples collected at each location varies as does the depth. So I wrote a very simple script to get my labels into a table format. I concatenated two fields in excel (Depth and Result) separated by spaces to create the [LABEL] field.

My issue now is adding an expression into my existing script which will return no values if no data is present in the data table. What I'm getting now is just several blank lines when samples were not collected at that depth. See the attached image for reference.

How can I fix my expression in order to skip these blanks?

Here is the script I have thus far...

"<FNT name= 'Arial' size='10'><BOL>" & [Sample_ID] & "</BOL></FNT>" + vbnewline + "<UND>" & "DEPTH (BGS)" & "</UND>" + "  " + "<UND>" & "LEAD (MG/KG)" & "</UND>" + vbnewline + vbnewline + [ALABEL] + vbnewline + [BLABEL] + vbnewline + [CLABEL] + vbnewline + [DLABEL] 

This has all been done in the simple label expression maker within ArcGIS so far. I assume I will need to add some kind of if then statement and a loop to get what I need. But like I said earlier... I am no expert at scripting yet.

enter image description here

1 Answer 1

1

The script would look something like this

Function FindLabel ( [Sample_ID], [ALABEL], [BLABEL], [CLABEL],[DLABEL] )
  dim label
  label = "<FNT name= 'Arial' size='10'><BOL>" & [Sample_ID] & "</BOL></FNT>" + vbnewline + "<UND>" & "DEPTH (BGS)" & "</UND>" + "  " + "<UND>" & "LEAD (MG/KG)" & "</UND>" + vbnewline
  if [ALABEL] <> " " then
    label = label + vbnewline + [ALABEL]
  end if 
  if [BLABEL] <> " " then
    label = label + vbnewline + [BLABEL]
  end if 
  if [CLABEL] <> " " then
    label = label + vbnewline + [CLABEL]
  end if
  if [DLABEL] <> " " then
    label = label + vbnewline + [DLABEL]
  end if 
  FindLabel = label
End Function  
2
  • You rule! This worked perfectly... I know that labeling in table format has been an issue in Arc map for a long time but I found that formatting in Excel first and then bringing into Arc is the best route to take for beginners like me. I really hope someone finds this thread in the future and avoids countless hours of internet searches trying to find a simple solution for beginners. Once again, I can't thank you enough!!! Commented Jul 31, 2018 at 21:12
  • Glad to help! Don't forget to click the check mark to indicate your question was answered.
    – kenbuja
    Commented Aug 1, 2018 at 13:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.