|
-
May 19th, 2009, 04:44 PM
#1
Thread Starter
New Member
[RESOLVED] Saving and Loading arrays? in VB6
Hello all!
I'm new here, in case you couldn't tell. I'm also relatively new to Visual Basic 6.0. So, I apologize if this should have gone in the "Games and Graphic Programming" section or something!
Anyway, let's get down to brass tacks.
I'm working on a MS Paint type program (for a class) and I'm having some trouble saving and loading. This is done using arrays-the program tracks your mouse movements and saves them in an array, then re-draws them when you load. I've done everything I think I'm supposed to--but I end up with a line going from the top left corner to the last place where I mouse-up'd.
Paint Project Code:
Dim flag As Integer
Dim path As String, i As Integer
Dim gsngx(1 To 3000) As Single
Dim gsngy(1 To 3000) As Single
Dim gnnumpoints As Long
Sub drawlines()
CurrentX = gsngx(1)
CurrentY = gsngy(1)
Circle (gsngx(1), gsngy(1)), 50
For i = 2 To gnnumpoints
Line -(gsngx(i), gsngy(i))
Circle (gsngx(i), gsngy(i)), 50
Next i
End Sub
Sub Drawcircle(x As Single, y As Single)
Circle (x, y), 50
If gnnumpoints < 3000 Then
gnnumpoints = gnnumpoints + 1
gsngx(gnnumpoints) = x
gsngy(gnnumpoints) = y
End If
End Sub
Public Sub Form_Load()
Dim i As Integer
flag = 0
r = 0
g = 0
b = 0
End Sub
Private Sub mnuopen_Click()
path = UCase$(Trim$(InputBox("Filename", "OpenFile")))
path = "H:\" & path & ".dat"
Open path For Binary Access Read As #1
Get #1, , gnnumpoints
For i = 1 To gnnumpoints
Get #1, , gsngx(i)
Get #1, , gsngy(i)
drawlines
Next i
Close #1
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
flag = 1
Drawcircle x, y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If flag = 1 Then
Form1.Line -(x, y), RGB(r, g, b)
Drawcircle x, y
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
flag = 0
End Sub
Private Sub mnusave_Click()
path = UCase$(Trim$(InputBox("Enter name:", "Save", "bob")))
path = "H:\" + path + ".dat"
Open path For Binary Access Write As #1
Put #1, , gnnumpoints
For i = 1 To gnnumpoints
Put #1, , gsngx(i)
Put #1, , gsngy(i)
Next i
Close #1
End Sub
I've cleared out some non-important stuff. Code was UNGODLY long.
I have no doubt there's an easier way to go about doing this-maybe a picturebox or something?-but this is how i'm supposed to do it. Like I said, it's for a class.
Can anyone help?
Last edited by XelaisPWN; May 20th, 2009 at 07:21 AM.
Reason: RESOLVED!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|