VB Script Code block newbie question re: IF statment

878
4
Jump to solution
12-14-2012 07:38 AM
PeterPeng
New Contributor II
I get a general error for this simple code:
dim [DIAMETER_1] as number dim [New_Pipe_S] as number dim X as number  if [New_Pipe_S] = 0 then  X = [DIAMETER_1] else  X = [New_Pipe_S] end if    Final_Dia = X


[ATTACH=CONFIG]19945[/ATTACH]
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
PeterPeng
New Contributor II
nevermind, someone at Stack answered my question!

http://gis.stackexchange.com/questions/44008/field-calculator-vb-script-codeblock-if-statement-synta...

Thanks all!

(fyi here is the correct one)

Dim Output

If  [New_Pipe_S] = 0 Then
Output = [DIAMETER]
Else
Output  = [New_Pipe_S]
End If

Final_Dia =
Output

View solution in original post

0 Kudos
4 Replies
markdenil
Occasional Contributor III
Don't declare and use the field references as variables
declare a variable, set it to the field value, and use the variable in the code

dim diam as number
dim pipe as number
dim X as number

diam = [DIAMETER_1]
pipe = [New_Pipe_S]

if pipe = 0 then
 X =  diam
else
 X = pipe
end if


Final_Dia =
X
0 Kudos
PeterPeng
New Contributor II
I tried that and it didn't work either, same general error 99999. All 3 fields were originally formated as Long and Short Integers in ArcMap. It's stored in a shapefile and I don't have the ArcMap spatial anaylist license, if that makes a difference :(?

Any other thoughts?

Much appreciated!!
0 Kudos
DarrenWiens2
MVP Honored Contributor
Don't "dim AS" in VB Script (if you really want to, you can dim by itself, but why bother?)

diam = [DIAMETER_1]
pipe = [New_Pipe_S]

if pipe = 0 then
 X =  diam
else
 X = pipe
end if


Final_Dia =
X
0 Kudos
PeterPeng
New Contributor II
nevermind, someone at Stack answered my question!

http://gis.stackexchange.com/questions/44008/field-calculator-vb-script-codeblock-if-statement-synta...

Thanks all!

(fyi here is the correct one)

Dim Output

If  [New_Pipe_S] = 0 Then
Output = [DIAMETER]
Else
Output  = [New_Pipe_S]
End If

Final_Dia =
Output
0 Kudos