Hi i am new to VB Scripting, I have a problem to declare an array in QTP. I am using a variable to declare an array which is come in runtime.Example:Dim variable1 - declare the variable using dimvariable1 = "senthil" - assign the value which is come in run timeDim variable1 (10) - declare the dynamic array using dimvariable1 (1) = "kumar" - store the value in arrayvariable1 (2) = "chandru" - store the value in array This is the way i tried, but it show the error message like "Name redefined", Is there any possible options available for this, plz send me.

Questions by p_senthil   answers by p_senthil

Showing Answers 1 - 17 of 17 Answers

sri

  • Apr 19th, 2006
 

you must give different name's for Variable and Array. 

  Was this answer useful?  Yes

Sri

  • Apr 19th, 2006
 

you must maintain different name's for Variable and Array.

you can't take same flight ticket at a time. if you can you will get this problems.

  Was this answer useful?  Yes

Hi sri

Thanks fro ur comments, from ur comments i got answer for my problems, i am really very sorry, i misunderstand ur comments, i have another problems in array is to pass the parameter in variable to array.

Example:

Dim myname

Dim myarray(100)

myname = "arra_para"

myarray(myname) = "senthil"   ' pass the parameter by variable

Its like myarray("arra_para") = senthil

Please help me about this problem for how to pass parameter to array

cheers

senthil

  Was this answer useful?  Yes

Sri

  • Aug 8th, 2006
 

Array is access by script value. this value always represent an integer. in ur case try this :

VarName = 1

ArrName(VarName)="Senthil"

u can also use FOR loop to pass more than one value in an Array.

  Was this answer useful?  Yes

jag

  • May 4th, 2007
 

Hi,

Try to use declare

Dim variable1Arr () 
 public varOne as integer

Inside the function

Redim variable1Arr(varOne)

Now your array value is passed with an integer.

Now write

variableArr(1)  = " Suresh"
variableArr(2) = "Ramesh"


'Why iam giving Redim option means, you said, you want to declare dynamic array.

  Was this answer useful?  Yes

ritesh

  • Aug 8th, 2007
 

Now you are using the following script


Dim myarray(30)

myarray(0) = "raj"
myarray(1) = "singh"


msgbox myarray(0) & myarray(1)
in message box you can see the both value and use this for further action.

  Was this answer useful?  Yes

You can daeclare a variable as under and then use it as an array:

dim a
a=Array("kumar","chandru","abcd", "efghijkl")

You can test it like:
document.write(a(0))


output:  kumar

Or

document.write(a(1))


output:  chandru

Hope it helps,

Karim

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions