I am new to VBScript and can't figure out why I'm getting an Object Required error with my code. It's very simple right now, I've just begun it:
<%
set fs=Server.CreateObject("Scripting.FileSystemObject")
Dim dateandtime
On Error Resume Next
set dateandtime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
If Err <> 0 Then
' File operation(s) failed, handle the error
response.write(Err.Description)
End If
%>
Why am I not able to set the DateTime? I've set the FileSystemObject for use later in the code FYI. I'm just putting it all in here so you see exactly what I have. I figure it's a simple syntax thing but I can't seem to find the answer anywhere. Thanks for your help!
The first mistake is to use Set when assigning a non-object to a variable. The last entry in the 'Related' list “Object required” when using Set in an assignment deals with it.
>> Set dt = "a string"
>>
Error Number: 424
Error Description: Object required [because Set wants an object to assign]
No Set, no problem:
>> dt = "a string"
>> WScript.Echo dt
>>
a string
Removing the Set will reveal the next problem: Unless you defined a suitable class and an instance named 'DateTime' of your own, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") will fail with the same error 424.
>> dt = Nix.Now.ToString("")
>>
Error Number: 424
Error Description: Object required [to use its .Now member]
Do a search here for ways to format a date in VBScript. (First hit for "[vbscript] format date": date format in VBS)
The () in the .Write call should be removed; they are not parameter list (), but 'pass me per value' (). See this answer and follow the link to Eric Lippert's article.
What about crear your code and just do this?
<%
dateandtime = now()
response.write dateandtime
%>
To use setyou need a Object.
Related
thank you for taking a look on this question. Just wondering if there is a best approach to create description object model at runtime. My code fails
Object doesn't support this property or method: 'Browser(...).page(...).WebButton'
FunctionCreateDescObjAt_RunTime(StrBrowserNme,StrBrwsrTitle,StrObject,StrPgeNme,StrPgtitle,StrObjectName,index)`
'create a description object for Browser & Page`
Set WebBrwsrDesc= Description.Create
WebBrwsrDesc("application version").value= "Internet Explorer.*"
If StrBrowser<>"" Then
WebBrwsrDesc("name").value=StrBrowserNme
WebBrwsrDesc("title").value=StrBrwsrTitle
End If
Set WebPageDesc= Description.Create
WebPageDesc("name").value=StrPgeNme
WebPageDesc("title").value=StrPgtitle
' 'Based on the type of object, execute the condition`
Select Case StrObject`
Case "WebButton"
Set WebBtnDes= Description.Create
WebBtnDes("html tag").value="INPUT"
WebBtnDes("name").value=StrObjectName
WebBtnDes("micclass").value="button"
WebBtnDes("index").value=index
'Browser("title:=.*","name:=.*").page("title:=.*","name:=.*").WebButton(WebBtnDes).fnWebButtonClick
Browser(WebBrwsrDesc).page(WebPageDesc).WebButton(WebBtnDes).click
end select
End Function
I am making a call from action
CreateDescObjAt_RunTime "Account Login","Your Store", "WebButton", "", "Account Login", "Login", "" And this is failing. However if I un comment this line & comment problem line, it works
Browser("title:=.*","name:=.*").page("title:=.*","name:=.*").WebButton(WebBtnDes).fnWebButtonClick
Could you please help me with the right approach? thanks
If you want to set a generic browser and page you can simply use a statement similar to the line you have commented:
Dim objPage : Set objPage = Browser("class:=browser").Page("title:=.*")
The line above will create a page object that you can work with.
Check the parameters being passed to your function to make sure you are correctly identifying your browser and page.
For the part of your actual object, which you want to create at runtime, you need to create a Description object, then look for the ChildObjects of your main object (in this case, your page) and store it to a collection. After that you can check whether or not your object is found. So your Select Case part would be something like this:
Select Case StrObject
Case "WebButton"
' This is just a description of your object, not your actual object
Dim descButton : Set descButton = Description.Create
descButton("html tag").value="INPUT"
descButton("name").value=StrObjectName
descButton("micclass").value="button"
descButton("index").value=index
' In the following statement you are looking for all child objects
' of your page that matches with your description, and storing it
' into the collButton collection
Dim collButton : Set collButton = Browser("class:=browser").Page("title:=.*").ChildObjects(descButton)
If collButton.count > 0 Then ' Now you are checking if any object was found
' There are many ways to get the button object that you want.
' Here I'm just assuming you want the first one, but you could iterate
' into the collection to make sure you have the right one
Dim objButton : Set objButton = collButton(0) ' I'm getting the first item, which is in index 0 of your collection
objButton(0).Click ' This object already have the whole Browser().Page().WebButton() identified, so no need to use it
Else
MsgBox "No WebButton found. Please check your Description object"
End If
' Your other cases...
End Select
MicClass of a Webbutton Can't be button. It should be WebButton
' You are using following
WebBtnDes("micclass").value="button"
It Should be : WebButton
'Anyway Describing Description Object
Set ObjButton=Description.Create
ObjButton("MiCClass").value="WebButton"
ObjButton("name").value=strButtonName
ObjButton("htmlid").value=strHtmlId
Set ObjButton= Browser().page().ChildObject(ObjButton)
I want to insert some information into a database in VB6, but I get runtime error '91'.
My code:
Private sub btn_click()
Fname = txtFname.text
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("Fname") = Fname
Adodc1.Recordset.Update
End sub
The debuger shows error on: Adodc.Recordset.AddNew
You haven't posted the rest of the code as to where the Adhoc1 variable is created etc...
This post suggests that the RecordSet has not been initialized prior to working with it, but it's hard to be more specific without the code.
Runtime error '91' is Object variable or With block variable not set, which is a slightly confusing way to say that your variable contains Nothing.
You either forgot to initialise the Adodc1 properly, or, and this is more likely, you need to initialise Adodc1.RecordSet to something useful (like a Set Adodc1.RecordSet = New RecordSet or related) before you can use it.
By the way you posted the code, I believe that you will populate a Recordset to insert into the database. Try as follows:
sub btn_click()
dim Adodc1 as adodb.recordset
set Adodc1 = new adodb.recordset
Fname = txtFname.text
Rs.Fields.Append "Fname", adVarChar, 20 'adVarChar = text, followed by the amount of characters
Adodc1.open()
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("Fname") = Fname
Adodc1.Recordset.Update
End sub
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
Can someone please tell me why this is tossing a Type Mismatch using Classic ASP error?
If (strPaidByPO = True) OR (arrResult(0) = "1") Then
'Do Stuff
Else
'Do Other stuff
End if
arrResults is an Array and strPaidByPO is a variable.
Thanks,
Before the If statement type the following (I think you may be making assumptions about the Types).
Call Response.Write(TypeName(strPaidByPO) & "<br />")
Call Response.Write(TypeName(arrResult) & "<br />")
Call Response.Flush()
If your variables are of the type you expected you should get the following output
Boolean
Variant()
Also you might receive this if your Array is multidimensional in which case you need to specify all the dimensions.
The other possibility is arrResult(0) contains something other than a String. In which case use TypeName(arrResult(0)) to check what that is.
Try this and see result based on which you can correct your script:
response.write(cStr(strPaidByPO) & "- My strPaidByPO value<br>")
response.write(arrResult(0) & "- My Array value")
If (strPaidByPO = True) OR (cStr(arrResult(0)) = "1") Then
'Do Stuff
Else
'Do Other stuff
End if
but if your strPaidByPO contain values other then true - false (Boolean) you need to review your approach to this completely. For example if strPaidByPO is NULL or empty your script will trough you an error like you described.
I have a very simple query that only returns one record. When I try to get the value out of the only column in the only record, I get "Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record." What's going on here? The code that is causing the error doesn't even execute if RecordCount is 0 and I have verified that the recordset does in fact contain a record.
Code is below. Error is thrown when trying to set strDN. It's so dead simple but I can't figure out where I'm going wrong.
EDITED TO INCLUDE COMMAND
<LDAP://DC=something,DC=com>;(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2)(employeeID=01234567));distinguishedName;subtree
Set adoRecordset = adoCommand.Execute
If adoRecordset.RecordCount > 0 Then
strDN = adoRecordset.Fields("distinguishedName").Value
Set objUser = GetObject("LDAP://" & strDN)
objGroup.add(objUser.ADsPath)
End if
The recordcount property leaves the cursor at the end of the recordset, so you cannot then obtain the record (eof=true), you must movefirst. Use a different cursor type, because the default cursor type is forward only:
'' Assign cursorType that allows forward and backward movement.
adoRecordset.cursorType = 3 ''adOpenStatic
See https://www.w3schools.com/asp/prop_rs_cursortype.asp
I use
If Not adoRecordset.EOF And Not adoRecordset.BOF Then
...
End If
For This Scenario
Try
Set adoRecordset = adoCommand.Execute
If adoRecordset.RecordCount > 0 Then
adoRecordset.MoveFirst 'Move to the first record
strDN = adoRecordset.Fields("distinguishedName").Value
Set objUser = GetObject("LDAP://" & strDN)
objGroup.add(objUser.ADsPath)
End if
-EDIT-
Have a look at the following link. There are some causes listed, and solutions for most of them:
http://classicasp.aspfaq.com/general/why-do-i-get-bof-or-eof-errors.html
[I was wrong about this - thanks, Dave] I believe you need to call adoRecordset.MoveNext (or whatever the call is) before attempting to get the value of a field in the recordset.
Calling adoRecordSet.Requery() after RecordCount request can also help in this situation, if your query isn't that complex to execute it the second time.