Select to view content in your preferred language

ArcPAD 8 - For Loop Causes Object Required Error

4282
4
01-26-2011 12:23 PM
DennisPomo
Emerging Contributor
Hi, I am initializing some controls on a form, I have a set of edit boxes named edtDBH1, edtDBH2...edtDBH6.
The user selects the number of items to be recorded and my script is supposed to enable the right number of controls and disable the others. To do this I am using a For loop to call a function with parameters for: control to be changed, iteration number and the Boolean value. This way I can recycle the function and use it to disable the remaining controls by using a countdown loop with Boolean value set to false.
The first loop works fine but the second loop does it's job and then throws a VBScript error: Object Required: rfPage...

I think I am not closing the first loop correctly or somehow the first loop is messing with the object references established at the start.

Any suggestions?

Code:

Sub SetNumDBH
Dim objPg, numDBH, controlCount
Set objPg = Layers("Tree_Inventory").Forms("EDITFORM").Pages("pgDBH").Controls
numDBH = objPg("cboNumDBH").Value
if numDBH = 0 then
MsgBox "DBH Number Not Valid! Check Values!"
Exit Sub
End If
For controlCount=1 to numDBH
call changeEDT(objPg, controlCount, True)
Next


For controlCount = (numDBH+1) to 6
  call changeEDT(objPg, controlCount, False)
Next
End Sub


Function changeEDT(byRef rfPage, counter, boolVal)
Dim strEdtName
strEdtName = "edtDBH" & counter
'MsgBox "Called: bool: " & boolval & " string:" & strEdtName
rfPage(strEdtName).Enabled = boolval
rfPage(strEdtName).Visible = boolval
End Function

-----------------------------------------------------------------------------------------
Many Thanks

Dennis
Tags (3)
0 Kudos
4 Replies
RolfBroch
Frequent Contributor
Your message VBScript error: Object Required: indicates that the object you try to retrieve in the statement rfPage(strEdtName).Enabled = boolval does not exist which seems to me that the steEdtName is incorrect. Could be a wrong spelling in your form definition.

Try changing the function to trap the error

Function changeEDT(byRef rfPage, counter, boolVal)
Dim strEdtName
strEdtName = "edtDBH" & counter
'MsgBox "Called: bool: " & boolval & " string:" & strEdtName
If rfPage(strEdtName) Is Nothing Then
MsgBox "Failed with strEdtName = " & strEdtName
Else
rfPage(strEdtName).Enabled = boolval
rfPage(strEdtName).Visible = boolval
End If
End Function
0 Kudos
DennisPomo
Emerging Contributor
Thanks Rolf,
This is a weird one, printing the string that is supposed to contain the controls name reveals that the string is correct. Substituting the string with the actual hard-coded name works but then the loop becomes pointless (it adds an incremental number to the string to access a series of controls).

I don't know what caused this, I got around it by changing the event used to execute the script to onselok and it works. Strange.

Thanks for your help.

Dennis
0 Kudos
RolfBroch
Frequent Contributor
That is strange. No 'blanks' hiding anywhere or uppercase/lowercase issues?
Check your statement objPg("cboNumDBH").Value for its lenght ie.

MsgBox Len(objPg("cboNumDBH").Value

Try to use an explicit conversion from integer to character using
strEdtName = "edtDBH" & CChar(counter)

There is an error there somewhere. Could you post your apl file?

Rolf
0 Kudos
DennisPomo
Emerging Contributor
Hi Rolf,

The issue seems to be sorted. The final code is the same but the trigger event is different. I think it was something to do with the object returned by the OnValidate function I was initially trying to use.

Thanks for your help.

Dennis
0 Kudos