Plotting points in vb.net

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a routine that calculates time vs temperature for a process. It
generates x,y points that I need to plot. The number of points to be plotted
varies, so I want to dynamically build the list of plot points at runtime.

I have tried using a point array, but the problem I run into is that the
points all have to be entered when the point array is dim'ed. I would like a
method by which I can add points, similar to building or concatenating a
string, as each calculation loop executes.

Does anyone have any ideas or sample code?

Thanks.
 
Mark Lancaster said:
I have a routine that calculates time vs temperature for a process. It
generates x,y points that I need to plot. The number of points to be plotted
varies, so I want to dynamically build the list of plot points at runtime.

I have tried using a point array, but the problem I run into is that the
points all have to be entered when the point array is dim'ed. I would like a
method by which I can add points, similar to building or concatenating a
string, as each calculation loop executes.

Does anyone have any ideas or sample code?

Thanks.

Not sure I understand why you say the points need to be entered when the
point array is dim'ed. Can't you create a dynamic array and add elements as
needed?
If that is what you want, why not use an ArrayList?

Or, just roll your own. Create a dynamic array. Give it a base size. Have a
variable track the usable contents. If you fill up your array, expand it a
resonable amount. Pretty much the same thing as a simple ArrayList.

'====================
Dim pointList() As Point
Dim numPoints As Integer
Dim tmpPoint As Point

'Set pointList to a base size of 100
ReDim pointList(99)
'Actual number of valid items
numPoints = 0

'Query data...
tmpPoint = New Point(x, y)
pointList(numPoints) = tmpPoint
numPoints += 1
'Have we filled the current array?
If numPoints > pointList.GetUpperBound(0) Then
'Expand it by 100
ReDim Preserve pointList(numPoints + 100)
End If
'loop...

'Deal with data
'Loop though the actual number of usable points
For idx As Integer = 0 To numPoints - 1
tmpPoint = pointList(idx)
'Plot Point...
Next

'OR, we could have resized the array to fit the contents
ReDim Preserve pointList(numPoints - 1)
'Plot Points...
'====================


Or, did I misunderstand your question?

Gerald
 
Try something like this . . .

Dim p As New Point(10, 20)

Dim v As Point

Dim myCol As New Collection

For i As Int16 = 0 To 10

myCol.Add(p)

Next

For Each v In myCol

Debug.WriteLine(v.ToString)

Next
 
Gerald,

Thanks for the help. I had a similar approach but it did not work because I
did not know about the ReDim command. You are right this should work fine.

Many thanks.

ML
 
Mark Lancaster said:
Gerald,

Thanks for the help. I had a similar approach but it did not work because I
did not know about the ReDim command. You are right this should work fine.

Many thanks.

ML

If this is the sort of approach you are looking for, then I recommend you
use the ArrayList object. It does the same thing as the code, and more.

Gerald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top