Home All Groups Group Topic Archive Search About
Author
23 May 2005 7:50 PM
Lance
hi all,

i've got a UDT structured as such

Private Type DataListing
    Date                         As String * 19
    TimeZone                     As String * 5
    PredictedValue               As String * 7
    ObservedValue                As String * 7
    ResidualValue                As String * 7
    Windspeed                    As String * 5
    WindDirection                As String * 5
    WindGust                     As String * 5
    BarPressure                  As String * 7
    AirTemperature               As String * 6
    WaterTemperature             As String * 6
    CRLineFeed                   As String * 2
End Type

with a datalisting entry (read from a text file) as follows

05/21/2005 13:36:00  CDT   1.39   1.46
  0.07 -999 -999 -999 -999.9 -99.9 -99.9

the problem (inconvenience, really) is that i've got many, many calculations
to perform with these value within the structure (and the are hundreds of
datalistings).  basically, for each calculation, i'm currently using
datatype conversions (ie., Csng, Cdbl, Cdate, etc.) and it's starting to get
pretty ugly.  is there a more efficient way to breakdown the datalisting?
ideally, it would be

Private Type DataListing
    Date                         As Date
    TimeZone                     As String * 5
    PredictedValue               As Single
    ObservedValue                As Single
    ResidualValue                As Single
    Windspeed                    As Single
    WindDirection                As Single
    WindGust                     As Single
    BarPressure                  As Single
    AirTemperature               As Single
    WaterTemperature             As Single
    CRLineFeed                   As String * 2
End Type

so calculations could be perform without converting them from strings, but
the only way i can think of to do this is to restructure the datalisting
into the structure above.  is that basically what i'm going to have to do or
am i completely overlooking an easier way?

lance

Author
23 May 2005 9:13 PM
Mike D Sutton
> i've got a UDT structured as such
<code snipped>
> with a datalisting entry (read from a text file) as follows
>
> 05/21/2005 13:36:00  CDT   1.39   1.46
>   0.07 -999 -999 -999 -999.9 -99.9 -99.9
>
> the problem (inconvenience, really) is that i've got many, many calculations
> to perform with these value within the structure (and the are hundreds of
> datalistings).  basically, for each calculation, i'm currently using
> datatype conversions (ie., Csng, Cdbl, Cdate, etc.) and it's starting to get
> pretty ugly.  is there a more efficient way to breakdown the datalisting?
> ideally, it would be
<code snipped>
> so calculations could be perform without converting them from strings, but
> the only way i can think of to do this is to restructure the datalisting
> into the structure above.  is that basically what i'm going to have to do or
> am i completely overlooking an easier way?

Open the file in Binary mode and you can read and write this structure type directly.

'*** Warning; air-code..
Dim FNum As Integer
Dim MyStruct As DataListing

' Populate MyStruct here..

FNum = FreeFile() ' Write structure to disk
Open FileName For Binary Access Write Lock Read Write As #FNum
    Put #FNum, , DataListing
Close #FNum

FNum = FreeFile() ' Read structure from disk
Open FileName For Binary Access Read Lock Write As #FNum
    Get #FNum, , DataListing
Close #FNum
'***

You'll also find that in most cases this makes the files you're working with a lot smaller and since they're just raw
binary data a lot more difficult to tamper with for 'average' users.
Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
23 May 2005 9:24 PM
Lance
hi mike,

i should note that the file is already existing on disk.

lance

Show quoteHide quote
"Mike D Sutton" <ED***@mvps.org> wrote in message
news:uZ%23cWx9XFHA.3620@TK2MSFTNGP09.phx.gbl...
>> i've got a UDT structured as such
> <code snipped>
>> with a datalisting entry (read from a text file) as follows
>>
>> 05/21/2005 13:36:00  CDT   1.39   1.46
>>   0.07 -999 -999 -999 -999.9 -99.9 -99.9
>>
>> the problem (inconvenience, really) is that i've got many, many
>> calculations
>> to perform with these value within the structure (and the are hundreds of
>> datalistings).  basically, for each calculation, i'm currently using
>> datatype conversions (ie., Csng, Cdbl, Cdate, etc.) and it's starting to
>> get
>> pretty ugly.  is there a more efficient way to breakdown the datalisting?
>> ideally, it would be
> <code snipped>
>> so calculations could be perform without converting them from strings,
>> but
>> the only way i can think of to do this is to restructure the datalisting
>> into the structure above.  is that basically what i'm going to have to do
>> or
>> am i completely overlooking an easier way?
>
> Open the file in Binary mode and you can read and write this structure
> type directly.
>
> '*** Warning; air-code..
> Dim FNum As Integer
> Dim MyStruct As DataListing
>
> ' Populate MyStruct here..
>
> FNum = FreeFile() ' Write structure to disk
> Open FileName For Binary Access Write Lock Read Write As #FNum
>    Put #FNum, , DataListing
> Close #FNum
>
> FNum = FreeFile() ' Read structure from disk
> Open FileName For Binary Access Read Lock Write As #FNum
>    Get #FNum, , DataListing
> Close #FNum
> '***
>
> You'll also find that in most cases this makes the files you're working
> with a lot smaller and since they're just raw
> binary data a lot more difficult to tamper with for 'average' users.
> Hope this helps,
>
>    Mike
>
>
> - Microsoft Visual Basic MVP -
> E-Mail: ED***@mvps.org
> WWW: Http://EDais.mvps.org/
>
>
Author
23 May 2005 9:26 PM
Lance
hi mike,

