Getting error Object Required: when indexing an array - vbscript

Here's the code:
Set page = Sys.Browser("iexplore").Page...
Set files_table = page.FindChildByXPath("//div[#class='dojoxGridContent']//div[#role='presentation']", True)
Set files_table_rows = files_table.children
row_index = 0
While Not file_found
lnk_Refresh.Click
aqUtils.Delay(6000)
Set cell = files_table_rows(row_index) //error thrown on this line
During debugging I can see both objects files_table and files_table_rows and they're both correct and have the correct data. When we try to get the first element in files_table_rows, we get an error:
Microsoft VBScript runtime error.
Object required:'files_table_rows(...)'
If I place this line of code:
Set cell = files_table_rows(row_index)
right before the While loop, cell gets set correctly. The issue is happening inside the While loop, and I don't understand why this is a problem.

Related

JavaEdit search function not locating visible element

I've got two library functions:
Function searchWindow(title)
Set searchWindow = Window("title:=" + title)
End Function
And
Function searchField(label)
Set searchField = JavaEdit("attached text:=" + label)
End Function
Here I'm testing them:
Environment.Loadfromfile("C:\UFTConstants\constants.ini")
Set loginFrame = searchWindow(Environment.Value("frameLogin"))
loginFrame.Click
Set userField = searchField("User ID / Ci-Usager")
userField.Set "test"
The first function works fine, and it's title property matches that of the application. However, the second will not find the text field, despite properties matching:
The error:
I've tried other properties as well, tagname, various class properties, as well as combinations of all three, and none are producing a find.
Any ideas?
First Update
As per request, full spy screencap:
The full line generated by the recording tool:
JavaWindow("Application Name").JavaDialog("Window Title").JavaEdit("User ID / Ci-Usager").Set "user"
However, when I try to re-create this programmatically, I get the same error, only for JavaWindow instead:
"Cannot identify the object [JavaWindow] of (class JavaWindow)..."
Possible Java set-up issue? This would not explain why recording can still locate Java objects, however.
Second Update
Here are the recognition properties:
I have ensured that all properties are set, still unable to locate.
Final Update
Ok, I've reduced the code to absolute barebones. No external constant file, no external library calls. I've copied the full extent of what is recorded in recording mode. I've printed each variable to ensure accuracy. I've included the full object hierarchy:
Set objWin = JavaWindow("label:=<redacted>")
objWin.SetTOProperty "to_class", "JavaWindow"
objWin.SetTOProperty "toolkit class", "javax.swing.JFrame"
MsgBox objWin.GetTOProperty("label")
MsgBox objWin.GetTOProperty("to_class")
MsgBox objWin.GetTOProperty("toolkit class")
Set objDialog = objWin.JavaDialog("label:=<redacted>")
objDialog.SetTOProperty "to_class", "JavaDialog"
objDialog.SetTOProperty "toolkit class", "<redacted>.LoginDialog"
MsgBox objDialog.GetTOProperty("label")
MsgBox objDialog.GetTOProperty("to_class")
MsgBox objDialog.GetTOProperty("toolkit class")
Set objEdit = objDialog.JavaEdit("attached text:=User ID / Ci-Usager")
objEdit.SetTOProperty "to_class", "JavaEdit"
objEdit.SetTOProperty "toolkit class", "javax.swing.JTextField"
MsgBox objEdit.GetTOProperty("attached text")
MsgBox objEdit.GetTOProperty("to_class")
MsgBox objEdit.GetTOProperty("toolkit class")
objEdit.Set "test"
Note the redacted text is to remove identifying elements from the code. They have been triple-checked on my side and are correct.
This still does not work.
However, recording the same does. What gives?
I think you have to mention the full hierarchy while working with the Javaedit field. Try re-writing the code for the function searchField as :
Function searchField(label)
Dim objFrame
Set objFrame = searchWindow(Environment.Value("frameLogin"))
Set searchField = objFrame.JavaEdit("attached text:=" + label) 'Javaedit should be the child of the login window. You had to mention the full hierarchy here
End Function

Microsoft VBScript runtime error '800a01a8' : object required

Hi i have an ASP page that call function with 2 parameters
when i call the function from the asp page i am getting this error
Microsoft VBScript runtime error '800a01a8'
Object required: 'AllPerInfo4xfm(...)'
my code is
set GetAllInv = new GetFunction
set MyOrsk = GetAllInv.AllPerInfo4xfm(ssgr,nat)
my function is
Public Function AllPerInfo4xfm(ssgr,nat)
dim sdir,sdir2,ssec,tlen,ssec2
tlen=len(ssgr)
sql ="Select * from Personal"
myors2.Open SQl,oConn,1,1
set Allperinfo4xf = myors2
end function
did i miss something
please advice
Assuming that AllPerInfo4xfm() does not return an object, loose the Set in
set MyOrsk = GetAllInv.AllPerInfo4xfm(ssgr,nat)
=>
MyOrsk = GetAllInv.AllPerInfo4xfm(ssgr,nat)
Update wrt comment:
If AllPerInfo4xfm() should return a recordset, make sure the function contains a line
Set AllPerInfo4xfm = objRecordset
(replace objRecordset with your variable name; now, of course, the Set in the assignment to MyOrsk is needed)
Update wrt OT's revision:
Given the revised code, both GetAllInv and myors2 should be checked. Are they valid objects when the line is executed?
cf. food for thought

Exception while adding TimeScaleValue MS Project

