Home All Groups Group Topic Archive Search About

VB2005 structures to file

Author
21 Apr 2006 3:50 PM
Galen Somerville
And yet another VB6 to VB2005 problem. All helpful suggestions appreciated.

As you can see in the code below, my structures use fixed length strings and
known array sizes. Consequently I can save to files as a large byte array.

This is a series of Lectures where there is a capacity for 8 instructors
with up to 8 lectures each. So a parameters file made from glctInstTable is
2,232 bytes.

The 64 lectures, for the above, each consist of 100 lecture steps each. This
creates a 211,200 byte lecture file.

At the start of the program all parameters are read in. Only a specific
lecture is read in when required, as shown in last item below.

During a program run, if changes are made, they can be written back to the
files on the fly.

Now the problem. I can initialize the array sizes when the program first
calls for reading in the lectures etc. But I do not want to initialize as
fixed length strings. But with variable length strings I can't write a
simple byte array to a file.

There would be no way to use simple math to find a lecture position in such
a file. I would like to avoid using a database approach.

I could pad all strings to a fixed size when writing the file and then trim
(unpad) when reading in the file. This would, of course, be a pain in the
neck.

HELP !!!

GalenS


TYPE DECLARATIONS
'   Lecture structures
Private Type ulctLectStruc
    FilNam As String * 25
    BPMRate As Integer
    PgmTyp As Byte
    VolLvl(4) As Byte
End Type
Public glctLecture(99) As ulctLectStruc

Private Type ulctInstrStruc
    InstName As String * 15
    Password As String * 8
    LectName(7) As String * 30
    Quiz(7) As Integer
End Type
Public glctInstTable(7) As ulctInstrStruc

Public Type stcLectures
    InstSelect As Boolean    'Instructor selected
    LectSelect As Boolean    'Lecture selected
    InstNum As Integer     'Current instructor #
    LectNum As Integer     'Current lecture #
    QuizNum As Integer     'Current quiz #
    LectEdit As Boolean      'force edit
    Passwd As Boolean      'password received
    Step As Integer      'Current active step
    BPM As Integer   'current lect step BPM
    Active As Boolean    'Lecture is in use
    Advance As Boolean       'Advance or backup direction
    PgmType As Byte     '0=Film  6=Resp  11=Vet
End Type
Public gLect As stcLectures

OPENING THE LECTURE AND PARAMETER FILES
    Temp1 = Len(glctLecture(0)) * 100
    Temp2 = Len(glctInstTable(0))
    sFile = clsRes.LoadResStgA(401)    'lct file
    strCurrFile = gstrPgmPath & sFile
    On Error GoTo ErrorHandler  ' Enable error-handling routine.
    lctFile = FreeFile
    Open strCurrFile For Random Access Read Write As #lctFile Len = Temp1  '
Open file for input.
    sFile = clsRes.LoadResStgA(400)    'par file
    strCurrFile = gstrPgmPath & sFile
    parFile = FreeFile
    Open strCurrFile For Random Access Read Write As #parFile Len = Temp2  '
Open file for input.


READING THE PASSWORD PROTECTED PARAMETERS FILE INTO STRUCTURES
    On Error GoTo ErrorHandler  ' Enable error-handling routine.
    For Index = 0 To 7 Step 1
        Get #parFile, Index + 1, glctInstTable(Index)
        strTemp = glctInstTable(Index).Password
        For Inner = 1 To 8 Step 1
            intTemp = Asc(Mid$(strTemp, Inner, 1)) Xor bytCode(Inner - 1)
            Mid$(strTemp, Inner, 1) = Chr$(intTemp)
        Next Inner
        glctInstTable(Index).Password = strTemp
    Next Index


READING IN THE DESIRED LECTURE (OUT OF 64) TO LECTURE STRUCTURE OF 100 STEPS
    On Error GoTo ErrorHandler  ' Enable error-handling routine.
    LectFilePosition = (gLect.InstNum * 8) + gLect.LectNum + 1
    Get #lctFile, LectFilePosition, glctLecture

