Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to assign an array return value
#1
Not Solved Sad 
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
Reply
#2
Not Solved
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)
Reply
#3
Not Solved
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.
Reply
#4
Not Solved
So it took you 9mins straight to solve the problem by yourself! nice Smile
Want to fast track your QTP/UFT Learning? Join our UFT Training Course
Reply
#5
Not Solved
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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Childobject return wrong checkbox count.. VpnQTP 1 2,561 04-09-2015, 09:07 PM
Last Post: babu123
  SQL on oracle database doesn't return a value Bluefields 2 3,056 07-09-2012, 01:23 PM
Last Post: Bluefields
  Return reusable object HelenN 0 4,203 04-20-2011, 08:31 PM
Last Post: HelenN
  VBScript - How to get the Function return value iamsekhar 2 22,332 09-13-2010, 04:16 PM
Last Post: lotos
  How to use Array of Array in QTP dineshb 1 16,399 12-12-2009, 02:00 AM
Last Post: rdemers25

Forum Jump:


Users browsing this thread: 1 Guest(s)