Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / May 2004



Tip: Looking for answers? Try searching our database.

is there a database alternative to ADO

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
del - 27 May 2004 12:17 GMT
I am a relative beginner so please be gentle with me.

I am using ADO in my program which works fine except it adds a massive
10 MB to my installation package.

I tried using DAO 3.5 which also worked find except it doesn't support
unicode which I need. If I went to DAO 3.6 it then needed JET4 which
is even bigger than ADO.

It is  a simple standalone program needed simple database support and
I am not concerned with security or speed as there are a maximum of
600 records per table.

Can anyone think of a way around this ? I don't mind paying for a 3rd
party control but can't seem to find any simple ones.

Can anyone help ?
Thanks  -  Del
J French - 27 May 2004 12:37 GMT
>I am a relative beginner so please be gentle with me.
>
[quoted text clipped - 11 lines]
>Can anyone think of a way around this ? I don't mind paying for a 3rd
>party control but can't seem to find any simple ones.

You could use VB's native file handling

Not the FileSystemObject
- just: Open Statement
        Get, Put, Seek etc

Zero overhead - and depends on nothing
del - 27 May 2004 13:37 GMT
Are you saying I can read and write to an access database using get
and put etc ?

I tried to test the sample code given in the VB help but didn't get
very far. I get an error message "Only user-defined types defined in
public objects can be passed to or from a variant or passed to late
bound functions" This is the code

===========
Public Type Record
  ID As Integer
  Name As String * 20
End Type

Public Sub test()

Dim MyRecord As Record, Position

Open App.Path & "\admin.mdb" For Random As #1 Len = Len(MyRecord)
   Position = 3
   Get #1, Position, MyRecord
Close #1

msgbox MyRecord

End Sub

>>I am a relative beginner so please be gentle with me.
>>
[quoted text clipped - 19 lines]
>
>Zero overhead - and depends on nothing

Thanks  -  Del
Phill.  W - 27 May 2004 13:56 GMT
> Are you saying I can read and write to an access database using get
> and put etc ?

No.  Absolutely not.

You can, however, write to a file of your /own/ using this method.

> MsgBox MyRecord

I think it's actually /this/ line that's your problem.  How /do/ you
display a structure, all in one go?  This might get you a bit further :

MsgBox MyRecord.ID & vbCrLf _
   & MyRecord.Name

HTH,
   Phill  W.
del - 27 May 2004 14:18 GMT
sorry I am list here. What do you mean by "write a file" . What kind
of file if I can't use an access database bearing in mind it has to
support unicode ?

>> Are you saying I can read and write to an access database using get
>> and put etc ?
[quoted text clipped - 13 lines]
>HTH,
>    Phill  W.

Thanks  -  Del
J French - 27 May 2004 15:27 GMT
>sorry I am list here. What do you mean by "write a file" . What kind
>of file if I can't use an access database bearing in mind it has to
>support unicode ?

Unicode - look at StrPtr and of course CreateFile

But I reckon you are deluded.
cmoyaX@nospam.com - 27 May 2004 23:55 GMT
It astounds me how little people know about writing to flat binary files. If
your demands are not super-complex, binary datafiles are always the way to
go for desktop apps... even preferable to XML. Sadly, this will probably
become a lost art.

> > Are you saying I can read and write to an access database using get
> > and put etc ?
[quoted text clipped - 13 lines]
> HTH,
>     Phill  W.
del - 28 May 2004 00:23 GMT
I did say I was a beginner. So where can I read about them ?

I experimented by saving an excel file full of russian characters to
unicode DOS but I noticed it would only space delimit. ON top of that
, it read ok in XP but in windows 98 it was just garbage.

>It astounds me how little people know about writing to flat binary files. If
>your demands are not super-complex, binary datafiles are always the way to
[quoted text clipped - 18 lines]
>> HTH,
>>     Phill  W.

Thanks  -  Del
cmoyaX@nospam.com - 28 May 2004 01:05 GMT
I didn't mean it as a diss on you. We're all beginners at some point.

Here's some food for thought to get you started on your journey.

Lookup the Open statement in the VB help files. What you want is the "For
Binary" variation.

Then lookup Get/Put statements.

For unicode you need to convert your string to a bytearray to get the full
set bytes (see the StrConv examples below), which VB for the most part
shields from you. Then you spit your values out into a binary file.

By the way, here's an old trick when working with binary files for creating
variable-length records:
| 4 bytes length of data | data |
When you read a record first you read the first 4 bytes (Long), which will
tell you how much data to read for the record. VB string themselves pretty
much work this way too.

