Using object's innerText - vbscript

The innerText looks like this:
9999
NA 1299
1/1/2015
7:01:35 EST
Cleanup Time
12/31/2015
12/31/2015
I'm trying to work with an object's innerText by doing the following:
Set arr_data = Sys.Browser.("iexplore").Page("...")...
For i = 0 To array_data.length-1
Set element = array_data(i)
Set text = element.innerText //error happens on this line
If InStr(text, "Cleanup Time")<> 0 Then
Log.Message("Found")
Else
Log.Message("Not Found")
End If
Next
The error I am getting is:
Microsoft VBSCript runtime error
Object required:'[string: "9999 IMP 9999"]'
I've also tried indexing by using
Set text = element.innerText(i)
But get a
Unknown runtime error
I've checked the objects in the debugger up to the point of Set text, and everything looks good.

The problem is we are trying to Set text, when we should just be using
text = element.outerText

Related

Convert vbscript into rapid integration flowlanguage

I'm using Pervasive 9.2 and would like to somehow convert the vbscript into pervasives RIFL language. I want to execute the code during a Process where the f(x) component is executed to run the code. As far as the Path to the xml data, I'll be using a Macro defining where the source data is and another to save the file as well.
Here is the vbscript code below:
Set xml = CreateObject("Microsoft.XMLDOM")
xml.async = False
count_var = 1
If xml.Load("c:\folder1\test.xml") Then
For Each accounts In xml.SelectNodes("//Accounts")
For Each account In Accounts.SelectNodes("./Account")
If count_var > 1 Then
Set accountEnum = xml.createNode(1, "Account" & count_var, "")
For Each child In Account.childNodes
accountEnum.appendChild(child.cloneNode(TRUE))
Next
Accounts.replaceChild accountEnum, Account
xml.save("c:\folder1\test.xml")
else
Set accountEnum = xml.createNode(1, "Account" & count_var, "")
For Each child In Account.childNodes
accountEnum.appendChild(child.cloneNode(TRUE))
Next
Accounts.replaceChild accountEnum, Account
xml.save("c:\folder1\test.xml")
End If
count_var = count_var + 1
Next
count_var = 1
Next
End If
Set node = Nothing
Set xml = Nothing
ParseXMLFile(filepath)
documentation here
http://docs.pervasive.com/products/integration/di/rifl/wwhelp/wwhimpl/common/html/wwhelp.htm#href=ParseXMLFile_Function.html&single=true
this will return a DOMDocument Object Type
documentation here
http://docs.pervasive.com/products/integration/di/rifl/wwhelp/wwhimpl/common/html/wwhelp.htm#href=DOMDocument_Object_Type.html&single=true
hope this helps

VBScript calculations - VBscript error - when a data field is NULL or 0

This is the piece of code im having an issue with.
<%=total+((rs("fee_overall")/100)*rs("fee_wip")-rs("fee_rendered"))%>
If any of the data fields are either 0 or NULL then i get a mismatch error
"Microsoft VBScript runtime error '800a000d' Type mismatch: '[string: ""]' "
Any help is apreciated.
Thanks
in this case Zero seems to be ok because you have no division by zero. for null variables the standard solution would be that you check if variables are not null , then do calculations:
if not(isnull(rs("feeoveral")) or isnull( rs("fee_wip")) or isnull(rs("fee_rendered")) ) then
response.write total+((rs("fee_overall")/100)*rs("fee_wip")-rs("fee_rendered"))
else
response.write "bolb"
end if
Try it like this.
Dim fee_over
If (IsNull(rs("fee_overall"))) Then
fee_over = "0"
Else
fee_over = (rs("fee_overall"))
End If
response.write total+((Cint(fee_over))/100)
Also please check that your database record is INT and default 0

Why does this VBS code fail with a "Type mismatch: 'CInt'" error?

