Call a function with empty argument - windows

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. :(

Related

How to call only a part of the procedure into another vbscript?

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

In bash -- storing method return value

I'm trying to store a value returned from a method like this: var=$(methodName), but the program never enters the method... It's weird because I do the same thing a few lines earlier (alreadyExists-variable in code sample), and it works fine. I had to do this: var='methodName' to make the program enter the method.
It works, so why care? I'm probably making a mistake, and I need to know what it is and learn from it. Let me know if you need more info to answer the question. Thanks!
overwriteOrNot()
{
echo DEBUG
# This debug string does not print if method is called from "local overwrite=$(overwriteOrNot)"
# but prints if method is called from "local overwrite='overwriteOrNot'"
...
}
local alreadyExists=$(studentNumberExists studentNumber)
if $alreadyExists ; then
# local overwrite=$(overwriteOrNot)
local overwrite='overwriteOrNot'
...
If you're using return, then you need to either directly branch on its result:
if overwriteOrNot; then
: "the function returned 0"
else
: "the function returned something other than 0"
fi
...or store the value of $? immediately after running the function:
overwriteOrNot
local overwrite=$?
Note that return can only return a single-byte integer. If you need to pass content which doesn't fit that type, it needs to be either passed on stdout or in a global variable.
The following:
local overwrite='overwriteOrNot'
assigns a string; it doesn't invoke a function. Instead:
local overwrite=$(overwriteOrNot)
You can check the return value from calling overwriteOrNot with the $? variable, or by checking its numeric return value directly in a conditional statement like:
if overwriteOrNot; then
:
fi
If you assign to overwrite, you can also check its value with any valid test condition such as equality, regular expression match, or emptiness. For example:
if [[ "$overwrite" == "foo" ]]; then
:
fi

How do I pass an argument to a PlatonScript procedure

Does anyone know how to pass a local variable to PlatonScript procedure as an argument?
I just don't want to use global variables.
Thanks
When you create a procedure that has parameters you have to declare it like
<p_targetsData>
<![CDATA[START:p_targetsData(testvar1,testvar2)
testvar1 = "test"
testvar2 = 123
RETURN 1 ]]>
</p_targetsData>
when you want to call it and pass the parameters you write
#testvar1:STRING
#testvar2:INTEGER
CALL p_targetsData(testvar1,testvar2)
jPlaton uses calling by reference so after the CALL execution your variables will still have their real value

QTP handling Null values with public functions

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)

Passing array of classes to parameter of action in QTP/VBScript

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

Resources