Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Subscript out of range
#1
Solved: 11 Years, 3 Months, 4 Weeks ago
Hi,

I am having trouble retreiving and then updating data from an array.

Here is my problem:
I am trying to get data from a WebTable cell. The data is a date with format "6/11/10 4:35 AM". Now I will have to split this data to get the date value "6/11/10".
Since the value I have to use should be in format of mm/dd/yyyy format so for that i thought of splitting the first index and concatenating the yy value with "20". But thats when I get the error "Subscript out of range: 'sToDate'".

Here is the line of code that I am using:

Code:
sToDate = Split(Browser("ABC").Page("ABC").Frame("fraMgr").WebTable("Table").GetCellData(2, 1), " ")
sToDate(0) = Split(sToDate(0), "/")
sToDate(0,2) = "20" & sToDate(0,2)
The sToDate value is "6/11/10 4:35 AM"

I am getting error in the last line. I even tried checking the value of sToDate(0,2) element but got the same error.
When I saw the value in Watch window, it is perfectly showing me it's value as "10". Attaching screenshot for the same.

PS - My problem is not getting the date in desired format as i know that can be done using CDate function. And in fact i have already done that. But I am not able to understand why I am getting the error for above logic. So this is just to solve my curiosity Smile.


Attached Files
.doc   Array Split.doc (Size: 115.5 KB / Downloads: 104)
Reply
#2
Solved: 11 Years, 3 Months, 4 Weeks ago
Split function will return only zero based one dimensional array. But in 3rd line you are trying to assign the value to a two dimensional array. You can try the following:

Code:
sToDate = Split("6/11/10 4:35 AM", " ")
MsgBox sToDate(0)
sToDate(0) = Split(sToDate(0), "/")
MsgBox sToDate(0)(2)
sToDate(0)(2) = "20" & sToDate(0)(2)
MsgBox sToDate(0)(2)
Reply
#3
Solved: 11 Years, 3 Months, 4 Weeks ago
Guin, Thanks a lot for clarification, this works.

Actually I was trying the two dimensional array because in Watch window I saw the notation QTP used for that element of array which is like "sToDate(0,2)" (this you can see in the attached doc as well).
Reply
#4
Solved: 11 Years, 3 Months, 4 Weeks ago
As an alternative you can use the built in date functions.
Code:
mydate = "6/12/10 10:23 AM"
mymonth = Month(mydate)
myday = Day(mydate)
myyear = Year(mydate)

msgbox "Month: " & mymonth &vbcrlf & "Day: " & myday & vbcrlf &  "Year: " & myyear

No need for multidimensional arrays then.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to count a repeated number in number in particular range gollsrin 1 3,584 04-28-2011, 11:41 AM
Last Post: Saket

Forum Jump:


Users browsing this thread: 1 Guest(s)