Graphing with VB (1 Viewer)

mrssevans

Registered User.
Local time
Today, 08:36
Joined
Nov 15, 2001
Messages
190
I am needing to make a graph using VB and I have some of the code, but I am getting a few errors and hoping someone could help troubleshoot. Here is what I am being asked to do:
1. Open the file.
2. Read the data a line at a time into an integer array for N total items.
All of the numbers will be positive; keep track of the largest value.
3. Close the file.
4. Set up to do a bar graph of the N items; you can use the line method on
the form to draw a colored box and fill it in. Setup a total width of 100
and a height of 100 for your form, and use a width for each bar of 100/N.
You can do a FOR loop for I = 1 to N, and the color of the Ith bar can
just be QBColor( I mod 15 + 1). Make the height of each bar relative to
the Ith value read from the file, with the values scaled so the max value
is shown as 100. You can use
Line (x1,y1)-(x2,y2),color,BF
where the BF means to draw a box instead of a line, and fill it in with
the color from the previous argument.

Here is my code:
Option Explicit
Private Sub Form_Load()
Dim mx As Double
Dim n As Integer
Dim x(0 To 1000) As Integer
Dim k As Integer
Dim wd As Integer
n = 0

Scale (0, 100)-(100, 0)
Open "a:\data.dat" For Input As #1

Do While Not EOF(1)
n = n + 1
Input #1, x(n)
If x(n) > mx Then mx = x(n)
Loop
Close #1

'Scale Point
For k = 1 To n
x(k) = 100 * x(k) / mx
Next
wd = 100 / n

For k = 1 To n
Line ((k - 1) * wd, x(k))-(k * wd, 0), QBColor(8), BF
Next

End Sub
Please help!
 

Users who are viewing this thread

Top Bottom