Select to view content in your preferred language

VB conditional statement not working in calculate field tool

1594
4
05-24-2011 09:11 AM
CrystalCarreon
Emerging Contributor
I am writing a python script which utilizes the expression & code block parameter in the calculate field tool to populate values for a specific field. The code block uses a conditional If,Then, Else statement to understand the value of an existing field (Num_Value) in order to calculate the value of another field (Num_Text). However, I keep receiving the error "(Microsoft VBScript compilation error) Expected end of statement". See script below:
...
CodeBlock = "dim X as string \\nIf [Num_Value] = 1 Then \\nX = \"Poor\" \\nElse X = \"Good\" \\nEnd If"
gp.CalculateField_management(InputFeature,"Num_Text","X","VB",CodeBlock)
...

Any ideas as to what I am doing wrong within the VB code block??
Any help is greatly appreciated!
Thanks!

P.S. Using arcmap 9.2
Tags (2)
0 Kudos
4 Replies
DarrenWiens2
MVP Alum
I using ArcGIS 10, so I can't test this. But, in 10 you can use VBScript for the code block (although I'm not completely sure what 9.2 uses - the help says standard VB). I know that VBScript doesn't like it when you dim variables AS a datatype. I suggest either not dimming your variable, or at least remove "as string".
0 Kudos
CrystalCarreon
Emerging Contributor
That did the trick! Thanks so much!

When I used that bit of code just within ArcMap it worked fine so I figured I would include it but I guess not!

Thanks again!
0 Kudos
DarrenWiens2
MVP Alum
No problem - I've spent a lot of time tilting at that windmill in the past!
0 Kudos
PaulGrimes
Deactivated User
Great post, perfect solution that saved me hours of head scratching. Thanks for taking the time to post the solution.

Paulg
0 Kudos