Link to home
Start Free TrialLog in
Avatar of ex279
ex279

asked on

Visual Representation of Data with MSChart

I'm having trouble representing my data with a line graph.  Eventually I would like to export my data and graph into an HTML format, but I'm not there, yet!  I'm using the MSChart to represent the data.  I need to redim my array because the datafile size will vary.  It could have 2 or 3 results, 500, or higher in the data file.  If I do not redim my array (and statically assign it), it works, but since I need to redim the array, it doesn't and I get the following error: "Run-time error '1101': Bad Function argument".  Is there a way around this or do I need to use something else or try another method?


Private Sub RunStats()

   Dim i As Integer
   Dim NextRecord As Integer
   Dim HostAddress As String
   
   FileNo = FreeFile
   RecLength = Len(MyData(1))
   FileName = App.Path & "\data.dat"
           
   Open FileName For Random As FileNo Len = RecLength
      NextRecord = (LOF(FileNo) / Len(MyData(1)))
      Dim arrRTT
      ReDim arrRTT(1 To NextRecord)
     
      For i = 1 To NextRecord
         Get FileNo, i, MyData(1)
         arrRTT(i) = LTrim(MyData(1).RTT)
         List1.AddItem (arrRTT(i)) 'DATA CHEcK ONLY
      Next i
   Close FileNo

   MSChart1.ChartData = arrRTT

End Sub
Avatar of GivenRandy
GivenRandy

Make sure you Dim as an array (and it is a good idea to specify the type, string in this case):

Dim arrRTT() As String
Avatar of ex279

ASKER

When I do that, I get a "Compile Error: Expected Array"
The shell code worked in my example. Perhaps it is your parenthesis after AddItem? Try this:

List1.AddItem arrRTT(i) ' DATA CHEcK ONLY

Which line is causing the error?
Avatar of ex279

ASKER

The line that is giving me the error is the "MSChart1.ChartData = arrRTT"

As for the array error, it is the "ReDim arrRTT(1 To NextRecord)".  But that is only if I "dim arrRTT as string".  If I just "dim arrRTT", it works fine.
Make sure there are parenthesis after "dim arrRTT":

Dim arrRTT()
Avatar of ex279

ASKER

I still get the same error "Run-time error '1101': Bad Function argument".
Is the data coming in a string of numbers (e.g., "123") or is it binary data? I see that it is getting stuffed into RTT ("arrRTT(i) = LTrim(MyData(1).RTT)"), but it needs to be the right type as well. The chart can convert string data to the numeric equivalent, but not if it is binary. This is another reason to have a type for the array (either string or long or single, whatever is appropriate).

What is the value of NextRecord? You mention that it varies (2, 3, 500, etc.), but did you debug it in this case?
Avatar of ex279

ASKER

NextRecord is actually the total number of records in the file.  NextRecord is a numeric value.  Data is being written into the array.  To test, I can loop a msgbox to echo the contents of the array and it displays it correctly.  If I don't redim the array and initally "dim arrRTT(1 to 10000)", it works, but I don't want to use the memory if I don't need it.  Also, it could go higher than 10000.
Avatar of ex279

ASKER

Is there another way to get data into a line graph (not using MSCHART)?
ASKER CERTIFIED SOLUTION
Avatar of GivenRandy
GivenRandy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ex279

ASKER

This is VB6
Avatar of ex279

ASKER

I'm trying the picture box now.  So far it looks like it's working.

picture1.line (x1,y1)-(x2,y2)
ex279:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
>Post your closing recommendations!  No comment means you don't care.

What about those of us on vacation who just got back?