Home All Groups Group Topic Archive Search About

Help w/ 1st File Access Program

Author
6 Jan 2006 5:56 PM
Confessor
[Ellipses added to defeat word wrapping, improve readability]

Public Class Form1
    Inherits System.Windows.Forms.Form
    Structure PointTemplate
        Dim Latitude As Single
        Dim Longitude As Single
        Dim Elevation As Integer
    End Structure
    Dim MaxPoint As Integer
    Dim Point() As PointTemplate
[Windows Form Designer Generated Code]
    Private Sub Form1_Load(...) Handles MyBase.Load
        If System.IO.File.Exists("C:\...\points.dat") = True Then
            System.IO.File.OpenRead("C:\...\points.dat")
        Else
            System.IO.File.Create("...\points.dat")
        End If
    End Sub
End Class

I'm hoping to store a persistent collection of points on the Earth's
surface (defined by Lat, Long, and Elevation), reading the data from and
writing to a file. Points read from the file will be stored in the Point()
array.

The best logical way to read data from the file into the array would seem
to be as follows, if you can forgive my lack of proper understanding of
file access commands.

For T = 1 to MaxPoint
        Read [line beginning with T] into Point(T).[variables]
Next

MaxPoint would of course, be stored in the file as well, probably at the
beginning.

Am I missing only exact syntax, or is my understanding of file access in
need of a paradigm shift?

Any help with either would be appreciated.

Thanks to everybody in advance,
Confessor

Author
6 Jan 2006 10:42 PM
Cor Ligthert [MVP]
Confessor,

In my opinion is the most easiest way probably to create from your Structure
a Serializable Class and than serialize and deserialize the object(s) you
have instanced from it.

\\\\
<Serializable()> _
Class SomeClass
///

See here a sample for that serializing process.

http://www.vb-tips.com/default.aspx?ID=7ffd296f-9e81-47e6-88dc-61641f5c8d9d

I hope this helps,

Cor