Hello all! The company I am currently working for has decided to migrate from ArcGIS 9.3 to 10.0 recently and we are having difficulty using a few of our Arc 9.3 models that utilize the Calculate Field tool. They were written in VBA and I need to get them to work using VBScript. The following bit of code is intended to calculate the x coordinate of the centre of a harvesting block and put it in a field.
Field Name: xcoord
Expression: dblX
Expression Type: VB
Code Block:
Dim dblX as Double
Dim pArea as IArea
Set pArea = [Shape]
dblX = pArea.Centroid.X
I am aware that you cannot have "as Double" in Dim statements with VBSand I have tried to remove those without any luck. I apologize in advance for my lack of scripting/programming language. I receive the following error once the model finished running:
General error executing calculator.
ERROR 999999: Error executing function.
Expected end of statement
Failed to execute (Calculate Field (3)).
I also get the same error when the following bit of code runs in another calculate field tool within the same model.
Field Name: LONGITUDE
Expression: sDMS
Expression Type: VB
Code Block:
Dim pArea As IArea
Dim dblX As Double
Dim dVal As Double
Dim dD As Double, dM As Double, dS As Double
Dim dM1 As Double, dS1 As Double
Dim sD As String, sM As String, sS As String
Dim sSuf As String
Dim sType As String
Dim sDMS As String
Dim sDeg As String, sMin As String, sSec As String
Dim inumdec As Integer
Dim pSpatRefFact As ISpatialReferenceFactory2
Set pSpatRefFact = New SpatialReferenceEnvironment
Dim pCoordSys As IGeographicCoordinateSystem
Set pCoordSys = pSpatRefFact.CreateGeographicCoordinateSystem(esriSRGeoCS_NAD1983)
Dim pNewSpRef As ISpatialReference
Set pNewSpRef = pCoordSys
Set pArea = [Shape]
pArea.Centroid.Project pNewSpRef
dblX = pArea.Centroid.X
dVal = dblX
sDeg = "d"
sMin = Chr(39)
sSec = Chr(34)
inumdec = 2
sType = "dms"
dVal = Abs(dVal)
dD = Int(dVal)
sD = CStr(dD)
dM = (dVal - dD) * 60
dM1 = Int(dM)
If (sType = "dms") Then
If (Len(CStr(dM1)) = 1) Then
sM = "0" & CStr(dM1)
Else
sM = CStr(dM1)
End If
dS = FormatNumber(((dM - dM1) * 60), inumdec)
dS1 = Int(dS)
If (Len(CStr(dS1)) = 1) Then
sS = "0" & CStr(dS)
Else
sS = CStr(dS)
End If
sDMS = sD & sDeg & " " & sM & sMin & " " & sS & sSec
Else
sM = CStr(FormatNumber(dM, inumdec))
sDMS = sD & sDeg & " " & sM & sMin
End If
Any assistance with getting this to run using VBScripting would be most appreciated. Thanks in advance!
Steve