Solved! Go to Solution.
You have no basis for thinking the "where" is the problem. The code works when the inputs are correct, otherwise I could not have made the screenshot. The only problems are tied to the inputs you are supplying. Your path is likely the problem. The backslash is an escape character and not being interpreted as a backslash. You must make it a raw string to correct that.
strpTable = r"A:\Desktop\New Folder\New Folder\BNDS.mdb\TEOR"
You can reference a table that is already in your map without using any path and it will work. So add TEOR to the map and make the path:
strpTable = "TEOR"
You also did not make the two sets of field pairs identical. That is corrected below where I assumed you wanted ATE and GEO listed as paired values under the HOLEID header.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
Remains the same.
I can send you the. "Mdb" for you to check?
Function FindLabel ( [X_Y_LINK] ) RelateFieldOfLayerValues = [X_Y_LINK] RelateFieldOfLayer = "X_Y_LINK" RelateFieldOfTable = "X_Y_LINK" strpTable = "CL_INTERSECTIONS_PAIRS" 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.PAIR_STNAMES strLabel2 = prow.INT_SPREAD 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 if iMaxLbl1Sz + iMaxLbl2Sz + iSpace - Len(RelateFieldOfLayerValues) > 0 Then FindLabel = FindLabel & "<UND>" & RelateFieldOfLayerValues & "</UND>" & String(iMaxLbl1Sz + iMaxLbl2Sz + iSpace - Len(RelateFieldOfLayerValues), "_") & vbnewline Else FindLabel = FindLabel & "<UND>" & RelateFieldOfLayerValues & "</UND>" & vbnewline End If Set prows = gp.searchcursor(strpTable,strWhereClause) Set prow = prows.next Do until prow is nothing strLabel1 = prow.PAIR_STNAMES strLabel2 = prow.INT_SPREAD 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
Here is the code I use to build my labels. X_Y_LINK is a text field. There are no NULL values in any of the data. The related table named CL_INTERSECTIONS_PAIRS was already in my map. PAIR_STNAMES is a text field and INT_SPREAD is a double field in the related table. The inputs I changed to fit my data are shown in red.
I did modify the code slightly to handle an error that occurs if the header is longer than the detail value pairs or where there are no related records in the relate table. My previous test of my header line revision did not cover these possibilities. The revised lines that corrected the error are shown in bold green italics. The bold green italic lines did not need customization to fit the input data, they just needed to be added.
Function FindLabel ( [X_Y_LINK] ) RelateFieldOfLayerValues = [X_Y_LINK] RelateFieldOfLayer = "X_Y_LINK" RelateFieldOfTable = "X_Y_LINK" strpTable = "CL_INTERSECTIONS_PAIRS" 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.PAIR_STNAMES strLabel2 = prow.INT_SPREAD 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 if iMaxLbl1Sz + iMaxLbl2Sz + iSpace - Len(RelateFieldOfLayerValues) > 0 Then FindLabel = FindLabel & "<UND>" & RelateFieldOfLayerValues & "</UND>" & String(iMaxLbl1Sz + iMaxLbl2Sz + iSpace - Len(RelateFieldOfLayerValues), "_") & vbnewline Else FindLabel = FindLabel & "<UND>" & RelateFieldOfLayerValues & "</UND>" & vbnewline End If Set prows = gp.searchcursor(strpTable,strWhereClause) Set prow = prows.next Do until prow is nothing strLabel1 = prow.PAIR_STNAMES strLabel2 = prow.INT_SPREAD 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
Perfect, thank you.
One more thing, is presented in table form? with rows and columns perfect?
Mine were not with correct alignment.
Perfect, thank you.
Did you use a uniform width font like Lucidia Console? You could also try Courior, Courier New, Letter Gothic Std, OCR A Std, Orator Std, Prestige Elite Std, and Simplified Arabic Fixed. Only fonts where every letter is the same width will come close to working.
Fonts like Arial won't work, because the character widths vary too much. There is no way to control letter spacing of variable width character fonts to make a decent looking table.
If the font does not fix the problem I would need to see a screen shot of what you are seeing. If the header row width is longer than your value pairs the spacing algorithm would need to be adjusted slightly to account for the extra width.
Anyway, no matter what they probably won't be perfect. If you look carefully at my screen shot the vertical separators do vary slightly, but the variance is not enough to make the table layout fail. Since these labels remain dynamic the fact that they only achieve a reasonable table effect with minor imperfections is a decent trade off over other methods that may achieve perfect tables, but that require the labels to become static.
I changed the font you suggested, but still with different tabs.
Masked name for confidentiality reasons.[ATTACH=CONFIG]33889[/ATTACH]
Sorry for the delay, changed the code like this::
Function FindLabel ( [HOLEID] )
RelateFieldOfLayerValues = [HOLEID]
RelateFieldOfLayer = "HOLEID"
RelateFieldOfTable = "HOLEID"
strpTable = "DADO"
iMaxLbl1Sz = 0
iMaxLbl2Sz = 0
iMaxLbl3Sz =0
iMaxLbl4Sz = 0
iSpace = 3
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.DE
strLabel2 = prow.INTERV
strLabel3 = prow.Fe_pct
strLabel4 = prow.GEO
If (Len(strLabel1) > iMaxLbl1Sz) Then
iMaxLbl1Sz = Len(strLabel1)
End If
If (Len(strLabel2) > iMaxLbl2Sz) Then
iMaxLbl2Sz = Len(strLabel2)
End If
If (Len(strLabel3) > iMaxLbl3Sz) Then
iMaxLbl3Sz = Len(strLabel3)
End If
If (Len(strLabel4) > iMaxLbl4Sz) Then
iMaxLbl4Sz = Len(strLabel4)
End If
Set prow = prows.next
Loop
Set prows = Nothing
if iMaxLbl1Sz + iMaxLbl2Sz + iMaxLbl3Sz + iMaxLbl4Sz + iSpace - Len(RelateFieldOfLayerValues) > 0 Then
'FindLabel = FindLabel & "<UND>" & RelateFieldOfLayerValues & "</UND>" & String(14, "_") & vbnewline
FindLabel = FindLabel & "<UND>" & RelateFieldOfLayerValues & "</UND>" & String(iMaxLbl1Sz + iMaxLbl2Sz + iMaxLbl3Sz + iMaxLbl4Sz + iSpace - Len(RelateFieldOfLayerValues), "_") & vbnewline
FindLabel = FindLabel & "<UND>" & "<CLR red='0' green='0' blue='255'>" & "|"& "FROM(m)"& "|"&"INT(m)"& vbtab & "|"&"Fe(%)" &"|"&"LIT"& String(iMaxLbl4Sz - Len("LIT"), "_") & "|"& "</CLR>"& "</UND>"& vbnewline
Else
FindLabel = FindLabel & "<UND>" & RelateFieldOfLayerValues & "</UND>" & vbnewline
FindLabel = FindLabel & "<UND>" & "<CLR red='0' green='0' blue='255'>" & "|"& "FROM(m)"& "|"&"INT(m)"& vbtab & "|"&"Fe(%)" &"|"&"LIT"& "</CLR>"& "</UND>"& vbnewline
End If
Set prows = gp.searchcursor(strpTable,strWhereClause)
Set prow = prows.next
Do until prow is nothing
strLabel1 = prow.DE
strLabel2 = prow.INTERV
strLabel3 = prow.Fe_pct
strLabel4 = prow.GEO
k1 = iSpace + (iMaxLbl1Sz - Len(strLabel1))
k2 = iSpace + (iMaxLbl2Sz - Len(strLabel2))
k3 = iSpace + (iMaxLbl3Sz - Len(strLabel3))
k4 = iSpace + (iMaxLbl4Sz - Len(strLabel4)) -3
FindLabel = FindLabel & "|"
FindLabel = FindLabel & strLabel1 & "<CLR red='255' green='255' blue='210'>" & String(k1, ".") & "</CLR>"
FindLabel = FindLabel & "|"
FindLabel = FindLabel & strLabel2 & "<CLR red='255' green='255' blue='210'>" & String(k2, ".") & "</CLR>"
FindLabel = FindLabel & "|"
FindLabel = FindLabel & strLabel3 & "<CLR red='255' green='255' blue='210'>" & String(k3, ".") & "</CLR>"
FindLabel = FindLabel & "|"
FindLabel = FindLabel & "<CLR red='255' green='255' blue='210'>" & String(k4, ".") & "</CLR>" & strLabel4 & "|" &vbnewline
Set prow = prows.next
Loop
Set prows = Nothing
End Function