I've a script named script 1 that creates a text file and stores some string values into it.
I need to call this script script 1 into another script file named script 2 but only part of it (script 1). I don't want to call the part of the script (script 1) that will store string values.
How can I call only part of the script 1 into script 2? I'm using TestComplete to run these scripts.
You can pass some parameter in script 1 which you can check every time before storing some values in file
function script1(flag)
----create text file---
if flag<>false then
--stores some string values--
end if
end function
function script2
Call script1(false)
end function
If you can't make any changes like passing some parameter in script1(as it might be called from other scripts also and then you will have to change signature everywhere), then you can create a global variable and before calling it from script2, assign some value in that variable and check that value in script1.
dim flag=true
function script1()
----create text file---
if flag<>false then
--stores some string values--
end if
end function
function script2()
flag=false
call script1()
flag=true
end function
Hope this solves your problem. Otherwise, share some sample code so that I can understand the scenario better.
This is an example, you can execute all of the "body" content or you can cut some lines or whatever you need.
You put Both files in the same folder
This is the content of Script1.vbs
a=5
msgbox "hello world"
b=3
msgbox cstr(a*b)
This is the content of Script2.vbs
Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile(".\script1.vbs",1,FALSE)
ts.ReadLine
body = ts.ReadLine
ts.Close
Execute body
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 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)
i am facing a vb script run time error saying "wrong number of arguments or invalid property assignment".
'useunit
sub in unita
call unita.testsub(param1,param2)
end sub
'sub in unitb
sub testsub(param1,param2)
.....
end sub
After USEUNIT you need to specify the name of the unit whose functions you will use in this unit. So, change your code in the following way:
unita
'USEUNIT unitb
sub main
dim param1
dim param2
param1="Test"
param2="Complete"
call unitb.testsub(param1,param2)
end sub
unitb
sub testsub(param1,param2)
Log.Message(param1 & param2)
end sub
I believe that
call unita.testsub(param1,param2)
should be
call unitb.testsub(param1,param2)
i found this from the oficial forums
Execute "Call UnitName.SubWithParams(1, ""string"", True)" ' Using syntax with the Call keyword and parentheses
Execute "UnitName.SubWithParams 1, ""string"", True" ' Syntax without the Call keyword and parentheses
res = Eval("UnitName.FunctionWithParams(1, ""string"", True)")
' Inserting parameter values dynamically
strFunctionCall = aqString.Format("UnitName.FunctionWithParams(%d, ""%s"", %s)", 42, "string", CStr(True))
res = Eval(strFunctionCall)
but still donot know how exactly should we pass the parameters
My question involves the use of QTP / VBScript.
Goal: From the qtp main starting file, initialize an array of classes, and pass that array as a parameter to a re-usable action via a parameter.
Problem: I am not able to pass an array of classes to my re-usable action.
Details:
I have two files: “application_main” and “personal_action”.
application_main is the entry point into qtp/vbscript.
personal_action is a re-usable action
Inside application_main, we have a call to InvokeApplication, proceeded by a few other declarations.
I am able to initialize an array and proceed to pass it as a parameter from my application_main to my personal_action:
From application_main:
Dim myArray
myArray = new Array(object1, object2, object3)
RunAction “personal_action”, oneIteration, myInteger, myBoolean, myArray
On the personal_action page, I edit the parameter properties via:
Edit->Action->ActionProperties. I select the Parameters tab.
In it, I have the option to define the amount of incoming parameters and each individual type. These available types seem to be restricted to:
String, Boolean, Date, Number, Password, Any
I set my 1st parameter as: Number
I set my 2nd parameter as: Boolean
I set my 3rd parameter as: Any
Upon running, I am prompted with this:
The type you specified for the ‘myArray’ parameter in your RunAction
statement does not match the type defined in the action.
Question: I am able to pass the Number and Boolean fine, but when an array is involved, qtp/vbscript doesn't seem to handle it well. Why am I not able to pass an array to an action via parameters from the main startup file? This seems like a common and simple task. Could I be so wrong?
Any help is appreciated. Thank you.
As per my knowledge, QTP will NOT allow this. There is no parameter type that can be used to represent an Array. This might be a limitation of QuickTest Professional.
Rather than passing array you can pass the Array elements as a string separated with delimiters.
Example:
"Item1^Item2^............" where "^" is the delimiter
then you can use split function of vb script, to get your array back.
Again doing the same thing with object,we have to give try for this
use lib file in your action ...
Create array public in lib
but in end for any case test or interation vararray=null
rodrigonw.
Sugestion... use function for include your lib in your actions (lib path)
Lib soluction
''######################################LIB"
'lib Passsagem de valores entre array
Dim arrayyy()
Sub setArrayyy(strvalores,redimencionaArray)
On error resume next
tamanho=UBound(arrayyy,1)
If Err.Number=9 then
ReDim arrayyy(0)
redimencionaArray=false
end if
err.Clear
On error goto 0
If redimencionaArray Then
tamanho=tamanho+1
ReDim preserve arrayyy(tamanho)
end if
arrayyy(tamanho)=strvalores
'arrayyy=arrayyy
End Sub
function getArrayyy() getArrayyy=arrayyy End function
''######################################"'Action X
call setArrayyy("X",false)
call setArrayyy("A",true)
call setArrayyy("D",true)
call setArrayyy("B",true)
''######################################'Action y
x=getArrayyy()
for countx=0 to ubound(x)
msgbox x(countx)
next
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