Results 1 to 7 of 7

Thread: Help!!! array.

  1. #1

    Thread Starter
    Hyperactive Member nickwrs's Avatar
    Join Date
    Jan 2000
    Location
    Atlanta, Ga
    Posts
    398

    Question

    Okay here is how it goes,

    I have a data tracking program, and it records data to a file, I have decided to allow an option of viewing this data via ms chart during the data tracking.

    But the amount of data is changing and I only know how to add data to mschart via an array, but since I have an undefined amount of data, I can't very well use an array,

    any suggestions or is there a better way to do this?

    I had considered using microsoft excel, but I don't know how to use it to make a chart, and or how to add data to it infinitely.

    Please help.


    Nicholas spencer

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    I may not completely understand your problem, but what I would do is to first find out how may records are going to be added to the array, dimension the array accordingly, and then interface with mschart (which I've never done).

  3. #3

    Thread Starter
    Hyperactive Member nickwrs's Avatar
    Join Date
    Jan 2000
    Location
    Atlanta, Ga
    Posts
    398
    That is the point, I don't know the eventual amount of records, there for I cannot dimension an array.

    I am looking for another solution.


  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Why don't you know the number of records? Could you create a trailer record for the file and write the number of records to it? Then when you open the file, read the last record first and then dimension the array. If I'm still off the mark, email me and I'd be happy to "talk" with you about it.

  5. #5
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    To Clairfy

    Is the plan to have the chart update dynamically while the data is "coming in" so to speak?

    Or will the user have to hit a refresh button to get the chart to update?

    The data being tracked is not recorded, only the tracking information is this correct?

    ON your comment about only knowing how to add data via an array, I took an example out of the help for MS Chart and slightly ammended it to give the following example.

    Code:
    Private Sub Command2_Click()
      With MSChart1
        Dim column, row, index1, index2, index3, index4 As Integer
        .RowCount = .RowCount + 1
        .row = .RowCount
        .Data = .RowCount * 7.5
      End With
    End Sub
    Private Sub Command1_Click()
      With MSChart1
        ' Displays a 3d chart with 8 columns and 8 rows
        ' data.
        Dim column, row, index1, index2, index3, index4 As Integer
        .chartType = VtChChartType3dBar
        .ColumnCount = 1
        .RowCount = 8
        For column = 1 To 1
          For row = 1 To 8
            .column = column
            .row = row
            .Data = row * 10
          Next row
        Next column
        ' Use the chart as the backdrop of the legend.
        .ShowLegend = True
        .SelectPart VtChPartTypePlot, index1, index2, index3, index4
        .EditCopy
        .SelectPart VtChPartTypeLegend, index1, index2, index3, index4
        .EditPaste
      End With
    End Sub
    Please don't mention the variable names and the pointless for next loop - as I said I ripped it out of the help and used it more or less as is.

    If you create a form with an MS Chart, Command1 and Command2, try hitting command1 which will update the chart with some data.

    Then each time you hit command2, the data will get a new row added.

    Obviously you would want this to be done on a timer event to give the effect of real time updates...

    Does this help in any way?

    Regards
    Paul Lewis

  6. #6

    Thread Starter
    Hyperactive Member nickwrs's Avatar
    Join Date
    Jan 2000
    Location
    Atlanta, Ga
    Posts
    398

    Cool Thanks, I'll try it.

    That's sounds reasonable, I'll try it!! :-)

  7. #7
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    Do you know about Redim?

    I do not fully understand what you are doing, but do you know about Redim?

    Redim allows you to change the dimensions of an array. It has an option which allows making an array larger without losing data already in the array.

    Perhaps you could work with an array that you Redim as required, and an array into which you read new data. Read more data into second array, Redim the other array, copy data from second to first. Repeat as often as required.

    I copied the following from my MSDN Library documentation.

    To create a dynamic array

    Declare the array with a Public statement (if you want the array to be public) or Dim statement at the module level (if you want the array to be module level), or a Static or Dim statement in a procedure (if you want the array to be local). You declare the array as dynamic by giving it an empty dimension list.
    Dim DynArray()

    Allocate the actual number of elements with a ReDim statement.
    ReDim DynArray(X + 1)

    The ReDim statement can appear only in a procedure. Unlike the Dim and Static statements, ReDim is an executable statement — it makes the application carry out an action at run time.

    ReDim [Preserve] varname(subscripts)

    Redim uses sames syntax as Dim. It has a "Preserve" option if array contains data when Redim is executed.

    Hope the above helps.




    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

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