Conversion code block to single line?
Due to a change in ArcGIS software here, a block of code no longer works (to calculate a field of a table, based on a condition). Is it pretty simple to convert a block of VBScript to a single line? This was my attempt (still not working):
Code:
Dim dblISOLEVEL As Double
Dim lngJoinCnt As Long
Dim dblZLEVEL as Double
lngJoinCnt = [Join_Count]
dblZLEVEL = [ZLEVEL]
if (lngJoinCnt = 1) and (dblZLEVEL = 0) then dblISOLEVEL = -1 elseif (lngJoinCnt > 1) and (dblZLEVEL = 0) then dblISOLEVEL = dblZLEVEL elseif (lngJoinCnt = 1) and (dblZLEVEL = 5) then dblISOLEVEL = 0 elseif (lngJoinCnt > 1) and (dblZLEVEL = 5) then dblISOLEVEL = dblZLEVEL else dblISOLEVEL = dblZLEVEL
end if
Can someone please help?
Re: Conversion code block to single line?
Sorry, forgot to include the ArcGIS link previously.
Re: Conversion code block to single line?
Not sure what's going on here or what the question is, but drop the End If if you are using a one line If.
Re: Conversion code block to single line?
Quote:
Originally Posted by
dilettante
Not sure what's going on here or what the question is, but drop the End If if you are using a one line If.
Thanks. Sorry, I didn't explain fully. ArcGIS includes a geoprocessing tool which we have built a model around. This particular code is included in a geoprocessing tool which calculates a field, based on the code. We have upgraded ArcGIS from 9.3 to 10 (which no longer supports the VBScript code block, but only a single line. A subcontractor developed the model, and now we are attempting to adjust the code to work with ArcGIS 10. Within the tool, we have the calculation being run on the "ISOLEVEL" field, within the table. The exression is titled "dbISOLEVEL". The expression type is "VB", and the code is in my first post.
I'll soon give your recommendation a try.
Re: Conversion code block to single line?
Well if what they changed went from executing script to doing an Eval of an expression you may have to turn this into some combination of nested IIf() function calls.
Sadly VBScript never got VB6's Choose() and Switch() functions which might also be helpful here.
Re: Conversion code block to single line?
Maybe something like this?
Code:
IIF((((lngJoinCnt = 1) and (dblZLEVEL = 0)), dblISOLEVEL = -1), IIF(((lngJoinCnt > 1) and (dblZLEVEL = 0)), dblISOLEVEL = dblZLEVEL), IIF((lngJoinCnt = 1) and (dblZLEVEL = 5), dblISOLEVEL = 0), IIF((lngJoinCnt > 1) and (dblZLEVEL = 5), dblISOLEVEL = dblZLEVEL), else (dblISOLEVEL = dblZLEVEL))
BTW, I just found out from an ArcGIS Technical Analyst, that the actual transition of the tools in the version progression is from VBA to VBScript.
Re: Conversion code block to single line?
Hmm, I guess I was somehow assuming that.
But VBScript can be run in "blocks" too. Are you sure they only use an Eval() call to run your script? If not then perhaps you do not need a one-liner like that.
Re: Conversion code block to single line?
After reading a bit about VBScript, all I had to do with the initial code (post #1) was get rid of the variable types. Instead I did this by "casting type values", as here:
Code:
Dim dblISOLEVEL
Dim lngJoinCnt
Dim dblZLEVEL
lngJoinCnt = CLng([Join_Count])
dblZLEVEL = CDbl([ZLEVEL])
if (lngJoinCnt = 1) and (dblZLEVEL = 0) then
dblISOLEVEL = -1
elseif (lngJoinCnt > 1) and (dblZLEVEL = 0) then
dblISOLEVEL = dblZLEVEL
elseif (lngJoinCnt = 1) and (dblZLEVEL = 5) then
dblISOLEVEL = 0
elseif (lngJoinCnt > 1) and (dblZLEVEL = 5) then
dblISOLEVEL = dblZLEVEL
else
dblISOLEVEL = dblZLEVEL
end if
Apparently, ESRI needs to update the error message for this issue. I notifiied them of this.
Thanks a lot for your help, dilettante.