1. Binary File I/O with variable string member
Hi,
I am working on a small application and dont want to store records in any
database (access,sql. etc). I want to write & read
information from my own binary file, for this purpose I have declared type
in my application which is as follows.
Public Type CustDetails
CustID as long
FName as string
LName as string
Addr as string
City as string
State as string
Country as string
DateofBirth as date
Weight as double
.
.
.
...etc. etc.
End Type
Now to save disk space I dont want to specify the length of string type
memebers.
I have declared the customer array and can save that customer array into
file easily but problem comes while loading this file back to the customer
array as I dont know what exactly would be the number of records saved in
this file so that i can redim my array accordingly.
My code for saving and retreving type array as follows
Dim arrCustomer() As CustDetails
Dim fso As New FileSystemObject
Private Const mFileName As String = "Customers.dat"
Private Sub SaveFile()
If GetUBound(arrCustomer) < 0 Then
Exit Sub
End If
Dim arrCounter As Integer
Dim FileNum As Integer
Dim DataFilePath As String
DataFilePath = App.Path & "\" & mFileName
FileNum = FreeFile
Open App.Path & "\" & mFileName For Binary As FileNum
Put FileNum, , arrCustomer
Close (FileNum)
MsgBox "Saved..", vbInformation
End Sub
Public Sub LoadFile()
Dim FileNum As Integer, RecordNumber As Integer
Dim DataFilePath As String
DataFilePath = App.Path & "\" & mFileName
If fso.FileExists(DataFilePath) Then
FileNum = FreeFile
Open App.Path & "\" & mFileName For Binary As FileNum
ReDim arrCustomer(0) ' this is a problem
Get FileNum, , arrCustomer
Close (FileNum)
End If
End Sub
Please help as I beleive there should be some way of retreiving variable
type member records. I have searched on the net but couldnt find out the
solution for this problem
Best regards
VJ
2. Reading a binary file with a string and a byte variable - Visual Basic/VB
3. Accessing class member variables - properties or variables?
Only expose your private members if you wish them to be publicly acessible,
that sounded horrible... I only create properties to be externally consumed
by another class, say I have a class that gets loaded from the database and I
have a property that accesses the data:
Public Overridable ReadOnly Property SomeData() As String
Get
Return m_SomeData
End Get
End Property
I'm going to poulate this properties value using the private member
m_SomeData, that way I don't interfere with anyone else's implementation
should they descide to override this property.
"dwok" wrote:
> I have been wondering this for a while now. Suppose I have a class
> that contains some private member variables. How should I access the
> variables throughout the class? Should I use properties that expose the
> variables or is it OK to just access the variables directly? Keep in
> mind that I am talking about accessing the variables from within the
> class that they are defined. Thanks!
>
>
5. Byte order of Long variable in Binary File
On reading Intiger Variables (4 bytes) from BBC micro
files, into VBA Long variables (4 bytes), I notice that
the byte order in which VBA reads the variable (using Get)
is in reverse to that used by the BBC micro.
i.e. On the disk
The BBC stores the 4 bytes in order MSB to LSB.
Decimal -2 is Hex FFFFFFFE
The VBA stores the 4 bytes in order LSB to MSB.
Decimal -2 is Hex FEFFFFFF
Can VBA be made to Put and Get the right way round?
6. Mark off two variables in a binary file - Visual Basic/VB
7. open binary file and search hex string
Hi... I would like to search for a hex string (for example: "E903") inside a binary file... Although I open the file correctly, how do I search hex values? Thanks in advance! Nikos
8. Write a string in a binary file, problem with CAPICOM - VB.Net