Results 1 to 4 of 4

Thread: [RESOLVED] Saving and Loading arrays? in VB6

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2009
    Posts
    4

    [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:
    1. Dim flag As Integer
    2. Dim path As String, i As Integer
    3. Dim gsngx(1 To 3000) As Single
    4. Dim gsngy(1 To 3000) As Single
    5. Dim gnnumpoints As Long
    6.  
    7. Sub drawlines()
    8. CurrentX = gsngx(1)
    9. CurrentY = gsngy(1)
    10. Circle (gsngx(1), gsngy(1)), 50
    11. For i = 2 To gnnumpoints
    12.     Line -(gsngx(i), gsngy(i))
    13.     Circle (gsngx(i), gsngy(i)), 50
    14. Next i
    15. End Sub
    16.  
    17. Sub Drawcircle(x As Single, y As Single)
    18. Circle (x, y), 50
    19. If gnnumpoints < 3000 Then
    20.     gnnumpoints = gnnumpoints + 1
    21.     gsngx(gnnumpoints) = x
    22.     gsngy(gnnumpoints) = y
    23. End If
    24. End Sub
    25.  
    26.  
    27. Public Sub Form_Load()
    28. Dim i As Integer
    29. flag = 0
    30. r = 0
    31. g = 0
    32. b = 0
    33. End Sub
    34.  
    35. Private Sub mnuopen_Click()
    36. path = UCase$(Trim$(InputBox("Filename", "OpenFile")))
    37. path = "H:\" & path & ".dat"
    38. Open path For Binary Access Read As #1
    39.     Get #1, , gnnumpoints
    40.     For i = 1 To gnnumpoints
    41.         Get #1, , gsngx(i)
    42.         Get #1, , gsngy(i)
    43.         drawlines
    44.     Next i
    45. Close #1
    46. End Sub
    47.  
    48. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    49. flag = 1
    50. Drawcircle x, y
    51. End Sub
    52.  
    53.  
    54. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    55. If flag = 1 Then
    56.    Form1.Line -(x, y), RGB(r, g, b)
    57.    Drawcircle x, y
    58. End If
    59. End Sub
    60.  
    61. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    62. flag = 0
    63. End Sub
    64. Private Sub mnusave_Click()
    65. path = UCase$(Trim$(InputBox("Enter name:", "Save", "bob")))
    66. path = "H:\" + path + ".dat"
    67. Open path For Binary Access Write As #1
    68. Put #1, , gnnumpoints
    69. For i = 1 To gnnumpoints
    70.     Put #1, , gsngx(i)
    71.     Put #1, , gsngy(i)
    72. Next i
    73. Close #1
    74. 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
  •  



Click Here to Expand Forum to Full Width