Mac querytables - macos

I have written a script which downloads data from yahoo finance into excel using querytable. It should loop through each URL and download the data but it can't get past the second loop and fails at the .Refresh BackroundQuery:=False with the error code 1004 - An unexpected error has occurred.
Here is the code:
rowOffset = 0
url = Worksheets("Yahoo codes").Range("b2").Offset(rowOffset, 0)
Do While url <> ""
With ActiveSheet.QueryTables.Add(Connection:="URL;" & url, Destination:=Worksheets("Yahoo Data").Range("A65536").End(xlUp).Offset(1, 0))
.RefreshStyle = xlOverwriteCells
.SaveData = True
.BackgroundQuery = True
.Refresh BackgroundQuery:=False
'.Refresh
End With
rowOffset = rowOffset + 1
url = Worksheets("Yahoo Data").Range("a2").Offset(rowOffset, 0)
Loop

It looks like you get the first URL from B2 and subsequent URLs from A3...
When you get the error, got to the Immediate Window (Ctl+G) and type
?Worksheets("Yahoo Data").QueryTables(2).Connection
and see if it looks right. If not, I suspect your second url = ... statement is wrong.

Related

HP UFT error: Object required: 'Browsers'

I'm trying to launch a page with Browsers.Item(btChrome).Run(datavalue) and check if the page contains a specific word string that I'm looking for. And I got an error of Object required: 'Browsers'. I'm confused because I was following the tutorial of https://support.smartbear.com/testcomplete/docs/app-testing/web/general/examples/checking-specific-text.html. Can someone please point out where my code goes wrong?
Sub Test(datavalue)
Dim browser, page, str, Obj
Browsers.Item(btChrome).Run(datavalue) 'datavalue is an url
Set browser = Sys.Browser("*")
Set page = browser.Page("*")
str = "*Dashboard*"
If browser.ObjectIdentifier = "chrome" Then
Call aqObject.CheckProperty(body, "innerText", cmpContains, str, False)
Else
Call aqObject.CheckProperty(body, "textContent", cmpContains, str, False)
End If
End Sub

VBscript anomalies