i should note that the source file containing the datalistings is already on
disk.  it is this file that is read into the structure.

lance

Show quoteHide quote
"Mike D Sutton" <ED***@mvps.org> wrote in message
news:uZ%23cWx9XFHA.3620@TK2MSFTNGP09.phx.gbl...
>> i've got a UDT structured as such
> <code snipped>
>> with a datalisting entry (read from a text file) as follows
>>
>> 05/21/2005 13:36:00  CDT   1.39   1.46
>>   0.07 -999 -999 -999 -999.9 -99.9 -99.9
>>
>> the problem (inconvenience, really) is that i've got many, many
>> calculations
>> to perform with these value within the structure (and the are hundreds of
>> datalistings).  basically, for each calculation, i'm currently using
>> datatype conversions (ie., Csng, Cdbl, Cdate, etc.) and it's starting to
>> get
>> pretty ugly.  is there a more efficient way to breakdown the datalisting?
>> ideally, it would be
> <code snipped>
>> so calculations could be perform without converting them from strings,
>> but
>> the only way i can think of to do this is to restructure the datalisting
>> into the structure above.  is that basically what i'm going to have to do
>> or
>> am i completely overlooking an easier way?
>
> Open the file in Binary mode and you can read and write this structure
> type directly.
>
> '*** Warning; air-code..
> Dim FNum As Integer
> Dim MyStruct As DataListing
>
> ' Populate MyStruct here..
>
> FNum = FreeFile() ' Write structure to disk
> Open FileName For Binary Access Write Lock Read Write As #FNum
>    Put #FNum, , DataListing
> Close #FNum
>
> FNum = FreeFile() ' Read structure from disk
> Open FileName For Binary Access Read Lock Write As #FNum
>    Get #FNum, , DataListing
> Close #FNum
> '***
>
> You'll also find that in most cases this makes the files you're working
> with a lot smaller and since they're just raw
> binary data a lot more difficult to tamper with for 'average' users.
> Hope this helps,
>
>    Mike
>
>
> - Microsoft Visual Basic MVP -
> E-Mail: ED***@mvps.org
> WWW: Http://EDais.mvps.org/
>
>
Author
23 May 2005 9:38 PM
Mike D Sutton
> i should note that the source file containing the datalistings is already on
> disk.  it is this file that is read into the structure.

If you have control over the format of the file then just perform the conversion once and start using binary files from
now on, it will also increase the I/O performance of your application not just calculation speed.  If the file is being
generated by something else that you don't have control over then unfortunately there's not a great deal you can do.
Personally I would perform the conversion at the time the file is read and written though and just use the second
structure internally - performing mathematical calculation by coercing variable into string is not just inefficient,
it's also prone to errors due to the rounding performed on floating point numbers.
Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
23 May 2005 11:00 PM
Lance
thanks mike.  it is indeed already generated by someone else, but i guess
there is no reason i can't  copy and restructure it to something that will
work with your suggestion.

thanks,
lance


Show quoteHide quote
"Mike D Sutton" <ED***@mvps.org> wrote in message
news:%23JSqC$9XFHA.612@TK2MSFTNGP12.phx.gbl...
>> i should note that the source file containing the datalistings is already
>> on
>> disk.  it is this file that is read into the structure.
>
> If you have control over the format of the file then just perform the
> conversion once and start using binary files from
> now on, it will also increase the I/O performance of your application not
> just calculation speed.  If the file is being
> generated by something else that you don't have control over then
> unfortunately there's not a great deal you can do.
> Personally I would perform the conversion at the time the file is read and
> written though and just use the second
> structure internally - performing mathematical calculation by coercing
> variable into string is not just inefficient,
> it's also prone to errors due to the rounding performed on floating point
> numbers.
> Hope this helps,
>
>    Mike
>
>
> - Microsoft Visual Basic MVP -
> E-Mail: ED***@mvps.org
> WWW: Http://EDais.mvps.org/
>
>