Calculate Field VB.NET codeblock

1581
2
Jump to solution
09-25-2012 05:51 AM
New Contributor
Hi all,

I'm trying to run the Calculate Field geoprocessor tool in VB.NET, but it's not behaving.  Below is what I have.  I think it might be smth to do with the lines "test = ..." but I'm not sure.  I'm working in Arc9.3

Your thoughts would be appreciated.

Dim gp2 As Geoprocessor = New Geoprocessor()                 Dim CalcField As ESRI.ArcGIS.DataManagementTools.CalculateField = New ESRI.ArcGIS.DataManagementTools.CalculateField()                 CalcField.in_table = pflayer                 CalcField.field = "Fault"                 CalcField.expression_type = "VB"                 CalcField.expression = "text"                 CalcField.code_block = "Dim text as String" & vbNewLine & _ "If [LOWEST_VAL] >-3 Then" & vbNewLine & _ "text = """ & vbNewLine & _ "ElseIf (( ([INSIDE_EDI]<=-3) OR ([OUTSIDE_ED] <=-3) ) AND ( ([NEARSIDE_C]>-3) AND ([FARSIDE_CO] >-3))) Then " & vbNewLine & _ "text = Edilon" & vbNewLine & _ "ElseIf (( ([NEARSIDE_C]<=-3) OR ([FARSIDE_CO] <=-3)) AND (( [INSIDE_EDI]>-3) AND ([OUTSIDE_ED] >-3)) )Then " & vbNewLine & _ "text = Concrete" & vbNewLine & _ "ElseIf ((( [NEARSIDE_C]<=-3) OR ([FARSIDE_CO] <=-3)) AND ( ([INSIDE_EDI]<=-3) OR ([OUTSIDE_ED] <=-3)) )Then " & vbNewLine & _ "text = Both" & vbNewLine & _ "end if"                  gp2.Execute(CalcField, Nothing)
Reply
0 Kudos
1 Solution

Accepted Solutions
Regular Contributor III
I would suggest using the debugger to see exactly what that code_block string looks like.

"text = """
This is setting text to a single double quote - is that what you want? 

Also, the other text assignments should probably be enclosing the string values in double quotes.  Since double quotes are special characters, you'll need to use escape characters in order to insert a literal double quote into the string.

View solution in original post

Reply
0 Kudos
2 Replies
Regular Contributor III
I would suggest using the debugger to see exactly what that code_block string looks like.

"text = """
This is setting text to a single double quote - is that what you want? 

Also, the other text assignments should probably be enclosing the string values in double quotes.  Since double quotes are special characters, you'll need to use escape characters in order to insert a literal double quote into the string.

View solution in original post

Reply
0 Kudos
New Contributor
Thanks Neil,

Yeah I just got there before reading your reply.  "text = ""Concrete"" " is the solution; I tried so many variations, not sure why this one wasn't attempted sooner.

Ciao
Reply
0 Kudos