CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 1999
    Location
    MD, USA
    Posts
    34

    Creating Data Report using data from an array .......

    Can someone help me with creating a data report using data from an array (2 dim)
    I am not sure how I can display the data in the report. Should I be using text boxes ?

    Thanks !


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: Creating Data Report using data from an array .......

    you can transform you array into an ADO recordset and assign the recordset variable to the DataSource property of your Report.
    You need to manually add the controls to your data report via the data report design window and "Insert Control/Textbox".


  3. #3
    Join Date
    Dec 1999
    Location
    MD, USA
    Posts
    34

    For Lothar Haensler - Re: Creating Data Report using data from an array .......

    Hey Lothar,
    Could you tell me how I can transform the array? I am a beginner and am not very familiar with ADO's.
    I didnt really find any material on transforming to a recordset.

    Thanks !!!



  4. #4
    Join Date
    May 1999
    Posts
    3,332

    For Lothar Haensler - Re: Creating Data Report using data from an array .......

    here is a sample that
    - fills an array
    - transforms that into a recordset
    - passes that rs to a datareport for display

    add a textbox for each "field" (=column) in your array and set the DataField property for each textbox in your datareport to the field name in your recordset.



    Dim arr(0 to 5, 0 to 10) as Integer
    Dim i as Integer
    Dim j as Integer
    ' fill array
    for i = 0 to 5
    for j = 0 to 10
    arr(i, j) = i * j
    next j
    next i
    ' transform into rs
    Dim rs as new ADODB.Recordset
    for j = 0 to UBound(arr, 2)
    rs.Fields.Append CStr(j), adInteger
    next j
    rs.Open
    for i = 0 to UBound(arr, 1)
    rs.AddNew
    for j = 0 to UBound(arr, 2)
    rs.Fields(j).Value = arr(i, j)
    next j
    rs.Update
    next i
    set r.DataSource = rs
    r.Show





  5. #5
    Join Date
    Dec 1999
    Location
    MD, USA
    Posts
    34

    For Lothar Haensler - Re: Creating Data Report using data from an array .......

    Thanks for the help.
    But i am getting an error saying that ' the application is using arguments that are of the wrong type, are out of acceptable range, or are in conflict with one another '.
    The data is going into the array fine.
    But code stops here: vbcode reportrs.Fields.Append l, adVarChar /vbcode

    I'm not sure what I am doing wrong !

    Here is the code used:
    vbcode
    Dim arr(0 to 200, 0 to 40) as string
    Dim i, j, k, l As Integer
    Dim rsReport As Recordset

    ' To store values of the flex grid to an array
    k = 1
    For i = 0 To MSFlexGrid1.Rows - 1
    If (MSFlexGrid1.RowHeight(i) > 1) Then
    l = 1
    For j = 0 To MSFlexGrid1.Cols - 1
    If (MSFlexGrid1.ColWidth(j) > 1) Then
    arr(k, l) = MSFlexGrid1.TextMatrix(i, j)
    'MsgBox Me.MSFlexGrid1.TextMatrix(i, j)
    'MsgBox arr(k, l)
    l = l + 1
    End If
    Next j
    k = k + 1
    End If
    Next i

    ' Transform the array into a recordset
    Dim reportrs As New ADODB.Recordset
    For l = 0 To UBound(arr, 2)
    reportrs.Fields.Append l, adVarChar
    Next l
    reportrs.Open
    For k = 0 To UBound(arr, 1)
    reportrs.AddNew
    For l = 0 To UBound(arr, 2)
    reportrs.Fields(l).Value = arr(k, l)
    Next l
    reportrs.Update
    Next k
    Set RptBudgets.DataSource = reportrs

    ' Open Report
    RptBudgets.Show

    /vbcode


  6. #6
    Join Date
    Dec 1999
    Location
    MD, USA
    Posts
    34

    For Lothar Haensler - Re: Creating Data Report using data from an array .......

    Got it !

    Shd have used adbstr instead of advarchar


  7. #7
    Join Date
    Dec 1999
    Location
    MD, USA
    Posts
    34

    For Lothar Haensler - Re: Creating Data Report using data from an array .......

    I have the report opening up now .
    But I'm having problems in setting the datafield property for the text boxes.


  8. #8
    Join Date
    May 1999
    Posts
    3,332

    For Lothar Haensler - Re: Creating Data Report using data from an array .......

    >But I'm having problems in setting the datafield property for the text boxes.

    what kind of "problems"?

    you just open the report window, right-click and select "Insert Control"/TextBox from the context menu.
    Then go to the properties window and enter the data field name.


  9. #9
    Join Date
    Dec 1999
    Location
    MD, USA
    Posts
    34

    For Lothar Haensler - Re: Creating Data Report using data from an array .......

    Well, For example, I am setting the datafield of one of the textboxes in the report to be:

    [vbcode ] rsreport.Fields.Item(0) [/vbcode]

    This gives me an error saying datafield not found.

    Also, I want the report to have a heading with the name, which may be different at different instances. Do you have any idea how i can pass the variable to the report ? I am trying to pass the variable through code but doesnt seem to work !

    Is there a book or website you refer for data reports? I havent found much material anywhere and dont want to keep bugging you with simple questions :-)


  10. #10
    Join Date
    May 1999
    Posts
    3,332

    For Lothar Haensler - Re: Creating Data Report using data from an array .......

    >rsreport.Fields.Item(0)
    this not a legal VB statement.
    What I meant was: set the DataField Property of the Textbox in the properties Toolbox of the datareport designer window to the name of your field.
    It's kind of hard to explain, when all you have is an ASCII text editor, isn't it?

    >Also, I want the report to have a heading with the name, which may be different at different instances. Do you have any idea how i can pass the variable to the report ?
    you can assign the heading at runtime via the object model of the datareport.

    DataReport1.Sections(1).Controls.Item("heading").Caption = "header"



    I have added a Label control to the heading section of the report.

    >s there a book or website you refer for data reports?
    None that I know of.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured