array() problem

StealthRT
09-02-2009, 07:20 PM
Hey all, i am having problems with trying to figure out how to go about fixing this string up for an array.

This code works just fine:

TitleArray = Array("test1", "test2", "test3", "test4", "test5", "test6")
DataArray = Array(34, 53, 12, 18, 55, 2)
NumOfItems = UBound(TitleArray) + 1

However, once i convert that test stuff to what i am accually going to be using (data from my database), it seems to not work out at all. It only shows one value on the chart instead.

Public TitleArray As Variant
Public DataArray As Variant
Public NumOfItems As Integer
Dim tempTitleArray As String
Dim tempDataArray As String
Dim recCount As Integer

Do Until .EOF
If x <> recCount Then
tempTitleArray = """" & !itemName & """" & "," & tempTitleArray
tempDataArray = !itemPriceTotal & "," & tempDataArray
Else
tempTitleArray = tempTitleArray & """" & !itemName & """"
tempDataArray = tempDataArray & !itemPriceTotal
End If
x = x + 1
.MoveNext
Loop

TitleArray = Split(tempTitleArray, ",")
DataArray = Split(tempDataArray, ",")
NumOfItems = UBound(TitleArray) + 1

I have also tried:

TitleArray = Array(tempTitleArray)
DataArray = Array(tempDataArray)

But i still get only one value... What is it that i am doing wrong?? :confused:

Thanks for your time,

David

vb5prgrmr
09-02-2009, 08:01 PM
try...

Public TitleArray() As String
Public DataArray() As String

jerome_gail26
09-02-2009, 08:26 PM
Public TitleArray As Variant
Public DataArray As Variant

These are array right?
As i know, this should be declare as
Public TitleArray() As Variant
Public DataArray() As Variant

kassyopeia
09-03-2009, 05:07 AM
I don't think that's the problem, Variants can hold arrays just fine:

Dim v As Variant
v = Split("1,2,3", ",")
Debug.Print v(LBound(v))
Debug.Print v(UBound(v))

Maybe your temp* strings aren't what they should be?

Anyway, there's no need to use these strings at all. You can declare the arrays as suggested by vb5, then ReDim them to (1 To recCount), and write the item* values directly to *Array(x) inside the Do-Loop.

mkaras
09-03-2009, 06:18 PM
...and following from the previous post save all the processing cycles involved doing the Split()'s to reseparate the data after its been pasted together.

mkaras

jerome_gail26
09-03-2009, 08:54 PM
My mistake. Since temp* as string is the variable holding values this should be declared as array

Here is a sample code:
Sub SomeArray()
Dim va As Variant
Dim v(5) As String

a = 0
Do While a < 5
v(a) = a & "," & a
Debug.Print v(a)
a = a + 1
Loop

Debug.Print "AFTER SPLIT"
For i = LBound(v) To UBound(v) - 1
va = Split(v(i), ",")
Debug.Print "LBound = " & va(LBound(va))
Debug.Print "UBound = " & va(UBound(va))
Next
End Sub


OUTPUT Will be:
0,0
1,1
2,2
3,3
4,4
AFTER SPLIT
LBound = 0
UBound = 0
LBound = 1
UBound = 1
LBound = 2
UBound = 2
LBound = 3
UBound = 3
LBound = 4
UBound = 4


Good Luck
Jerome and Gail

dannydesiliva
09-05-2009, 05:29 AM
Ok, so the way the second post is written can not be used in its entirety. the variable currentPage is actually assigned a value further down the page (of code) outside of the function init() and then the iframe.src is set to theIframe.src = pageArray[currentPage]; before the iframe is launched also outside the function init().

I have tried every way I know to return pageArray from the function but when I do an <script type="text/javascript">alert(pageArray);</script> from within the <div> tag that holds the iframe, I get a blank alert box.

This leads me to believe the pageArray is empty or I'm not doing something correctly (most likely). So, how do I return pageArray from the function so it can be used correctly? Since it's defined as a global (outside the function), I would have thought the value would be available. So what am I missing?

Thank you again,

M.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum