View Single Post
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: can someone help me with saving my data in a file program?

 
0
  #7
Dec 8th, 2008
You mean the data entry form is the "main" form? You can set menu item to disabled (Enabled = False).

Or you don't even have to do that. If the user selects "Open Summary" (and the file is empty) the user gets an empty summary form.

Here's a fixed "Read Data"-button, which checks first that the file exists. It also closes the StreamReader, a minor bug in my previous posting:
  1. Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
  2. '
  3. Dim i As Integer
  4.  
  5. AutoCount = -1
  6. If Not My.Computer.FileSystem.FileExists(FileName) Then
  7. Exit Sub
  8. End If
  9. Try
  10. autoStreamReader = New StreamReader(FileName)
  11. Do Until autoStreamReader.EndOfStream
  12. AutoCount += 1
  13. ReDim Preserve Autos(AutoCount)
  14. Autos(AutoCount).Model = autoStreamReader.ReadLine
  15. Autos(AutoCount).Manufacturer = autoStreamReader.ReadLine
  16. Autos(AutoCount).Year = autoStreamReader.ReadLine
  17. Autos(AutoCount).VIN = CInt(autoStreamReader.ReadLine)
  18. Loop
  19. Catch ex As Exception
  20. ' Handle exception
  21. Finally
  22. autoStreamReader.Close()
  23. End Try
  24. '
  25. For i = 0 To AutoCount
  26. ComboBox1.Items.Add(Autos(i).VIN)
  27. Next i
  28. '
  29. End Sub
Reply With Quote