Solved

vb.net 2005 Visual Studio Array help

Posted on 2006-10-29
7
699 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:lbsi
  • 3
  • 3
7 Comments
 
LVL 48

Expert Comment

by:AlexFM
Comment Utility
Dim ParmArray() As String         ' class member

In the function:

Redim ParmArray(Records - 1)
0
 
LVL 12

Expert Comment

by:Mamtha1982
Comment Utility
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,Records)

If VS 2003
Redim ParamArray(Records)



0
 

Author Comment

by:lbsi
Comment Utility
Will this allow me to "see" the values I assigned to the Array in the first form from the code in the second form?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 12

Expert Comment

by:Mamtha1982
Comment Utility
yes, but declare that arrays in a module with Public keyword
0
 

Author Comment

by:lbsi
Comment Utility
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.ParameterValues
            Dim ParD As New CrystalDecisions.Shared.ParameterDiscreteValue()
            Dim i As Integer
            For i = 0 To Records - 1
                ParmName = ParmArray(i)
                ParmVal = ParmValue(i)
                Par = RD.DataDefinition.ParameterFields.Item(ParmName).CurrentValues
                ParD.Value = "" & CStr(ParmVal) & ""
                Par.Add(ParD)
                RD.DataDefinition.ParameterFields.Item(ParmName).ApplyCurrentValues(Par)
            Next

     End Sub
End Class

0
 
LVL 12

Accepted Solution

by:
Mamtha1982 earned 500 total points
Comment Utility
assuming that you are doing in 2005....

Public Module Globals
 
    'Declare Arrays and variable to hold record count from DataGridView
     Public ParmArray() As String
    Public ParmValue() 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

        ' Here i added
        Array.Resize(ParamArray,Records)
        Array.Resize(ParamArray,Records)

        '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.ParameterValues
            Dim ParD As New CrystalDecisions.Shared.ParameterDiscreteValue()
            Dim i As Integer

            ' Here no need Records variable, sujest use Length of Array
            For i = 0 To ParamArray.Length - 1
                ParmName = ParmArray(i)
                ParmVal = ParmValue(i)
                Par = RD.DataDefinition.ParameterFields.Item(ParmName).CurrentValues
                ParD.Value = "" & CStr(ParmVal) & ""
                Par.Add(ParD)
                RD.DataDefinition.ParameterFields.Item(ParmName).ApplyCurrentValues(Par)
            Next

     End Sub

End Class

0
 

Author Comment

by:lbsi
Comment Utility
Thanks...all is well now. :)

Have a Good Day,
Ed
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now