Binary I/O Example: (warning: these routines lose the unicode data... you
need to convert the string to a byte array first for what you want to do...
but this will help get you started I think)

Public Sub WriteBinaryFileString(ByVal filenum As Integer, ByVal WriteData
As String)

  Dim StartPos As Long
  Dim strsize As Integer

  StartPos = LOF(filenum) + 1

  strsize = Len(WriteData)
  Put #filenum, StartPos, strsize
  Put #filenum, , WriteData

End Sub

Public Function ReadBinaryFileString(ByVal filenum As Integer) As String

  Dim tmpstr As String
  Dim strsize As Integer

  Get #filenum, , strsize
  tmpstr = String$(strsize, " ")
  Get #filenum, , tmpstr
  ReadBinaryFileString = tmpstr

End Function

Remember Get/Put can employ a "cursor" type access. Get #filenum, , 10
(notice the missing parameter) will get you the *next* 10 bytes after the
last set of bytes that were read in.

StrConv Examples:

'will give you the full set of bytes for a VB unicode string
Dim bytes() as Byte
bytes=StrConv(strS, vbFromUnicode)

'to reverse it:
Dim str as String
str=StrConv(bytes, vbUnicode)

I hope this helps.

> I did say I was a beginner. So where can I read about them ?
>
[quoted text clipped - 26 lines]
>
> Thanks  -  Del
cmoyaX@nospam.com - 28 May 2004 01:13 GMT
Clarification (I had the examples reversed):

'will give you the full set of bytes for a VB unicode string
Dim bytes() as Byte
bytes=StrConv(strS, vbUnicode)

'to reverse it:
Dim str as String
str=StrConv(bytes, vbFromUnicode)

> I didn't mean it as a diss on you. We're all beginners at some point.
>
[quoted text clipped - 94 lines]
> >
> > Thanks  -  Del
J French - 28 May 2004 05:29 GMT
>It astounds me how little people know about writing to flat binary files. If
>your demands are not super-complex, binary datafiles are always the way to
>go for desktop apps... even preferable to XML. Sadly, this will probably
>become a lost art.

It already is pretty much a lost art.
Good to see someone recommending reviving it.
Mike Williams - 28 May 2004 10:04 GMT
> It already is pretty much a lost art.
> Good to see someone recommending reviving it.

I don't have to "revive" it, Jerry. It is the only thing I know! I've always
"rolled my own" and I wouldn't know an Access database if I fell over it in
a dark alley!

Mike
Dag Sunde - 28 May 2004 10:10 GMT
> > It already is pretty much a lost art.
> > Good to see someone recommending reviving it.
>
> I don't have to "revive" it, Jerry. It is the only thing I know! I've always
> "rolled my own" and I wouldn't know an Access database if I fell over it in
> a dark alley!

Maybe not You or I, and a few others that have occationally stumbled in
dark alleys before.

But I will be suprised if more that 5-10% of the programmers that have
joined the profession recently (4-5years) do their own binary file-formats
on a regular basis...

--
Dag
58°26'15.9" N 008°46'45.5" E
J French - 28 May 2004 12:34 GMT
<snip>

>Maybe not You or I, and a few others that have occationally stumbled in
>dark alleys before.
>
>But I will be suprised if more that 5-10% of the programmers that have
>joined the profession recently (4-5years) do their own binary file-formats
>on a regular basis...

The little sods would not know how to Seek() their own posteriors

- which is an alarming sign of de-skilling

What amazes me is that it is so easy ... and fundamental.
cmoyaX@nospam.com - 28 May 2004 13:29 GMT
I think part of the problems stems from the lack of "primar" reference
books. Does anyone remember the big fat books that came with VB3 and VB4
(not to mention the even fatter reference books that came with my Commodore
64 and 128 :-) )? They had complete sections on file I/O. In hindsight, the
VB4 black & white cover compared to the older Vb3 full color cover was a
foreshadowing of its pending extinction.

> <snip>
>
[quoted text clipped - 10 lines]
>
> What amazes me is that it is so easy ... and fundamental.
Martin Trump - 28 May 2004 17:15 GMT
>The little sods would not know how to Seek() their own posteriors
>- which is an alarming sign of de-skilling
>What amazes me is that it is so easy ... and fundamental.

Perhaps truer than you realised. Look up 'fundament' in the dictionary
:-)

Regards
Signature

Martin Trump