Author
21 Apr 2006 5:27 PM
Mythran
Show quote Hide quote
"Galen Somerville" <galen@community.nospam> wrote in message
news:e16MVtVZGHA.508@TK2MSFTNGP02.phx.gbl...
> And yet another VB6 to VB2005 problem. All helpful suggestions
> appreciated.
>
> As you can see in the code below, my structures use fixed length strings
> and known array sizes. Consequently I can save to files as a large byte
> array.
>
> This is a series of Lectures where there is a capacity for 8 instructors
> with up to 8 lectures each. So a parameters file made from glctInstTable
> is 2,232 bytes.
>
> The 64 lectures, for the above, each consist of 100 lecture steps each.
> This creates a 211,200 byte lecture file.
>
> At the start of the program all parameters are read in. Only a specific
> lecture is read in when required, as shown in last item below.
>
> During a program run, if changes are made, they can be written back to the
> files on the fly.
>
> Now the problem. I can initialize the array sizes when the program first
> calls for reading in the lectures etc. But I do not want to initialize as
> fixed length strings. But with variable length strings I can't write a
> simple byte array to a file.
>
> There would be no way to use simple math to find a lecture position in
> such a file. I would like to avoid using a database approach.
>
> I could pad all strings to a fixed size when writing the file and then
> trim (unpad) when reading in the file. This would, of course, be a pain in
> the neck.
>
> HELP !!!
>
> GalenS
>
>
> TYPE DECLARATIONS
> '   Lecture structures
> Private Type ulctLectStruc
>    FilNam As String * 25
>    BPMRate As Integer
>    PgmTyp As Byte
>    VolLvl(4) As Byte
> End Type
> Public glctLecture(99) As ulctLectStruc
>
> Private Type ulctInstrStruc
>    InstName As String * 15
>    Password As String * 8
>    LectName(7) As String * 30
>    Quiz(7) As Integer
> End Type
> Public glctInstTable(7) As ulctInstrStruc
>
> Public Type stcLectures
>    InstSelect As Boolean    'Instructor selected
>    LectSelect As Boolean    'Lecture selected
>    InstNum As Integer     'Current instructor #
>    LectNum As Integer     'Current lecture #
>    QuizNum As Integer     'Current quiz #
>    LectEdit As Boolean      'force edit
>    Passwd As Boolean      'password received
>    Step As Integer      'Current active step
>    BPM As Integer   'current lect step BPM
>    Active As Boolean    'Lecture is in use
>    Advance As Boolean       'Advance or backup direction
>    PgmType As Byte     '0=Film  6=Resp  11=Vet
> End Type
> Public gLect As stcLectures
>
> OPENING THE LECTURE AND PARAMETER FILES
>    Temp1 = Len(glctLecture(0)) * 100
>    Temp2 = Len(glctInstTable(0))
>    sFile = clsRes.LoadResStgA(401)    'lct file
>    strCurrFile = gstrPgmPath & sFile
>    On Error GoTo ErrorHandler  ' Enable error-handling routine.
>    lctFile = FreeFile
>    Open strCurrFile For Random Access Read Write As #lctFile Len = Temp1
> ' Open file for input.
>    sFile = clsRes.LoadResStgA(400)    'par file
>    strCurrFile = gstrPgmPath & sFile
>    parFile = FreeFile
>    Open strCurrFile For Random Access Read Write As #parFile Len = Temp2
> ' Open file for input.
>
>
> READING THE PASSWORD PROTECTED PARAMETERS FILE INTO STRUCTURES
>    On Error GoTo ErrorHandler  ' Enable error-handling routine.
>    For Index = 0 To 7 Step 1
>        Get #parFile, Index + 1, glctInstTable(Index)
>        strTemp = glctInstTable(Index).Password
>        For Inner = 1 To 8 Step 1
>            intTemp = Asc(Mid$(strTemp, Inner, 1)) Xor bytCode(Inner - 1)
>            Mid$(strTemp, Inner, 1) = Chr$(intTemp)
>        Next Inner
>        glctInstTable(Index).Password = strTemp
>    Next Index
>
>
> READING IN THE DESIRED LECTURE (OUT OF 64) TO LECTURE STRUCTURE OF 100
> STEPS
>    On Error GoTo ErrorHandler  ' Enable error-handling routine.
>    LectFilePosition = (gLect.InstNum * 8) + gLect.LectNum + 1
>    Get #lctFile, LectFilePosition, glctLecture
>
>

This reply doesn't help exactly what you are doing, but a suggestion...have
you tried going the route of datasets?  I mean, you can do what you are
trying to using a dataset and saving the file(s) as XML.  Loading is just as
easy.

HTH,
Mythran