I am experiencing difficulty with the following VBS code. It works only sometimes, and even then it fails quickly. Why?
Dim Butt
Set Butt = CreateObject("InternetExplorer.application")
Butt.visible = True
Butt2 = InputBox("Put the link to one hat you would like to snipe.", "Hat Selection")
Butt3 = InputBox("Enter the maximum amount of Robux you will spend on this hat.", "Maximum Payment")
Dim Proace
Set Proace = CreateObject("Microsoft.XMLHTTP")
Proace.Open "GET", "http://www.roblox.com", False
Proace.Send
Do
Do While Butt.Busy
WScript.sleep 200
Loop
St00f = CInt(Replace(Mid(St00f, (InStr(St00f, ">R$")+3), 8), "</b>", ""))
If St00f <= CInt(Butt3) Then
Butt.Navigate "javascript:WebForm_DoPostBackWithOptions(new%20WebForm_PostBackOptions(""ctl00$cphRoblox$TabbedInfo$UserSalesTab$lstItemsForResale$ctrl0$lnkBuyNow"",%20"""",%20true,%20"""",%20"""",%20false,%20true))"
Exit Do
End If
Loop
Do While Butt.Busy
WScript.sleep 200
Loop
MsgBox("Congratulations! Your snipe was successful! You sniped "&Butt2&" for "&Butt3&" Robux!")
Butt.Quit
Set Butt = Nothing
Set Proace = Nothing
WScript.Quit
Error:
Script: C:\Users\John\Downloads\SingleHatSniper.vbs
Line: 14
Char: 1
Error: Type mismatch: 'CInt'
Code: 800A000D
Source: Microsoft VBScript runtime error
Please help me, I'm not that great with VBS. That much is clear, my friend helped me write this.
As you might have known by now, this is where the error occurs
St00f = CInt(Replace(Mid(St00f, (InStr(St00f, ">R$")+3), 8), "</b>", ""))
And that line does these things
InStr that returns the numeric position of the first occurrence of ">R$"
Its then added with 3 to get the index after the string"R$"
Now Mid splits the string St00f with start index after "R$" to a length of 8
Then Replace takes the split string and replaces an occurrence of "</b>" with ""
At last CInt converts the string to an integer or more correctly * converts any number to the variant of subtype Integer*
And you are getting the error at the CInt conversion.
If I were at your place, I will split this line by line by keeping only one function per line and then try something like MsgBox for the output after each line and find what's wrong with that.
The key is the variable St00f and what that variable holds.
Happy Coding :)
The "Type mismatch" error indicates that your Replace(...) did not return a valid numerical string:
>> i = CInt("4711")
>>
>> i = CInt("999999999999")
>>
Error Number: 6
Error Description: Overflow
>> i = CInt("no number")
>>
Error Number: 13
Error Description: Type mismatch
>> i = CInt("")
>>
Error Number: 13
Error Description: Type mismatch
Consider using IsNumeric() before you apply CInt().
CInt can handle betweeen -32,768 and 32,767
Use CLng instead of CInt
Copied from Cint overflow error when value exceeds 100,000+

VbScript FormateDateTime function showing different format for two files

I have got below code, where I am sending the formatted date and time to my XSLT and which is giving a XML as output.
#importXSLT "tcm:228-190529-2048" As expandXSLT
#importXSLT "tcm:228-642694-2048" As renderXSLT
Dim xml, currentDateTime, datLong , datLongTime , fullDate
Set xml = getNewDomDocument()
xml.loadXML TDSE.GetListPublications(3)
expandXSLT.input = xml
Call expandXSLT.addParameter("publication", Component.Publication.Id)
expandXSLT.transform
xml.loadXML(expandXSLT.output)
'WriteOut xml.xml
currentDateTime = now()
datLong = FormatDateTime(currentDateTime, 1)
datLongTime = FormatDateTime(currentDateTime, 3)
fullDate = datLong &" "& datLongTime
renderXSLT.input = xml
Call renderXSLT.addParameter("currentPublishedDate", CStr(fullDate))
renderXSLT.transform
WriteOut renderXSLT.output
Set xml = Nothing
Now above logic for doing date formatting is same for two outputted XML, but suprising I am getting different output for both the files.
First File gives - Sunday, October 23, 2011 8:52:36 AM as output
Second File gives - 23 October 2011 09:14:45 as output.
Please suggest what can be reason as well as solution also, and one more thing if I want output as below for both the file as 23 October 2011 09:14:45 AM
Thanks!!
Before you do the date formatting, try to explicitly set the locale using something like SetLocale(2057).
2057 is UK format which seems to be what you want, otherwise look at this Locale ID Chart to find the correct value.

How to save the active "Word" document in VBScript?

Here I have a small VBS script that helps me append a new line to a table in MS "Word" 2003:
Set wd = CreateObject("Word.Application")
wd.Visible = True
Set doc = wd.Documents.Open ("c:\addtotable.doc")
Set r = doc.Tables(1).Rows.Add
aa = Split("turtle,dog,rooster,maple", ",")
For i = 0 To r.Cells.Count - 1
r.Cells(i + 1).Range.Text = aa(i)
Next
It works fine, but it doesn't save anything. I want it to save the performed changes.
By the method of macro-recording in the "Word" I got this macro command that saves active "Word" document:
ActiveDocument.Save
So, I decided to append this macro to the VBS script above:
Set wd = CreateObject("Word.Application")
wd.Visible = True
Set doc = wd.Documents.Open ("c:\addtotable.doc")
Set r = doc.Tables(1).Rows.Add
aa = Split("turtle,dog,rooster,maple", ",")
For i = 0 To r.Cells.Count - 1
r.Cells(i + 1).Range.Text = aa(i)
Next
ActiveDocument.Save
But it doesn't save anything. What am I doing wrong here?
Have you already tried calling doc.Save after making those changes? If that doesn't work:
The issue is that ActiveDocument doesn't automatically reference what you think it does in VBScript the way it does in Word's VBA.
Try setting a new variable to the active document, like so:
Dim activeDoc
Set activeDoc = wd.ActiveDocument
activeDoc.Save
I think you have to use ActiveDocument.SaveAs("C:\addtotable.doc"); because I can't find any documentation for .Save. SaveAs accepts a second parameter which specifies what format to save it in. Pastebin of the parameters here.

Resources