J French - 28 May 2004 12:30 GMT
>> It already is pretty much a lost art.
>> Good to see someone recommending reviving it.
>
>I don't have to "revive" it, Jerry. It is the only thing I know! I've always
>"rolled my own" and I wouldn't know an Access database if I fell over it in
>a dark alley!

All credit to you
Perhaps we can enlighten the misled
Besos007 - 28 May 2004 13:15 GMT
Thanks but back to planet earth for a minute.

Before I do more damage to my brain and try this out , can you just
confirm to me that doing this binary stuff will work in the same was
as a database table i.e. each line of the file contains several fields
and I can say go to line 100 and tell me what is in the 5th field ?

It would be nice to know this could be done.  I did a test with an
installshield setup using a access 2002 databse and one simple "Hello
World" msgbox. Installshiel told me I required MDAC 7 and Jet 4 ,
installer etc and the total file package came to 35 MB for a 5kb
program !  So much for progress.
f

>>> It already is pretty much a lost art.
>>> Good to see someone recommending reviving it.
[quoted text clipped - 5 lines]
>All credit to you
>Perhaps we can enlighten the misled
cmoyaX@nospam.com - 28 May 2004 13:48 GMT
I don't think you'd be doing damage. You'd be acquiring a very essential
skill that would actually give you insight and appreciation into "real"
databases (which of course are binary files also). However, if you have to
get this done NOW then as always the easier RAD solution is to go with the
prepackaged db solution.

But think about this... outside of corporate environments, how many desktop
applications actually use relational databases? The answer is probably zero.
All programs that use the "document" paradigm sure don't. Acrobat PDF's are
binary (actually they're sort of a hybrid Text / Binary format). Word
Documents are binary data files. So are Excel files. Even programs like
Quicken that actually benefit from the relational db model use their own
rolled "databases." Only MS Money uses a modified version of Access MDB's to
store data.

As for being able to do what you want to do. There are no "lines" in a
binary format (there are however "lines" or "records" in sequential Text
formats... you might want to consider that format too- they're actually
quite similar though but less robust). Your code would know how many fields
are in a record. So it knows how many fields to traverse to get to another
record. You can even add padding (empty non-defined fields) for future use
(because making changes to your "format" in the future can be a big pain!).
As long as you understand that the file format is anything you want it to
be, the world is your oyster.

You can also try XML. It's very capable and all you need is the MSXML
parser... which installs with IE. I haven't done much with having to store
unicode characters in XML. But my first thought would would be to store your
string as NUMBERS rather than as a plain string and use StrConv to read them
in and out.

> Thanks but back to planet earth for a minute.
>
[quoted text clipped - 19 lines]
> >All credit to you
> >Perhaps we can enlighten the misled
del - 28 May 2004 19:11 GMT
thanks guy but this all sounds far beyond me. Looks like I am stuck
with my 10 MB MDAC overload.

I am looking at codebase but that seems to be designed for experienced
database programmers and the help files (horrible pdf files) were
hopeless.
Why don't these companies realise there must be thousands of us out
here that just want to do very simple data retrieval in a user
friendly way. ADO fits the bill perfectly and I find it easy to use
but I assume I am only using 1% of it's capabilites

>I don't think you'd be doing damage. You'd be acquiring a very essential
>skill that would actually give you insight and appreciation into "real"
[quoted text clipped - 52 lines]
>> >All credit to you
>> >Perhaps we can enlighten the misled

Thanks  -  Del
cmoyaX@nospam.com - 28 May 2004 19:16 GMT
Just one more suggestion: You can try making your installer "smart." Leave
out MDAC. If the user is installing on a pre WinXP machine, then silently
download it directly from Microsoft. At least WinXP (which ships with MDAC
2.7) users won't incur the huge download.

Good luck!

> thanks guy but this all sounds far beyond me. Looks like I am stuck
> with my 10 MB MDAC overload.
[quoted text clipped - 65 lines]
>
> Thanks  -  Del
J French - 29 May 2004 06:01 GMT
>thanks guy but this all sounds far beyond me. Looks like I am stuck
>with my 10 MB MDAC overload.

Writing ones own filing system is incredibly easy.
It is also very rewarding.

Not understanding rudimentary filing is crippling you.
- and forcing you to rely on 3rd party bloatware.
del - 29 May 2004 08:25 GMT
ok , but how to I learn how to do it with simple step by step
instructions ? and I am still not clear whether it will work for
unicode characters in win 98

>>thanks guy but this all sounds far beyond me. Looks like I am stuck
>>with my 10 MB MDAC overload.
[quoted text clipped - 4 lines]
>Not understanding rudimentary filing is crippling you.
>- and forcing you to rely on 3rd party bloatware.

Thanks  -  Del
J French - 29 May 2004 11:39 GMT
>ok , but how to I learn how to do it with simple step by step
>instructions ? and I am still not clear whether it will work for
>unicode characters in win 98

1) Find out what Unicode Characters really are
2) Look at StrConv() in the help files (others have told you this)
   Play with Byte Arrays and Strings
