Results 1 to 8 of 8

Thread: Conversion code block to single line?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    9

    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?

  2. #2

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    9

    Re: Conversion code block to single line?

    Sorry, forgot to include the ArcGIS link previously.

  3. #3
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    9

    Re: Conversion code block to single line?

    Quote Originally Posted by dilettante View Post
    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.

  5. #5
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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.

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    9

    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.
    Last edited by bguidry; Jan 11th, 2012 at 01:45 PM.

  7. #7
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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.

  8. #8

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    9

    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.
    Last edited by bguidry; Jan 13th, 2012 at 09:19 AM. Reason: Working correctly now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width