Get boolean from UFT Checkpoint without throwing error if check fails - hp-uft

I'm using this kind of boolean in my code:
Dim found
found = FileContent("TestFile.docx").Check CheckPoint("TestFile.docx")
If(found) Then
'Do stuff
End If
The problem is I don't want it to throw an error if the check fails.
What shall I do?
Thanks in advance

filesystemobject would most likely be your best bet. You can do a .Exist

Related

VBScript newbie, GetObject 424 Object Required when connecting to application

I am trying to connect to an open application and send command to one of it's DLL functions. Here is the code- the error happens on the the GetObject. What am I doing wrong?
Dim oOL
Dim lcCmd
lcCmd = "'QQWOMOD.TWOAuto', '100',False"
MsgBox lcCmd
On Error Resume Next
'The Next stmt is commented out, but gives the same error as the one that follows it
'Set oOL = GetObject("C:\Program Files (x86)\Component Control\Quantum Control\Quantum.exe", "Quantum.SysMod")
Set oOL = GetObject("Quantum.SysMod")
If oOL is Nothing Then
MsgBox "1- " + Err.Description
MsgBox "1- " + Err.number
End If
MsgBox ("2")
oOL.InspectWO(lcCmd)
MsgBox("3")
A suggestion: comment this line and run the program again.
On Error Resume Next
This line is not allowing you to understand the error because the program will go ahead even though the error is raised.
Welcome to Stack Overflow. I'm still amazed by the number of people who start programming using ancient VBScript, but let's see this through. :)
The first thing you need to do is avoid using On Error Resume Next wherever possible, since this will mask the true cause of your errors. The error you report, Object Required is because oOL has not been set at all due to an error with the line above. If I take your example and allow errors, we'll see that it's complaining about a syntax error stemming from the call to GetObject. I believe you meant to use CreateObject?
Assuming that's the case, you'll have to run it again and see if it works. If not, and you get an error like "ActiveX component can't create object" it means you don't have the necessary DLL installed for Quantum SysMod. You should look at the software's documentation to see about registering it. You can also reference the regsvr32 page.
Again, if you have any other development tools available to you that can load the required component such as, C# or even VB.Net, then you should really try using those instead. VBScript is a terrible language.

VBA application.run, MAc excel 2016

Once again thanks in advance for your help.
I am having trouble using application.run, it does not report any error but the code crashes. The project is big and application.run was the simplest way I found to pass a function as an argument...
I simplified the issue to this:
MsgBox Application.Run("Application.WorksheetFunction.Var_S", ThisWorkbook.Worksheets("Data").Range("B3:B974"))
This is simplified, but I cannot manage to get even this to work.
However the following gives the intended result hence the issue is from the use of application.run and not the var function itself.
MsgBox Application.WorksheetFunction.Var_S(ThisWorkbook.Worksheets("Data").Range("B3:B974"))
Hence I know the issue comes from the way I use application.run. As I said no error is reported but the code stops. nothing is returned and anything after application.run is not executed..
My guess is that I do not have the correct syntax, but I could not find lots of documentations about this. Based on what I read this is supposed to be the correct syntax.
Thanks
Instead of Application.Run you can use
MsgBox CallByName(Application.WorksheetFunction, "Var_S", VbMethod, _
ThisWorkbook.Worksheets("Data").Range("B3:B974"))
Function Var_S returns a value. You're not getting an error because it's running properly. In example #2 you're telling it what to with the returned value. What should it be doing with the response in example #1? If you'd like to simply further as an example, instead the Var_S function, try it with the Now() function, which returns current date: Application.Run "now()" ... again, it runs the function just fine. Application.Run runs a function, whereas MsgBox displays data.

Cannot convert Group Description to String Variable

I have the following code:
Set objHoldGroup = GetObject("LDAP://" & objGroup)
strGroupDesc = (objHoldGroup.Description)
WScript.Echo(strGroupDesc)
The variable strGroupDesc returns nothing when echoed. I can output the description directly but I need it for further processing. Thoughts?
Explanation: Apparently your script sets Option Explicit (good), which you didn't tell us about (bad). This option makes defining variables before you can use them mandatory (good). Normally that would raise an "undefined variable" error, though. Since that doesn't seem to happen with your code, you seem to also have an On Error Resume Next somewhere in your code (very bad), which, again, you chose to keep quiet about (bad).
Next time please don't omit parts of your code that are vital for troubleshooting the problem. And don't use On Error Resume Next.
Issue found: I forgot to Dim strGroupDesc.

compile error: method or data member not found in vb6

Hi all I am a php developer but since working in an organisation I got a work on a vb6 project.
The software is quite old let say atleast 10 year and I don't know vb6 at all. But still I manage to solve some errors but now I stuck on and I didn't get any solution. I have got this error when compiling the project, highlighting this code.
with .Panels(6) = selected.
Public Sub StatusBarDateTime()
'' FrmMain.Stb1.Panels(5) = Time
FrmMain.Stb1.Panels(6) = Format(Date, "dd-mmm-yyyy")
End Sub
and when I delete this line on code it show another error that
Compile error:
Sub or Function not defined
highlighting this line of codes
Private Sub MDIForm_Load()
StatusBarDateTime
End Sub
I assumed that it is declaring the function. so I delete this function also.
Now after deleting this when I compiled againg I got this error saying that
Run time error'481'
Invalid picture
and when I click on debug it shows this line of code
Private Sub Form_Load()
FrmMain.Show
Dim strUser As String
Call Center_Align(FrmLogin)
OpenConnection
strUser = "select * from TMUser order by login_name"
rsUser.Open strUser, conpgdhm, adOpenKeyset, adLockOptimistic
Set CmbUserID = rsUser
CmbUserID = "login_name"
CmbUserID = "login_id"
End Sub
highlihting Set CmbUserID = rsUser line. and now I got nothing.
I don't know how many error may I get after resolving this but that is the next part.
First I have to solve this. I have no idea how to resolve this.
I am banging my head around for two days now, If someone can help me please.
Thanks in advance.
Those were helpful....
The reason it's stopping there is because you are attempting to assign a datareader (or whatever object type rsUser is) as the value to a string or int type (CmbUserID)
You are trying to fit a whole bag of rectangles into a round whole. This is in reference to your latest error only. Based on what I see here, you lack the experience in VB6 to continue without some assistance. I suggest a consultant.
Hope this helps.

VB6 "Invalid use of property" error where the code seems fine

I am having a very strange problem. First, the code.
Private Function ProcessRecord(ByVal rsDocs As ADODB.Recordset) As Variant
Dim rsTemp As ADODB.Recordset
rsTemp = rsDocs
rsDocs = RemoveDuplicateDocs(rsTemp)
Exit Function
The error is occurring on the second line of the function, where rsTemp is set equal to rsDocs. It's saying: "Compile error: Invalid use of property". I've looked for information on this error elsewhere, and all the reports are cases where people either forgot an equal sign, or incorrectly added the "Set" command to the beginning of the line of code. This error makes no sense to me, because it was compiling fine before, and the changes I've made to this project are not even in the class that throwing the error. The code here is identical to the way it was before. Has anyone ever seen an error like this pop up for what seems to be no good reason? Thanks!
You need to use
set rsTemp = rsDocs
since rsTemp is an object.

Resources