3) Look in Help Files for the:  Open Statement

Frankly, I would write a few simple things that store and read ANSII
- then delve into Unicode

At risk of being rather brusque, if you cannot learn how to explore
the help files and experiment, then you will be restricted to using VB
as a 'user' rather than a programmer

Show some signs of making an effort and you will get plenty of help.

Here is a simple demo
- I suggest you choose a different font to fully test it.
- also look at what is really written in the file
( I can help you there with a very old utility )

Option Explicit

' Add two Command Buttons
' Add one Textbox
' Add one Label

Const Fle$ = "c:\test.dat"

Private Sub Form_Load()
  Command1.Caption = "Save Text"
  Command2.Caption = "Load Text"
  ' --- Select a Unicode Font
  Me.Font.Name = "Wingding"
  '
  Set Text1.Font = Me.Font
  Set Label1.Font = Me.Font
  '
  Label1.Caption = ""
  Text1.Text = "This is Text" + ChrW$(352)
End Sub

' --- Write some Unicode
Private Sub Command1_Click()
  Dim B() As Byte
  Dim S As String
  Dim Channel As Integer
 
  Channel = FreeFile
  S = Text1.Text
  B() = S ' Take Unicode String
  Open Fle$ For Binary As #Channel
  Seek #Channel, 1  ' not needed
  Put #Channel, , B()
  Close #Channel
End Sub

' --- Read some Unicode
Private Sub Command2_Click()
  Dim B() As Byte
  Dim S As String
  Dim Channel As Integer
  Dim L As Long
 
  Channel = FreeFile
  L = FileLen(Fle$)
  ReDim B(0 To L - 1)
  Open Fle$ For Binary As #Channel
  Seek #Channel, 1  ' not needed
  Get #Channel, , B()
  Close #Channel
 
  S = B()
  Label1.Caption = S
End Sub
Schmidt - 30 May 2004 17:29 GMT
> ok , but how to I learn how to do it with simple step by step
> instructions ? and I am still not clear whether it will work for
> unicode characters in win 98

Here's some easy to use approach, to implement your own filebased
Recordset-Class, that should work with Win98 and has Unicode-Support also:
Open a Standard-Exe-Project and add a Class (name it cRsPersons for
example).

'****Into the Form:
Option Explicit

Private Persons As CRsPersons

Private Sub Form_Load()
Dim i&, T#, CC&
 Set Persons = New CRsPersons
 Persons.BindTo "c:\Persons.dat"
 CC = Persons.RecordCount
 MsgBox "File contains " & CC & " Records."

 If CC Then
   MsgBox "First RecordID = " & Persons.ID & ", " & Persons.Name
   Persons.AbsolutePosition = Persons.RecordCount \ 2
   MsgBox "Mid RecordID = " & Persons.ID & ", " & Persons.Name
   Persons.MoveLast
   MsgBox "Last RecordID = " & Persons.ID & ", " & Persons.Name

   T = Timer 'Fast delete of all records (from last to first)
   Persons.MoveLast
   Do
     Persons.Delete
     Persons.MovePrevious
   Loop Until Persons.BOF
   MsgBox CC & " Records deleted after " & Timer - T & " sec"
 End If

 T = Timer
 With Persons
   For i = 1 To 10000
     .AddNew
     .ID = i: .Name = "Name" & i: .BirthDay = Now
     .Update
   Next i
   MsgBox .RecordCount & " Records added in " & Timer - T & " sec"
 End With
End Sub

'****Into the Class cRsPersons (the main-part of this class is generic):
Option Explicit

Private Type Tbl 'look at this Type as your TableDef
 Deleted As Boolean 'set always this first member (for internal use)
 ID As Long
 Name As String * 64 'always use FixedLength Strings
 BirthDay As Date
 '+ additional fields at will - make sure, that all Members that'll be
 'defined here (excepting the Deleted-Member), get their correct
 'Property-Implementation at the end of this class
End Type

'***********Default CodeBlock - Don't change it************
Private Declare Sub RtlMoveMemory Lib "kernel32" _
 (Dst As Any, Src As Any, ByVal BCount&)
