I am trying to write a QTP Script which works as follows
* takes a column from table checks if it is null
if yes
it adds that column name in a variable .
Later that column name will be used to display to user that all such fields are left blank .
Something like this:
Set rsRecordset1 = dbConnection.Execute("select formcd,sndrpstlcd,recppstlcd,sndrcntrycd, from test_data where trk in ('"&tin&"')")
If rsRecordset1.EOF = false Then
Blank_field="blank_fields->"
formcd = rsRecordset1("formcd").value
typcd="formcd"
Call validatenull (typcd,Blank_field)
packaging = rsRecordset1("packaging").value
typcd="packaging"
Call validatenull (typcd,Blank_field)
......
Public function validatenull (typcd,Blank_field)
If (isnull(typcd) )Then
Blank_field = Blank_field & " " & typcd &", "
End If
End Function
Value of blank_Field is expected to catch values as "blank_fields->Form_id,packaging (Considering Form_id, Packaging passes Null values) {It shouldnt add values which are not Null to blank_fields}
In simpler words
ss = Null
call nnn(ss)
Public function nnn(ss)
If isnull(ss) Then
msgbox("yes")
End If
End Function
Has Error that msgbox does not populates But,
ss= Null
nnn(ss)
If isnull(ss) Then
msgbox("yes")
End If
Populates Msgbox as Yes
But I want Case 1 to be working and I do not want to add any more variables to the function name.
IF By making an Array we can do it, please suggest .
It appears your function works fine, but you are passing the wrong values. From your code snippet:
formcd = rsRecordset1("formcd").value
typcd="formcd"
Call validatenull (typcd,Blank_field)
When you call 'validatenull', you are passing the variable 'typecd'. On the previous line, you populate this variable with a string, so it will never be null. It appears what you intended to pass was the variable 'formcd'. Your second call to 'validatenull' does the same thing. Here is your first call modified to use the other variable.
formcd = rsRecordset1("formcd").value
typcd="formcd"
Call validatenull (formcd,Blank_field)
Related
I have a batch script, which is called master.cmd. It accepts 6 arguments.
I want to call a function in this script, for example, the name of the function is plopsl_tka.
In this function, I see this check:
if [%6]==[] ( echo no need to update
It means that if the last parameter is null, print this message.
From my script - lets call it dba.cmd, I want to call to this function plopsl_tka (from master.cmd script), and I want to call it with null argument.
This is what I did (this is my script: dba.cmd):
if [!client!]==[Ct] ( call c:\autoprocess\master.cmd plopsl_tka pk sdeploy1ry_pl_env14 ctrdr cy_pd_env18 !rel_version! ' ')
As you can see, the last & sixth argument is ' '; this is how I thought to call a function with null argument, but it doesn't work. :(
I am working on small VBScript and trying to create scripting.dictionary[]. I have to pass that array of dictionary to a function by ref. I got that function through compiled library. the function definition is below.
public string Update(string name, ref Scripting.Dictionary[] Data, string sRecordId = "")
My lines of code is here
Set objQWS = CreateObject("Dll")
Set X = PassDictionary
objQWS.Update "Name", x, ""
MsgBox "Additional Info Sent"
Function PassDictionary()
Dim objDic
Set objDic = CreateObject("Scripting.Dictionary")
objDic.Add "id", 1
objDic.Add "name", "a"
objDic.Add "extd_price", "b"
objDic.Add "sales_rep", "c"
objDic.Add "opportunity_id", "d"
Set PassDictionary = objDic
End Function
The problematic area is the Update function.
Every time I run the code, on Update function it give me the error "type mismatch". can anybody tell me how can I make that thing working?
You're passing a single dictionary, not an array of dictionaries. Try something like
Set x = PassDictionary
arr = Array(x)
objQWS.Update "Name", arr, ""
Not sure if it'll work, though, since VBScript doesn't really know types, so the array will have the type Variant().
Another thing you could try is to change the type of the parameter from Scripting.Dictionary[] to Scripting.Dictionary, since you're only passing a single dictionary anyway.
I'm working with HP UFT. This tool use VBScript to automatics test.
Is it possible to create new method in function library.
I mean something like this.
Browser("Browser").Page("Page").WebEdit("login").MyMethod()
How can I do that?
Go to the Design menu, and select Function Definition Generator...
You'll get the following UI
Basically this is a helper for RegisterUserFunc.
By selecting the Register to a test object check-box (and which type of test object) the function you add will be available as a regular test object function.
Note that you can override an existing function, for example you can change Set to see if the value is "~today~" add today's date.
Adding User Defined Functions is actually pretty easy: define the function, decide on the object type you wish to add the function to, and use RegisterUserFunc to put it all together:
Function BrokenImage(ImageObject)
BrokenImage = True
ImageObject.WaitProperty "visible", True, 1000
ImageLoaded = False
StartTime = Now()
Do
If ImageObject.Object.naturalHeight > 0 And ImageObject.Object.naturalHeight > 0 Then
BrokenImage = False
Exit Do
End If
If DateDiff("s", StartTime, Now()) > 10 Then Exit Do
Loop While ImageLoaded = False
End Function
RegisterUserFunc "Image", "BrokenImage", "BrokenImage"
Once you've got the function defined, you call it as you would any other object method:
If Browser().Page().Image().ImageBroken() = true Then Print "Broken Image"
You can also add additional parameters which will then be passed to the new method.
I have a function to get data table values for my test, based on the function return value (True or False), I am doing subsequent actions. The function return value is getting passed successfully for the first two runs and it returns a empty value during the 3rd run. The return value of the function is maintained until it comes out of the function.
Please see below the example function call and code. The first two function calls Apple and Orange are working fine. Test is failing for the third functional call Banana.
Call Sample_Function(1,"Apple")
Call Sample_Function(2,"Orange")
Call Sample_Function(3,"Banana")
Function Sample_Function(RowId,SearchCriteria)
Dim DataStatus
DataStatus = Retrieve_Excel_Data(RowId)
If DataStatus = True Then 'It returns a empty value during 3rd run
Msgbox "Sucess"
Else
Msgbox "Failed"
End If
End Function
Function Retrieve_Excel_Data(RowId)
Dim XlsStatus, Source, Target, RowCount
XlsStatus = False
DataTable.AddSheet(Target)
DataTable.ImportSheet "C:\a.xls", Source, Target
RowCount = DataTable.GetSheet(PO_Target_SheetName).GetRowCount
If RowCount < 1 then
XlsStatus = True
Retrieve_Excel_Data = XlsStatus
Else
Retrieve_Excel_Data = XlsStatus
End If
End Function`
What happens when you step through your code on the 3rd run? If you had On Error Resume Next turned on and there was an error executing the Retrieve_Excel_Data function on the 3rd attempt, it would cause the calling routine (in this case, Sample_Function) to move to the next line of code. That could result in the variable DataStatus not getting populated.
I have to modify a VB6 app and am repeatedly beating my head against a wall over control arrays.
I know that the event handler for the array includes its index value and I can set some variable there, but i should be able to directly access the selected radio button in an array of OptionButton. Currently I'm doing this
For i = 0 To optView.Count - 1
If optView.Item(i).value = True Then
currIndex = i
Exit For
End If
Next
Is this really my only option?
Yes, this is our only option. The control array object does not contain any selecting logic (which makes sense, as "selected" might mean different things for different controls). The only change I'd make is replacing the For with For Each.
Another way to do this that I have used. Write a function, and then call the function, passing in the control name, to return the index number. Then you can reuse this in the future especially, if you add it to a module (.bas).
Function f_GetOptionFromControlArray(opts As Object) As Integer
' From http://support.microsoft.com/KB/147673
' This function can be called like this:
' myVariable = f_GetOptionFromControlArray(optMyButtons) 'Control syntax OK
' myVariable = f_GetOptionFromControlArray(optMyButtons()) 'Array syntax OK
On Error GoTo GetOptionFail
Dim opt As OptionButton
For Each opt In opts
If opt.Value Then
f_GetOptionFromControlArray = opt.Index
Exit Function
End If
Next
GetOptionFail:
f_GetOptionFromControlArray = -1
End Function