Solved! Go to Solution.
Function FindLabel ( [RelateField] ) iMaxLbl1Sz = 0 iMaxLbl2Sz = 0 iSpace = 3 Set gp = CreateObject("esriGeoprocessing.GPDispatch.1") strWhereClause = chr(34) & "RelateFieldinTable" & chr(34) & " = '" & [RelateField] & "'" strpTable = "path to your relate table" Set prows = gp.searchcursor(strpTable,strWhereClause) Set prow = prows.next Do until prow is nothing strLabel1 = prow.Depths strLabel2 = prow.TotalPAHs If (Len(strLabel1) > iMaxLbl1Sz) Then iMaxLbl1Sz = Len(strLabel1) End If If (Len(strLabel2) > iMaxLbl2Sz) Then iMaxLbl2Sz = Len(strLabel2) End If Set prow = prows.next Loop FindLabel = "<UND>" & FindLabel & [RelateField] & "</UND>" & vbnewline Set prows = gp.searchcursor(strpTable,strWhereClause) Set prow = prows.next Do until prow is nothing strLabel1 = prow.Depths strLabel2 = prow.TotalPAHs k = (iMaxLbl1Sz - Len(strLabel1)) + iSpace + (iMaxLbl2Sz - Len(strLabel2)) FindLabel = FindLabel & strLabel1 & String(k, ".") & strLabel2 & vbnewline Set prow = prows.next Loop End Function
Function FindLabel ( [RelateFieldOfLayer] ) iMaxLbl1Sz = 0 iMaxLbl2Sz = 0 iSpace = 5 Set gp = CreateObject("esriGeoprocessing.GPDispatch.1") strWhereClause = chr(34) & "RelateFieldOfTable" & chr(34) & " = '" & [RelateFieldOfLayer] & "'" strpTable = "PathToRelateTable" Set prows = gp.searchcursor(strpTable,strWhereClause) Set prow = prows.next Do until prow is nothing strLabel1 = prow.LabelField1 strLabel2 = prow.LabelField2 If (Len(strLabel1) > iMaxLbl1Sz) Then iMaxLbl1Sz = Len(strLabel1) End If If (Len(strLabel2) > iMaxLbl2Sz) Then iMaxLbl2Sz = Len(strLabel2) End If Set prow = prows.next Loop FindLabel = FindLabel & "<FNT name='Arial' size='6.25'>" & [RelateFieldOfLayer] & "</FNT>" & vbnewline FindLabel = FindLabel & String(iMaxLbl1Sz + iMaxLbl2Sz + iSpace, "_") & vbnewline Set prows = gp.searchcursor(strpTable,strWhereClause) Set prow = prows.next Do until prow is nothing strLabel1 = prow.LabelField1 strLabel2 = prow.LabelField2 k1 = (iMaxLbl1Sz - Len(strLabel1)) + 2 k2 = iSpace + (iMaxLbl2Sz - Len(strLabel2)) - 3 FindLabel = FindLabel & strLabel1 & "<CLR red='255' green='255' blue='255'>" & String(k1, ".") & "</CLR>" FindLabel = FindLabel & "|" FindLabel = FindLabel & "<CLR red='255' green='255' blue='255'>" & String(k2, ".") & "</CLR>" & strLabel2 & vbnewline Set prow = prows.next Loop End Function
Function FindLabel ( [RelateFieldOfLayer] ) RelateFieldOfLayerValues = [RelateFieldOfLayer] RelateFieldOfLayer = "RelateFieldOfLayer" RelateFieldOfTable = "RelateFieldOfTable" strpTable = "PathToRelateTable" iMaxLbl1Sz = 0 iMaxLbl2Sz = 0 iSpace = 5 Set gp = CreateObject("esriGeoprocessing.GPDispatch.1") strWhereClause = chr(34) & RelateFieldOfTable & chr(34) & " = '" & RelateFieldOfLayerValues & "'" Set prows = gp.searchcursor(strpTable,strWhereClause) Set prow = prows.next Do until prow is nothing strLabel1 = prow.LabelField1 strLabel2 = prow.LabelField2 If (Len(strLabel1) > iMaxLbl1Sz) Then iMaxLbl1Sz = Len(strLabel1) End If If (Len(strLabel2) > iMaxLbl2Sz) Then iMaxLbl2Sz = Len(strLabel2) End If Set prow = prows.next Loop Set prows = Nothing FindLabel = FindLabel & "<UND>" & RelateFieldOfLayerValues & "</UND>" & String(iMaxLbl1Sz + iMaxLbl2Sz + iSpace - Len(RelateFieldOfLayerValues), "_") & vbnewline Set prows = gp.searchcursor(strpTable,strWhereClause) Set prow = prows.next Do until prow is nothing strLabel1 = prow.LabelField1 strLabel2 = prow.LabelField2 k1 = (iMaxLbl1Sz - Len(strLabel1)) + 2 k2 = iSpace + (iMaxLbl2Sz - Len(strLabel2)) - 3 FindLabel = FindLabel & strLabel1 & "<CLR red='255' green='255' blue='255'>" & String(k1, ".") & "</CLR>" FindLabel = FindLabel & "|" FindLabel = FindLabel & "<CLR red='255' green='255' blue='255'>" & String(k2, ".") & "</CLR>" & strLabel2 & vbnewline Set prow = prows.next Loop Set prows = Nothing End Function
Jennifer:
Thanks for the code. I have modified it slightly to make it slightly easier to change the inputs of the script that need to be customized for user specific data by adding variables in the top lines of the Function. The field names still have to be modified in the body of the text. The inputs are shown in Red, Bold and Italics similar in your code.
I also modified the label style created by the code by eliminating the horizontal line inserted below the table header by using an underline of the header instead to reduce the amount of vertical space needed for each label. As you mentioned, the label font needs to have uniform spaced characters to work correctly.
Function FindLabel ( [RelateFieldOfLayer] ) RelateFieldOfLayerValues = [RelateFieldOfLayer] RelateFieldOfLayer = "RelateFieldOfLayer" RelateFieldOfTable = "RelateFieldOfTable" strpTable = "PathToRelateTable" iMaxLbl1Sz = 0 iMaxLbl2Sz = 0 iSpace = 5 Set gp = CreateObject("esriGeoprocessing.GPDispatch.1") strWhereClause = chr(34) & RelateFieldOfTable & chr(34) & " = '" & RelateFieldOfLayerValues & "'" Set prows = gp.searchcursor(strpTable,strWhereClause) Set prow = prows.next Do until prow is nothing strLabel1 = prow.LabelField1 strLabel2 = prow.LabelField2 If (Len(strLabel1) > iMaxLbl1Sz) Then iMaxLbl1Sz = Len(strLabel1) End If If (Len(strLabel2) > iMaxLbl2Sz) Then iMaxLbl2Sz = Len(strLabel2) End If Set prow = prows.next Loop Set prows = Nothing FindLabel = FindLabel & "<UND>" & RelateFieldOfLayerValues & "</UND>" & String(iMaxLbl1Sz + iMaxLbl2Sz + iSpace - Len(RelateFieldOfLayerValues), "_") & vbnewline Set prows = gp.searchcursor(strpTable,strWhereClause) Set prow = prows.next Do until prow is nothing strLabel1 = prow.LabelField1 strLabel2 = prow.LabelField2 k1 = (iMaxLbl1Sz - Len(strLabel1)) + 2 k2 = iSpace + (iMaxLbl2Sz - Len(strLabel2)) - 3 FindLabel = FindLabel & strLabel1 & "<CLR red='255' green='255' blue='255'>" & String(k1, ".") & "</CLR>" FindLabel = FindLabel & "|" FindLabel = FindLabel & "<CLR red='255' green='255' blue='255'>" & String(k2, ".") & "</CLR>" & strLabel2 & vbnewline Set prow = prows.next Loop Set prows = Nothing End Function
How would the "where" in string type primary keys?
The code assumed the related field was a string field, because single quotes are surrounding the value in the where clause variable.
strWhereClause = chr(34) & RelateFieldOfTable & chr(34) & " = '" & RelateFieldOfLayerValues & "'"
If the relate field was actually a numeric field the code would have to be changed to remove the single quotes from the line of code that builds the where clause.
strWhereClause = chr(34) & RelateFieldOfTable & chr(34) & " = " & RelateFieldOfLayerValues
If this does not answer your question, please copy the specific lines of code into your message that you are concerned about to better help me understand your question.
Function FindLabel ( [HOLEID] ) RelateFieldOfLayerValues = [HOLEID] RelateFieldOfLayer = "HOLEID" RelateFieldOfTable = "HOLEID" strpTable = "A:\Desktop\New Folder\New Folder\BNDS.mdb\TEOR" iMaxLbl1Sz = 10 iMaxLbl2Sz = 0 iSpace = 8 Set gp = CreateObject("esriGeoprocessing.GPDispatch.1") strWhereClause = chr(34) & RelateFieldOfTable & chr(34) & " = '" & RelateFieldOfLayerValues & "'" Set prows = gp.searchcursor(strpTable,strWhereClause) Set prow = prows.next Do until prow is nothing strLabel1 = prow.ATE strLabel2 = prow.GEO If (Len(strLabel1) > iMaxLbl1Sz) Then iMaxLbl1Sz = Len(strLabel1) End If If (Len(strLabel2) > iMaxLbl2Sz) Then iMaxLbl2Sz = Len(strLabel2) End If Set prow = prows.next Loop Set prows = Nothing FindLabel = FindLabel & "<UND>" & RelateFieldOfLayerValues & "</UND>" & String(iMaxLbl1Sz + iMaxLbl2Sz + iSpace - Len(RelateFieldOfLayerValues), "_") & vbnewline Set prows = gp.searchcursor(strpTable,strWhereClause) Set prow = prows.next Do until prow is nothing strLabel1 = prow.ATE strLabel2 = prow.GEO k1 = (iMaxLbl1Sz - Len(strLabel1)) + 2 k2 = iSpace + (iMaxLbl2Sz - Len(strLabel2)) - 3 FindLabel = FindLabel & strLabel1 & "<CLR red='0' green='0' blue='0'>" & String(k1, ".") & "</CLR>" FindLabel = FindLabel & "|" FindLabel = FindLabel & "<CLR red='0' green='0' blue='0'>" & String(k2, ".") & "</CLR>" & strLabel2 & vbnewline Set prow = prows.next Loop Set prows = Nothing End Function
The field names for the cursor are not supposed to be surrounded by brackets. (I would have put brackets in my example around the red text if I meant for you to enter a field name within brackets for the lines of code below)
Change this:
strLabel1 = prow.[HOLEID]
strLabel2 = prow.[ATE]
to this:
strLabel1 = prow.HOLEID
strLabel2 = prow.ATE
HOLEID should be a text field to work with this where clause and should not have Null values.Function FindLabel ( [HOLEID] ) RelateFieldOfLayerValues = [HOLEID] RelateFieldOfLayer = "HOLEID" RelateFieldOfTable = "HOLEID" strpTable = "A:\Desktop\New Folder\New Folder\BNDS.mdb\TEOR" iMaxLbl1Sz = 10 iMaxLbl2Sz = 0 iSpace = 8 Set gp = CreateObject("esriGeoprocessing.GPDispatch.1") strWhereClause = chr(34) & RelateFieldOfTable & chr(34) & " = '" & RelateFieldOfLayerValues & "'" Set prows = gp.searchcursor(strpTable,strWhereClause) Set prow = prows.next Do until prow is nothing strLabel1 = prow.HOLEID strLabel2 = prow.ATE If (Len(strLabel1) > iMaxLbl1Sz) Then iMaxLbl1Sz = Len(strLabel1) End If If (Len(strLabel2) > iMaxLbl2Sz) Then iMaxLbl2Sz = Len(strLabel2) End If Set prow = prows.next Loop Set prows = Nothing FindLabel = FindLabel & "<UND>" & RelateFieldOfLayerValues & "</UND>" & String(iMaxLbl1Sz + iMaxLbl2Sz + iSpace - Len(RelateFieldOfLayerValues), "_") & vbnewline Set prows = gp.searchcursor(strpTable,strWhereClause) Set prow = prows.next Do until prow is nothing strLabel1 = prow.HOLEID strLabel2 = prow.GEO k1 = (iMaxLbl1Sz - Len(strLabel1)) + 2 k2 = iSpace + (iMaxLbl2Sz - Len(strLabel2)) - 3 FindLabel = FindLabel & strLabel1 & "<CLR red='0' green='0' blue='0'>" & String(k1, ".") & "</CLR>" FindLabel = FindLabel & "|" FindLabel = FindLabel & "<CLR red='0' green='0' blue='0'>" & String(k2, ".") & "</CLR>" & strLabel2 & vbnewline Set prow = prows.next Loop Set prows = Nothing End Function
It did not work.
Is to write the "where" directly?
Function FindLabel ( [HOLEID] ) RelateFieldOfLayerValues = [HOLEID] RelateFieldOfLayer = "HOLEID" RelateFieldOfTable = "HOLEID" strpTable = r"A:\Desktop\New Folder\New Folder\BNDS.mdb\TEOR" iMaxLbl1Sz = 10 iMaxLbl2Sz = 0 iSpace = 8 Set gp = CreateObject("esriGeoprocessing.GPDispatch.1") strWhereClause = chr(34) & RelateFieldOfTable & chr(34) & " = '" & RelateFieldOfLayerValues & "'" Set prows = gp.searchcursor(strpTable,strWhereClause) Set prow = prows.next Do until prow is nothing strLabel1 = prow.ATE strLabel2 = prow.GEO If (Len(strLabel1) > iMaxLbl1Sz) Then iMaxLbl1Sz = Len(strLabel1) End If If (Len(strLabel2) > iMaxLbl2Sz) Then iMaxLbl2Sz = Len(strLabel2) End If Set prow = prows.next Loop Set prows = Nothing FindLabel = FindLabel & "<UND>" & RelateFieldOfLayerValues & "</UND>" & String(iMaxLbl1Sz + iMaxLbl2Sz + iSpace - Len(RelateFieldOfLayerValues), "_") & vbnewline Set prows = gp.searchcursor(strpTable,strWhereClause) Set prow = prows.next Do until prow is nothing strLabel1 = prow.ATE strLabel2 = prow.GEO k1 = (iMaxLbl1Sz - Len(strLabel1)) + 2 k2 = iSpace + (iMaxLbl2Sz - Len(strLabel2)) - 3 FindLabel = FindLabel & strLabel1 & "<CLR red='0' green='0' blue='0'>" & String(k1, ".") & "</CLR>" FindLabel = FindLabel & "|" FindLabel = FindLabel & "<CLR red='0' green='0' blue='0'>" & String(k2, ".") & "</CLR>" & strLabel2 & vbnewline Set prow = prows.next Loop Set prows = Nothing End Function