Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > File I/O and Registry > Help with unknown database


Reply
 
Thread Tools Display Modes
  #1  
Old 12-02-2003, 10:43 AM
Speedy_SgZ Speedy_SgZ is offline
Newcomer
 
Join Date: Oct 2003
Posts: 22
Default Help with unknown database


Hi all!

I don't know much about reading and writing files in Visual Basic, that's why I post this question. In the picture I provide with this post you can see 3 blocks of data. Each blocks contains 9 rows (= records in the database)

http://soccer.gamez.nl/temp/vb/1.jpg
Three blocks of data

http://soccer.gamez.nl/temp/vb/2.jpg
One data block

http://soccer.gamez.nl/temp/vb/3.jpg
One row (= 1 record)

http://soccer.gamez.nl/temp/vb/4.jpg
Columns explained

In total the "database" contains 34 blocks of data each containig 9 rows. I'd like to open this database format in Visual Basic. I was thinking about 9 rows with each 5 dropdown boxes. In the first box comes A, in the second box comes B, in the third box comes C, in the fourth box comes D and in the fifth box comes E. I also want to convert the bits and bytes into ASCII.

A: varies from 00 (decimal: 0) to 11 (decimal: 17)
B: varies from 00 (decimal: 0) to 11 (decimal: 17)

C: indicates the day ; varies from 01 (decimal: 1) to 1F (decimal: 31)
D: indicates the month ; varies from 00 (decimal: 0) to 0B (decimal: 11)
E: indicates the year ; varies from 00 (decimal 0) to 01 (decimal 1)

Notes (decimal values used):
The year: 00 = 2003 and 01 = 2004
The month: 00 = January, 11 = December
The day: 01 = day 1, 31 = day 31

Is it possible to create something so when you pick "Block A" in a dropdown menu the 9 records of "Block A" are shown in the dropdowns? And when you choose for instance for "Block Z" it loads the records of "Block Z"? Is there also a way to change the values in the file. If the dropdown box for "day" contains 12 and you change it to 23 it also changes in the file.

I hope I'm clear enough to get some help . Thanks in advance!

Greetings, Speedy
Reply With Quote
  #2  
Old 12-02-2003, 10:26 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,722
Default

There's a number of ways you could go about this. You should read the
File I/O tutorial in the tutorial section. I'll just give you one way of
getting the information from the file. You can decide what you want to
do with it after that point. You can write the information back to the
file by just changing the "get" to a "put", the rest of the I/O code is
unchanged.

This example defines a record (UDT) in the format you specified. It
creates an array to read all 34 blocks, of 9 records. Once you read the
tutorial you may see how to change the code to read one record, or
one block at a time, if you want.

Code:
Private Type DateRecType bytA As Byte bytB As Byte int2 As Integer 'don't care byt4 As Byte 'don't care bytDate As Byte bytMonth As Byte bytYear As Byte End Type Private Sub Command1_Click() Dim block(1 To 34, 1 To 9) As DateRecType '34 blocks of 9 records Open "c:\tst.fil" For Binary As #1 Get #1, , block 'read all 34 blocks Close #1 With block(34, 9) 'Print the information from the 9th record of the 34th block. Debug.Print .bytA; .bytB; .bytDate; .bytMonth; .bytYear End With End Sub
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #3  
Old 12-05-2003, 01:04 PM
Speedy_SgZ Speedy_SgZ is offline
Newcomer
 
Join Date: Oct 2003
Posts: 22
Default

Quote:
Originally Posted by passel
There's a number of ways you could go about this. You should read the
File I/O tutorial in the tutorial section. I'll just give you one way of
getting the information from the file. You can decide what you want to
do with it after that point. You can write the information back to the
file by just changing the "get" to a "put", the rest of the I/O code is
unchanged.

This example defines a record (UDT) in the format you specified. It
creates an array to read all 34 blocks, of 9 records. Once you read the
tutorial you may see how to change the code to read one record, or
one block at a time, if you want.

Code:
Private Type DateRecType bytA As Byte bytB As Byte int2 As Integer 'don't care byt4 As Byte 'don't care bytDate As Byte bytMonth As Byte bytYear As Byte End Type Private Sub Command1_Click() Dim block(1 To 34, 1 To 9) As DateRecType '34 blocks of 9 records Open "c:\tst.fil" For Binary As #1 Get #1, , block 'read all 34 blocks Close #1 With block(34, 9) 'Print the information from the 9th record of the 34th block. Debug.Print .bytA; .bytB; .bytDate; .bytMonth; .bytYear End With End Sub



OK, many many thanks! Works perfect! But now have an other little problem. As you can see on this screenshot I have loaded the first block out of the database. Now I'd like to change the values from 0 till 17 in blocks A en B in text. I know how I can do it in VB, but I'd like to do it with an external file. Any suggestions?

And something else: when changing the date for instance, how can I save the changes to the original file?

http://soccer.gamez.nl/temp/vb/5.jpg

Thanks in advance!
Reply With Quote
  #4  
Old 12-05-2003, 10:13 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,722
Default

I don't understand your question about using an external file for changing
the values in the A and B values.

To save the changes, assuming you've read all the data in so it's sitting
in the (34,9) array, you just change the "Get" to a "Put" to write all the
data back to the file. Just update the values in the array.
Code:
' Block(1,7).BytDate = 14 Block(1,7).BytMonth = 11 Open "c:\tst.fil" For Binary As #1 Put #1, , block 'Write all 34 blocks Close #1

Of course, if you didn't want to write or read the whole file, you can
calculate the position, and only read or write as much as you want.
Each record is 8 bytes, so the byte position would be.
8 * rows * block
1 + ((block-1) * 72) + ((Row-1) * 8)

For the 1,7 example above, the byte position would be
1 + (1-1) * 72) + ((7-1) * 8)
1 + (0 ) + (48 )
49

Code:
' Open "c:\tst.fil" for Binary as #1 Get #1, 49, block(1,7) 'read the 7th row of the first block Block(1,7).BytDate = 14 'modify the date Block(1,7).BytMonth = 11 'modify the Month Put #1, 49, block(1,7) 'Write the row back to the disk Close #1

Since you display a "block", perhaps you just want to read a block, and
write a block.
Code:
' Dim block(1 To 9) As DateRecType '1 block of 9 records Open "c:\tst.fil" For Binary As #1 BlkPos = 1 + ((3 - 1) * 72) 'Get position for 3rd block Get #1, BlkPos, block 'read 1 block Close #1

Plenty of options. It's up to you what you want to do.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unknown Database format... DAO 3.6? BlueLagoon Database and Reporting 1 09-17-2003 07:07 AM
Backup database destress Database and Reporting 3 07-14-2003 01:04 AM
use Access to close another Access app strBean Word, PowerPoint, Outlook, and Other Office Products 20 12-20-2002 02:47 PM
adding records to database with unknown fields cyclonebri Database and Reporting 2 12-06-2002 10:11 AM
User-defined type not defined (im new) skript_kiddie General 8 06-16-2002 02:06 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->