Why does the following work in VBScript (classic ASP)
Dim y: y = rs("file_description")
Dim x: x = (instr(y, "Internal Server Error") <> 0 or instr(y, "Server Unavailable") <> 0) AND instr(y, "RetryCount=9") = 0
But this does not work. It halts execution (without an error number or description!)
dim x: x = (instr(rs("file_description"), "Internal Server Error") <> 0 or instr(rs("file_description"), "Server Unavailable") <> 0) AND instr(rs("file_description"), "RetryCount=9") = 0
Seems strange that simply extracting the rs("file_description") expression into a variable causes the code to work.
I don't understand why.
rs("file_description") can mean the field object or its default property .Value. VBScript picks one or another depending on the context. Because
y = rs("file_description")
does not use Set, y will contain the .Value. To make things clear for the second aproach, use
x = (instr(rs("file_description").Value, ...

manualresetevent.waitone is hanging

I have a windows service with a timer. About 3 times a day the timer uploads files to different ftp servers. I set the timer, upload the files, then set the next time. This worked fine for a while, until I added another ftpserver for uploading files. When uploading to that ftpserver the project hangs at manualresetevent.waitone (even though the folder was uploaded)
Here part of the code, let me know if more is needed.
Dim state As New FtpState
Dim request As FtpWebRequest = DirectCast(WebRequest.Create(target), FtpWebRequest)
request.Method = WebRequestMethods.Ftp.UploadFile
request.Credentials = mycredentials
state.Request = request
state.FileName = fileName
' Get the event to wait on.
waitObject = state.OperationComplete
' Asynchronously get the stream for the file contents.
request.BeginGetRequestStream(New AsyncCallback(AddressOf EndGetStreamCallback), state)
' Block the current thread until all operations are complete.
waitObject.WaitOne()
' The operations either completed or threw an exception.
If state.OperationException IsNot Nothing Then
Throw New Exception(state.OperationException.ToString)
Else
Publish.sendMail("Upload completed for filename:" & fileName & state.StatusDescription)
End If
End If
This ftpserver works a little different than the others that I'm using and I'm not sure if thats the cause of the problem.
Here is the difference: I upload a zip folder (not just files) which can be quite large and soon after it's uploaded, it is being moved from that ftpserver.
(Whereas the other ftpservers leave the files on the ftpserver)
I think this problem only started once the zipfolder got larger.
I know that it is uploaded and then deleted from there.
So if the upload completed, why does it get stuck at waitone?
Here my endstreamcallback function
Private Shared Sub EndGetStreamCallback(ByVal ar As IAsyncResult)
Dim state As ftpState = DirectCast(ar.AsyncState, ftpState)
Dim requestStream As Stream = Nothing
' End the asynchronous call to get the request stream.
Try
requestStream = state.Request.EndGetRequestStream(ar)
' Copy the file contents to the request stream.
Const bufferLength As Integer = 2048
Dim buffer As Byte() = New Byte(bufferLength - 1) {}
Dim count As Integer = 0
Dim readBytes As Integer = 0
Dim stream As FileStream = File.OpenRead(state.FileName)
Do
readBytes = stream.Read(buffer, 0, bufferLength)
requestStream.Write(buffer, 0, readBytes)
count += readBytes
Loop While readBytes <> 0
'Console.WriteLine("Writing {0} bytes to the stream.", count)
' IMPORTANT: Close the request stream before sending the request.
requestStream.Close()
' Asynchronously get the response to the upload request.
state.Request.BeginGetResponse(New AsyncCallback(AddressOf EndGetResponseCallback), state)
' Return exceptions to the main application thread.
Catch e As Exception
Publish.sendMail("Could not get the request stream.")
state.OperationException = e
state.OperationComplete.[Set]()
Return
End Try
End Sub
' The EndGetResponseCallback method
' completes a call to BeginGetResponse.
Private Shared Sub EndGetResponseCallback(ByVal ar As IAsyncResult)
Dim state As FtpState = DirectCast(ar.AsyncState, FtpState)
Dim response As FtpWebResponse = Nothing
Try
response = DirectCast(state.Request.EndGetResponse(ar), FtpWebResponse)
response.Close()
state.StatusDescription = response.StatusDescription
' Signal the main application thread that
' the operation is complete.
state.OperationComplete.[Set]()
' Return exceptions to the main application thread.
Catch e As Exception
Publish.sendMail("Error getting response.")
state.OperationException = e
state.OperationComplete.[Set]()
End Try
End Sub

ASP CDO issue with read receipt request

I am have problems with an older classic ASP application where read receipts are employed in the code. This particular routine has been used for a number of years successfully but recently we have migrated to a new server with Windows 2008 r2, IIS 7.5 and SmarterMail 11.07 client. Now whenever the application attempts to send a server generated email, the SmarterMail logs are showing it successfully receives and authenticates the submission, but seems to terminate or abort the connection without cause and won't send the email without any errors. I'm at a loss here because like I stated, this routine has worked without problems for some time now and if we don't select the "read-receipt" option in the ASP application the email distributes just fine. I have included a shortened version of the code below and mainly looking for validation that the code for all intended purposes should work as is and if anyone may know of similar issues related to this within SmarterMail itself, like some kind of default security setting I am unaware of. Incidentally, if we manually use the SmarterMail webmail interface, we can successfully send mail with read receipts, so I know it should be possible.
- Thank you kindly!
Code Example
set Mail = Server.CreateObject("CDO.Message")
'Basic configuration
Mail.AutoGenerateTextBody = 0
Mail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strHost
Mail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
Mail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = strPort
Mail.Configuration.Fields.Update
Mail.Fields("urn:schemas:mailheader:X-Mailer") = "Custom EMailer"
Mail.Fields.update
'Priority
Mail.Fields("urn:schemas:mailheader:X-Priority") = emPriority
Mail.Fields("urn:schemas:mailheader:X-MSMail-Priority") = emPriorityTxt
Mail.Fields("urn:schemas:httpmail:importance") = emPriority
Mail.Fields.update
'Addressing
With Mail
.From = strFrom
.ReplyTo = strReplyTo
.To = strTo
.CC = strCc
.BCC = strBCc
End With
'Attachments
if len(sfls) > 0 then
if instr(1,sfls,",",1) > 0 then
strAttachments = split(sfls,",",-1,1)
else
strAttachments = sfls
end if
if isarray(strAttachments) then
for x = 0 to ubound(strAttachments)
Mail.AddAttachment strAttachments(x)
next
else
Mail.AddAttachment strAttachments
end if
end if
'Body
Mail.Subject = strSubject
if isHTML then
Mail.HTMLBody = strBody
else
Mail.TextBody = strBodyTxt
end if
'###################################################################
'If this section is included the email will not send, times out or
'connection is terminated, according to the SmarterMail logs
'###################################################################
' Read/Delivery Receipt
if isRead then
Mail.Fields("urn:schemas:mailheader:disposition-notification-to") = rrReplyTo
Mail.Fields("urn:schemas:mailheader:return-receipt-to") = rrReplyTo
Mail.DSNOptions = 14
Mail.Fields.Update
end if
'###################################################################
'Send Message
strErr = ""
bSuccess = False
On Error Resume Next
Mail.Send
If Err <> 0 Then
strErr = Err.Description
else
bSuccess = True
End If
set Mail = nothing
============================================================

Error System.Runtime.InteropServices.COMException

I got a problem with a project I'm making
it's program that gets signature from a wacom
sign pad It works fine at first run then whenever
I try to enter another signature for the second
time it gets this error message
Here is the code:
Dim sigCtl As New SigCtl
Dim dc As New DynamicCapture
Dim res As DynamicCaptureResult
sigCtl.Licence = "AgAZAPZTkH0EBVdhY29tClNESyBTYW1wbGUBAoECA2UA"
res = dc.Capture(sigCtl, "who", "why", vbNull, vbNull)
If (res = DynamicCaptureResult.DynCaptOK) Then
print("signature captured successfully")
Dim sigObj As SigObj
sigObj = sigCtl.Signature
sigObj.ExtraData("AdditionalData") = "VB test: Additional data"
Dim filename As New String("sig1.png")
sigObj.RenderBitmap(filename, 200, 150, "image/png", 0.5F, &HFF0000, &HFFFFFF, -1.0F, -1.0F, _
RBFlags.RenderOutputFilename Or RBFlags.RenderColor32BPP Or RBFlags.RenderEncodeData)
sigImage.Load(filename)
Else
print("Signature capture error res=" & res)
Select Case res
Case DynamicCaptureResult.DynCaptCancel
print("signature cancelled")
Case DynamicCaptureResult.DynCaptError
print("no capture service available")
Case DynamicCaptureResult.DynCaptPadError
print("signing device error")
Case Else
print("Unexpected error code ")
End Select
End If
The error occurs around sigobj.rederbitmap syntax it gives of the System.Runtime.InteropServices.COMException exception
I'm kinda puzzled whats wrong here since it always work at first try
Thanks in advance*strong text*
I had the same problem with a wacom STU-530 device.
What worked for me was to change the filename string each time the user wanted to use another test.
Dim rndm As New Random
Dim serial As Integer = rndm.Next(1, 9999)
Dim str_serial As String = CStr(serial)
Dim filename As New String("sig_" & str_serial.PadLeft(4, "0") & ".png")

Resources