Private FNr&, RLen&, ii&, Idx&(), Records() As Tbl, RC&, B() As Byte, W0$
Public Sub BindTo(FName$)
Dim i&, FLen&, Record As Tbl
 If FNr Then Close FNr
 FNr = FreeFile: Open FName For Binary As FNr
 RLen = LenB(Record): FLen = LOF(FNr)
 RC = FLen \ RLen: FLen = RC * RLen: W0 = ChrW(0)
 ReDim Records(-1 To RC + 256): ReDim Idx(-1 To RC + 256)
 If RC = 0 Then ii = -3: ReDim B(RLen - 1): Exit Sub
 ReDim B(RC * RLen - 1): Get FNr, 1, B
 RtlMoveMemory Records(0).Deleted, B(0), RC * RLen
 RC = 0: ReDim B(RLen - 1)
 For i = 0 To FLen \ RLen - 1
   If Not Records(i).Deleted Then Idx(RC) = i: RC = RC + 1
 Next i
 If RC = 0 Then ii = -3 Else ii = 0
End Sub
Public Function BOF(): BOF = (ii = -1) Or (ii = -3): End Function
Public Function EOF(): EOF = (ii = -2) Or (ii = -3): End Function
Public Function RecordCount&(): RecordCount = RC: End Function
Public Property Get AbsolutePosition&()
 If ii < 0 Then Exit Property Else AbsolutePosition = ii + 1
End Property
Public Property Let AbsolutePosition(ByVal P&)
 If P <= 0 Or P > RC Then Exit Property Else ii = P - 1
End Property
Public Sub MoveFirst()
 If RC Then ii = 0
End Sub
Public Sub MoveLast()
 If RC Then ii = RC - 1
End Sub
Public Sub MovePrevious()
 If BOF Then Exit Sub Else ii = ii - 1: If ii < 0 Then ii = RC - 1
End Sub
Public Sub MoveNext()
 If EOF Then Exit Sub Else ii = ii + 1: If ii = RC Then ii = -2
End Sub
Public Sub Delete()
Dim i&: If ii < 0 Then Exit Sub
 Records(Idx(ii)).Deleted = True: Update: RC = RC - 1
 For i = ii To RC - 1: Idx(i) = Idx(i + 1): Next
 If ii = RC Then ii = -2
End Sub
Public Sub AddNew()
 ii = RC: Idx(ii) = IIf(RC > 0, Idx(ii - 1) + 1, 0): RC = RC + 1
 Records(Idx(ii)) = Records(-1) 'set NewRecord=EmptyRecord
 If Idx(ii) < UBound(Idx) Then Exit Sub
 ReDim Preserve Records(-1 To Idx(ii) * 2)
 ReDim Preserve Idx(-1 To Idx(ii) * 2)
End Sub
Public Sub Update()
If ii < 0 Then Exit Sub
 RtlMoveMemory B(0), Records(Idx(ii)).Deleted, RLen
 Put FNr, Idx(ii) * RLen + 1, B
End Sub
Private Function GetStr$(S$) 'Unicode-String from Tbl-StringMember
 GetStr = LeftB$(S, (LenB(S) - 1 + InStrB(S, W0)) Mod LenB(S) + 1)
End Function
Private Sub Class_Terminate()
 If FNr Then Close FNr
End Sub
'******************End Default-Codeblock********************

'<<<<<<<<<<<<<Tbl-Implementation starts here>>>>>>>>>>>>>>>>
'this class implements the ID, Name and Brithday-Members of the Tbl-
'Type defined on Top of this class; no implementation is needed for
'the Deleted-Field, wich always should be the first member in a TblDef
'take care for the correct field-names inside every property-pair
'you can easily implement additional validation for every Record-
'Field, if you check the appropriate V-Value inside every Property Let
Public Property Get ID(): If ii < 0 Then Exit Property
 ID = Records(Idx(ii)).ID
End Property
Public Property Let ID(V): If ii < 0 Then Exit Property
 Records(Idx(ii)).ID = V
End Property

Public Property Get Name(): If ii < 0 Then Exit Property
 Name = GetStr(Records(Idx(ii)).Name)
End Property
Public Property Let Name(V): If ii < 0 Then Exit Property
 Records(Idx(ii)).Name = V & W0 '<< allways add W0 to str-members
End Property

Public Property Get BirthDay(): If ii < 0 Then Exit Property
 BirthDay = Records(Idx(ii)).BirthDay
End Property
Public Property Let BirthDay(V): If ii < 0 Then Exit Property
 Records(Idx(ii)).BirthDay = V
End Property

Olaf
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.