Micro Focus QTP (UFT) Forums
How to assign an array return value - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: How to assign an array return value (/Thread-How-to-assign-an-array-return-value)



How to assign an array return value - ConstantChange - 01-15-2008

Hi!

First, I have to admit, I actually am a Java guy and regularly lose my temper with VBScript's inconsistancy. So I might have already created a blind spot. But I still dont get this:

I have a function that returns an array (pasted later), and for some reason when I call it and want to assign it to a variable it tells me "Object required". AND NOTHING else (what an excellently accurate error message).

the line that produces the error:

set indices=stringTokenize("1;3;4;6;7;10", ";")

(I tried a dim indices() and dim indices(6) and much more before calling this function).

The function itself works, when I debug it to the end the return value is the correct array, but as soon as it jumps out of the function and should assign the return value to "indices" it comes up with this superweird error message.

Maybe its necessary to see the method in order to help me, so here it is, but I think its pretty irrelevant.

Function stringTokenize(wholeString, delimiter)
dim pos, i, found, lastPos
redim allTokens(0)

pos=1
i=0
found=0
While pos>0
ReDim preserve allTokens(i)
lastPos=pos
pos=instr(lastPos, wholeString, delimiter)
if(pos>0) then
allTokens(i)=mid(wholeString, lastPos, pos-lastPos)
pos=pos+1
else
allTokens(i)=mid(wholeString, lastPos)
end if
found=found+1
i=i+1

Wend
stringTokenize=allTokens
End Function
----------------------------------------

So why do I get this "Object required" error? Which object is required? The Strings surely not...


THANK YOU VERY MUCH!!!
CC


RE: How to assign an array return value - ConstantChange - 01-15-2008

ps.: By the way, if I dont use "set" in front of the assignment (set indices=stringTokenize...), it will run over that line of code but "indices" will just NOT EXIST ! (non existent in the debugger)


RE: How to assign an array return value - ConstantChange - 01-15-2008

PROBLEM SOLVED, THANKS!

thats the way to do it, no "set" and no dim ..()

so now its:

dim indices
indices=stringTokenize("1;2;3;4;5", ";")


that works...maybe I tried all combinations of dim and set, but not this one.


RE: How to assign an array return value - Ankur - 01-16-2008

So it took you 9mins straight to solve the problem by yourself! nice Smile


RE: How to assign an array return value - ConstantChange - 01-16-2008

Thanks Ankur, for looking into this thread. Well, 9 minutes is not honestly correct, as I spent at least 1 hour (well, lets say it felt like that Wink ) just on this single problem beforehand!


Cheers,
CC

ps.: I am very sure I will appreciate this forum a lot in the coming future - as I already do because I dont feel "alone" in this yet pretty isolated qtp world!