lbsi
asked on
vb.net 2005 Visual Studio Array help
Good Day
I am having difficulty with my array declaration in my application. One form has my DataGridView on it. It has
a button to generate a report. The form that is loaded from the button click has the Crystal Viewer on it. So to start,
in the generate button I can load the data from my DataGridView into the arrays using this code:
Records = DataGridView.RowCount
Dim ParmArray(Records - 1) As String
Dim ParmValue(Records - 1) As String
Dim i As Integer
For i = 0 To Records - 1
ParmArray(i) = DataGridView.Rows(i).Cells (1).Value. ToString
ParmValue(i) = DataGridView.Rows(i).Cells (2).Value. ToString
Next
In order to share the the Arrays with the second form with the Crystal Viewer so I can build the parameter
list to pass to the report, I put the Array declarations in the Globals module. When I do that,
the Arrays do not get assigned the RecordCount - 1 value to dimension the array.
It seems like a pretty straight-forward idea...share arrays between forms. Is it not possible to do it this way?
Thanks,
Ed
I am having difficulty with my array declaration in my application. One form has my DataGridView on it. It has
a button to generate a report. The form that is loaded from the button click has the Crystal Viewer on it. So to start,
in the generate button I can load the data from my DataGridView into the arrays using this code:
Records = DataGridView.RowCount
Dim ParmArray(Records - 1) As String
Dim ParmValue(Records - 1) As String
Dim i As Integer
For i = 0 To Records - 1
ParmArray(i) = DataGridView.Rows(i).Cells
ParmValue(i) = DataGridView.Rows(i).Cells
Next
In order to share the the Arrays with the second form with the Crystal Viewer so I can build the parameter
list to pass to the report, I put the Array declarations in the Globals module. When I do that,
the Arrays do not get assigned the RecordCount - 1 value to dimension the array.
It seems like a pretty straight-forward idea...share arrays between forms. Is it not possible to do it this way?
Thanks,
Ed
Did you use Public when you declared this Array's(in a module)?
Ex:
Public ParamArray() As String
In your DataGrid form, you have to mention the size of array as below
if VS 2005
Array.Resize(ParamAyyay,Re cords)
If VS 2003
Redim ParamArray(Records)
Ex:
Public ParamArray() As String
In your DataGrid form, you have to mention the size of array as below
if VS 2005
Array.Resize(ParamAyyay,Re
If VS 2003
Redim ParamArray(Records)
ASKER
Will this allow me to "see" the values I assigned to the Array in the first form from the code in the second form?
yes, but declare that arrays in a module with Public keyword
ASKER
Good Morning
Here is what I have:
1) Public declared Arrays in a module along with the variable to assign the recordcount of the DataGridView to.
2) Class EnterParms contains the form with the DataGridView and the GenerateReport button where I am putting the
DataGridView values into the Arrays. Also, shows the ShowReport form.
3) I use the ShowReport Load event to get the Array values to process for the parameters which get passed to the
CrystalReprotViewer.
***When I step into the code for the EnterParms class, the Arrays are not getting dimensioned when I assign the Record
variable with the recordcount of the DataGridView. Is there a better way to do this or am I missing something maybe?
Thanks,
Ed
Public Module Globals
'Declare Arrays and variable to hold record count from DataGridView
Public Records As Integer
Public ParmArray(Records - 1) As String
Public ParmValue(Records - 1) As String
End Module
Public Class EnterParms
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerateReport.Click
Records = DataGridView.RowCount
'Get DataGridView values and load into Arrays
Dim i As Integer
For i = 0 To Records - 1
ParmArray(i) = DataGridView.Rows(i).Cells (1).Value. ToString
ParmValue(i) = DataGridView.Rows(i).Cells (2).Value. ToString
Next
Dim ShowReport As New LBSI_ShowReport
LBSI_ShowReport.Show()
End Sub
End Class
Public Class ShowReport
Private Sub LBSI_ShowReport_Load
Dim Par As CrystalDecisions.Shared.Pa rameterVal ues
Dim ParD As New CrystalDecisions.Shared.Pa rameterDis creteValue ()
Dim i As Integer
For i = 0 To Records - 1
ParmName = ParmArray(i)
ParmVal = ParmValue(i)
Par = RD.DataDefinition.Paramete rFields.It em(ParmNam e).Current Values
ParD.Value = "" & CStr(ParmVal) & ""
Par.Add(ParD)
RD.DataDefinition.Paramete rFields.It em(ParmNam e).ApplyCu rrentValue s(Par)
Next
End Sub
End Class
Here is what I have:
1) Public declared Arrays in a module along with the variable to assign the recordcount of the DataGridView to.
2) Class EnterParms contains the form with the DataGridView and the GenerateReport button where I am putting the
DataGridView values into the Arrays. Also, shows the ShowReport form.
3) I use the ShowReport Load event to get the Array values to process for the parameters which get passed to the
CrystalReprotViewer.
***When I step into the code for the EnterParms class, the Arrays are not getting dimensioned when I assign the Record
variable with the recordcount of the DataGridView. Is there a better way to do this or am I missing something maybe?
Thanks,
Ed
Public Module Globals
'Declare Arrays and variable to hold record count from DataGridView
Public Records As Integer
Public ParmArray(Records - 1) As String
Public ParmValue(Records - 1) As String
End Module
Public Class EnterParms
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerateReport.Click
Records = DataGridView.RowCount
'Get DataGridView values and load into Arrays
Dim i As Integer
For i = 0 To Records - 1
ParmArray(i) = DataGridView.Rows(i).Cells
ParmValue(i) = DataGridView.Rows(i).Cells
Next
Dim ShowReport As New LBSI_ShowReport
LBSI_ShowReport.Show()
End Sub
End Class
Public Class ShowReport
Private Sub LBSI_ShowReport_Load
Dim Par As CrystalDecisions.Shared.Pa
Dim ParD As New CrystalDecisions.Shared.Pa
Dim i As Integer
For i = 0 To Records - 1
ParmName = ParmArray(i)
ParmVal = ParmValue(i)
Par = RD.DataDefinition.Paramete
ParD.Value = "" & CStr(ParmVal) & ""
Par.Add(ParD)
RD.DataDefinition.Paramete
Next
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks...all is well now. :)
Have a Good Day,
Ed
Have a Good Day,
Ed
In the function:
Redim ParmArray(Records - 1)