0

I am new in the VBScript world, so I am really confused with programming. I need to do this expression in my evaluator in my Network Analyst. Basically I am adding a "cost" that is my percentage of primary roads, where:

TIPO 0 = Primary roads
TIPO 1 = Secondary Roads
TIPO 2 = Tertiary roads

So the equation should be really simple: Primary Roads/(Total Roads)

In that Way, I made this Field Evaluator

 The value is: C

My script is:

Dim A

If [TIPO] = 0 Then

 A = [SHAPE_Length]

elseif [TIPO] = 1 Then

 A = [SHAPE_Length]

elseif [TIPO] = 2 Then

 A = [SHAPE_Length]

end if

Dim B

If [TIPO] = 0 Then

 B = [SHAPE_Length]

elseif [TIPO] = 1 Then

 B = 0

elseif [TIPO] = 2 Then

 B = 0

end if

Dim C

C = A / B

return 

The value is: C What happens is that even that the field Evaluator shows has okay(without errors), the when calculating the field, it shows 0 has an answer, and sometimes show an error messagem when I try to rebuild my network.

  • 1
    where's your return C? Your function does stuff but doesn't return a result. That isn't python, it's VBS.. which is out of favor with Esri but should still work. You've also got an extra end if that isn't matched by a starting if, it should be end function - but where's your function name? – Michael Stimson Dec 5 '17 at 23:52
  • Hello, indeed is VB script, I tried to do in VB because honestly dont know how to write in Python, it seems a lot more complicated. I just reviewed the script and edited it, what do you think about it? – gert Dec 6 '17 at 0:55
  • 1
    Have a read of gis.stackexchange.com/questions/147141/…, vbscript is different to python in that there is no return and the variables go directly into the code block so that return is not needed. In the field calculator expression your field value is C. I also think it's not necessary to dim your variables in vbscript. – Michael Stimson Dec 6 '17 at 1:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.