I'm getting this exception in this code:
Dim TSV As TimeScaleValues
TSV = ActiveProject.Task(ntask).Resources(nresource).TimeScaleData(nStartDate , nEndDate, PjResourceTimescaledData.pjResourceTimescaledActualWork, PjTimescaleUnit.pjTimescaleDays, 1)
TSV.item(1).Add( nMinutes , 1 ) ' nMinutes is the value of time in minutes. The error occours in this line !!!!
When I execute the last line I get this exception
Invalid value for argument.
Error code -2146827187
{Microsoft.Office.Interop.MSProject.TimeScaleValue Add(System.Object, System.Object)}
The estrange thing is that I got this example right from this microsoft reference page.
What I'm trying to do is add a time to time scale on project.
I solved the problem.
I was setting the value in the wrong place.
Seems confuse, but I was trying to get the time scale value from resource, but the right place to set the values is on assignments.
I was doing this..
TSV = ActiveProject.Task(ntask).Resources(nresource).TimeScaleData...
The right code is like:
TSV = ActiveProject.Assignments.TimeScaleData..
For each resource in the task is created one assingment, so teh final code is like:
For Each assignment As Assignment In Task.Assigments
if assignment.Resource.WindowsUserAccount = <desiredAccount> then
tsv = assingment.TimeScaleData..
end if
Next

ArcPad - VBscript - Autopopulate attributes

I am using the following script to grab parcel and address information from one layer to fill the attribute table of a newly created feature.
There is no returned error, but the problem I am having is that there seems to be the wrong information stuck in the memory of recordselect function. No matter where I place a point it gives the same parcel # and address. Or maybe it isn’t actually be performing the IF function properly.
Sub Address
Dim rsCurrentXY
Set rsCurrentXY = Map.Layers("Violations").records
rsCurrentXY.movelast
Dim objXYShape
Set objXYShape = rsCurrentXY.Fields.Shape
Dim pControls
Set pControls= Application.Map.selectionlayer.Forms("EDITFORM").Pages(“PAGE1”).Controls
Dim rsGrid
' Find corresponding map page to the valve point
Set rsGrid = Map.Layers("ACPA_parcels").records
rsGrid.movefirst
Do While Not rsGrid.eof
If rsGrid.fields.shape.Ispointin(objXYShape) Then
pControls("txtAddress").value = rsGrid.Fields("ADD1").Value
Exit Do
End If
rsGrid.Movenext
Loop
' Clean Up
Set rsCurrentXY = Nothing
Set objXYShape = Nothing
Set rsGrid = Nothing
End Sub
(I have another subroutine called "PIN" that would do the exact same thing.)
I have them called when their respective edit boxes in the custom form are activated by the inspector.
Thanks for the help,
Robert
Accessing the EDITFORM via Application.Map.selectionlayer.Forms("EDITFORM") will be problematic. Whenever working with controls on an EDITFORM you should using ThisEvent.Object to discover all your objects. For example, if your event handler is Page_OnLoad then ThisEvent.Object will refer to your current page. You should have code like this:
Dim pPage1
Set pPage1 = ThisEvent.Object
Dim pControls
Set pControls = pPage1.Controls

VB6 execution with database is different when stepping through vs running

I've come across a weird scenario with the following code in a vb6 app:
Private database As dao.Database
Set database = openDaoDatabase([some valid database location], False)
createDBField database, "Table", "FirstRow", dao.dbInteger, 0, "0"
Public Sub createDBField(targetDB As dao.Database, strTable As String, strField As String, dbType As dao.DataTypeEnum, Size As Integer, strDefValue As String)
Dim td As dao.TableDef
Dim fld As dao.field
Set td = targetDB.TableDefs(strTable)
Set fld = td.CreateField(strField, dbType, 0)
If dbType = dao.DataTypeEnum.dbText Or dbType = dao.DataTypeEnum.dbMemo Then fld.AllowZeroLength = True
If strDefValue <> "" Then fld.DefaultValue = strDefValue
td.Fields.Append fld
Set td = Nothing
Set fld = Nothing
End Sub
When I step through, everything works and the new field is added to the database. However, when I simply run the application, the database becomes corrupted due to 'inconsistency'. I added some error handling and now get the error: "Unrecognized database format: [path]".
After searching the Microsoft database, I found a solution: http://support.microsoft.com/kb/238401. I'm using the Microsoft.Jet.OLEDB.4.0 provider, have SP6 installed and have a reference to the Microsoft DAO 3.6 Object Library, but it's still not working!
Any thoughts?
Update:
td.Fields.Append fld is the culprit. After removing all silent error handling, I was able to catch an error: "Run-time error 3343 Unrecognized Database Format". For some reason, I can just step over it though.
I suspect your problem is happening because of the AllowZeroLength property. I suspect the field should be added to the fields collection and the AllowZeroLength property updated.
After
td.Fields.Append fld
put something like the following:
Set tdfField = tabledef.Fields(strField)
Set prp = tdfField.CreateProperty("AllowZeroLength", dbboolean, True)
tdfField.Properties.Append prp
Note the above is aircode and not tested.
That said, it doesn't make a lot of sense to me for a text or MEMO field's AllowZeroLength property to default to True. After all, the front end user can't really visually distinguish between the NULL value and a zero length string value.
I don't see a call to database.close that might be the cause. If your VB app terminates abruptly that might leave the DB in an inconsistent state.
Which line is the error occurring on? Usually when I run into VB errors like this they are timing related. Stepping through gives enough time for something to finish processing. Try adding some sleep commands before the statement that is causing the error.

Resources