PDA

View Full Version : Passing Array



taporctv
06-27-2007, 05:55 AM
I need help passing my array of Integers from my Userform command button event to a chart event. I tried passing it to a separate sub procedure and use the chart event to get my array from the sub procedure. The logic behind this was wrong from what I coded. Whats the correct way of passing this array to the chart event. I'm trying to avoid using global varaibles.

mdmackillop
06-27-2007, 06:02 AM
Can you post your code?

taporctv
06-27-2007, 06:21 AM
Here's the command button event on the userform with an array
Private Sub GenerateCommandButton_Click()
' Array Declaration
Dim queryArray() As Integer
' Hide user form
UserForm1.Hide
Application.ScreenUpdating = False
GenerateCommandButton.Enabled = False
Sheets("Sheet2").ResetCommandButton.Enabled = True

' Loop through listbox to determine which items were selected
Dim Item As Integer

For Item = 0 To QueryListBox.ListCount - 1
If QueryListBox.Selected(Item) Then
Select Case Item
Case 0
Query1
CalcPercentage
ReDim Preserve queryArray(Item + 1)
queryArray(Item) = 1
Case 1
Query2
CalcPercentage
ReDim Preserve queryArray(Item + 1)
queryArray(Item) = 2
Case 2
Query3
CalcPercentage
ReDim Preserve queryArray(Item + 1)
queryArray(Item) = 3
Case Else
QueryListBox.Selected(Item) = False
End Select
End If
Next

' Pass the array
PassArray queryArray
Sheets("Sheet2").Select

End Sub

Thats all I really have for now. I tried passing it to a sub procedure and it worked. But my Problem was how do i pass the array from the sub procedure to the chart event? Function, Sub Procedure?