Forum Discussion

SamuraiJack's avatar
SamuraiJack
Contributor
15 years ago

VBScript gives 'Object required' error when trying to assign a property value to a variable

but I can save the variable to my Excel spreadsheet fine.



call Log.Message("Data recording started")

set MsExcel = Sys.OleObject("Excel.Application")

set dtaSheet = MsExcel.Worksheets("PolList")


' begin recording data


 


dim iexplore

dim Poltot

set iexplore = Aliases.Sys.iexplore

set page = iexplore.pagePolicyList



set Poltot = page.PolicyTable.RowCount  ** This generates the error



dtaSheet.Cells(tcRw,"A") = page.PolNum.innerText

dtaSheet.Cells(tcRw,"B") = page.DropMyGrange.href

dtaSheet.Cells(tcRw,"C") = page.DropPayMyBill.href

dtaSheet.Cells(tcRw,"D") = page.NavPolSumm.href

dtaSheet.Cells(tcRw,"E") = page.NavBillPay.href

dtaSheet.Cells(tcRw,"F") = page.NavPolDoc.href

dtaSheet.Cells(tcRw,"G") = page.PolNum.href

dtaSheet.Cells(tcRw,"I") = page.BillDetailLink.href

dtaSheet.Cells(tcRw,"J") = page.PolicyTable.RowCount  ** this works fine


 


if (Aliases.Sys.iexplore.pagePolicyList.PayBillBtn.Exists) Then


 


dtaSheet.Cells(tcRw,"H") = page.PayBillBtn.href


 


End If


2 Replies

  • Hi Jack,


    According to VBScript syntax, the Set keyword must be used only when you are assigning an object. When you are working with simple types (such as integer, which is, I believe, returned by the RowCount property), you must not use the Set keyword. Please see the following page for more information:

    http://www.tizag.com/vbscriptTutorial/vbscriptvariables.php


    BTW, if using VBScript is not a requirement for you, you can consider using JScript - the syntax of the scripting language is easier to understand.


  • I had a brain freeze moment with that code..  I fixed it by not setting the variable ahead of time and instead just using the INT returned by the property




    For pn = 0 to (page.PolicyTable.RowCount -1)


    pn = 0 (page.PolicyTable.RowCount -1)