tdbaccess.dll issue... Problem with my code or Bug ?

This forum contains all information about TDBAccess library for NHL 2004 roster access and general NHL coding questions.

Moderator: Owen

Post Reply
iam
Posts: 43
Joined: Sun Sep 19, 2004 5:10 pm

tdbaccess.dll issue... Problem with my code or Bug ?

Post by iam » Sun Nov 06, 2005 5:15 pm

I began playing with tdbaccess today, using VB6.

At first I tried running the example provided in the DLL help file and couldn't get the msgbox to display the number of record of the table.

Then after trying a couple things, I finally was able to make it work but in a strange way...

The only way I was able to get anything from the DB was by opening the DB file twice.

Code: Select all

 DBpath = App.Path & "\iam.sea"
 DBHandle = TDBOpen(DBpath)
 DBpath = App.Path & "\iam.sea"
 DBHandle2 = TDBOpen(DBpath)
I don't get it. Index returned by TDBopen is 0 but unless I don't open it twice, nothing will work... whats wrong with this?

Artem
Site Admin
Posts: 1166
Joined: Thu Oct 23, 2003 5:30 pm

Post by Artem » Sat Dec 17, 2005 1:19 pm

If index is 0 on the first call, the file is opened correctly. The problem is likely somewhere else in the code. The most common problem with VB users of TDBAccess is not allocating the memory for stings correctly. If you use TDBFieldGetValueAsString or GetTableProperies which all return strings in one way of another, you have to initialize the string containers with enough size. The easiest way to do this is using Spaces() function.

For example, when you retrieve table properties, use the following code (syntax might be off a bit):

Code: Select all

Dim Prop As TdbTableProperties

'Initialize a string that will hold table name
Prop.Name = Spaces(4)

'Get properties of the first table in the first file
TDBTableGetProperties(0, 0, Prop)
If you do this in a loop, call Spaces() at the beginning of each iteration.

iam
Posts: 43
Joined: Sun Sep 19, 2004 5:10 pm

Post by iam » Fri Dec 23, 2005 12:34 pm

Suchy_63 wrote:If index is 0 on the first call, the file is opened correctly. The problem is likely somewhere else in the code. The most common problem with VB users of TDBAccess is not allocating the memory for stings correctly. If you use TDBFieldGetValueAsString or GetTableProperies which all return strings in one way of another, you have to initialize the string containers with enough size. The easiest way to do this is using Spaces() function.

For example, when you retrieve table properties, use the following code (syntax might be off a bit):

Code: Select all

Dim Prop As TdbTableProperties

'Initialize a string that will hold table name
Prop.Name = Spaces(4)

'Get properties of the first table in the first file
TDBTableGetProperties(0, 0, Prop)
If you do this in a loop, call Spaces() at the beginning of each iteration.
Thanks a lot for the reply Suchy....

I modified my code for the initializaton part, but I still had an issue, so I investigated a bit more.

Then I realized I was using variables (declared as integer) for the DBindex and FieldIndex parameters in the TDBTableGetProperties function.

I tried with static values instead and it worked right away.

Can't we use variables when calling this function instead of using static dbindex or fieldindex arguments?

EDIT EDIT EDIT EDIT
I'M DUMB!

My bad, I was declaring my variables private, the DLL needs their values so as soon as I declared them Public instead, bingo it worked!

Thanks a lot for your help Suchy! Merry Xmas !

Post Reply