Friday, August 21, 2009

VB6: Cellphone database, database manipulation Part 1

A simple database created with 1 table and 1 record. Download the database at

http://dl.getdropbox.com/u/1696625/visual-basic-6.0-projects/cellphone-database/phone.7z


The database created with MS Access 97. Unzip the 7zipped database above in a folder. You must use this in a folder, or it with generate an error; the path would be something like C:\\phone.mdb

Below is a simple procedure to manipulate the database and dump the fields name into debug windows.

You could access the debug screen or Immediate windows in your MS Visual Basic 6.0, using Ctrl + G

Dim gLibWS As Workspace
Dim gLibDB As Database
Dim gLibDyna As Recordset
Dim gLibSnap As Recordset
Dim gLibTable As Recordset
Dim gDbName As String

gDbName = App.Path & "\phone.mdb"

' Print database name with path to debug screen
Debug.Print gDbName

Set gLibWS = DBEngine.CreateWorkspace("Workspace", "Admin", "")

' Open DataBase with Exclusive and Read/Write access
Set gLibDB = gLibWS.OpenDatabase(gDbName$, True, False)

Set gLibSnap = gLibDB.OpenRecordset("cellphone", dbOpenSnapshot)
giFldTotal% = gLibDB.TableDefs("cellphone").Fields.Count - 1

' Print total of fields in the debug windows
Debug.Print "Total of fields: " & giFldTotal%


For fiIndex% = 0 To giFldTotal% - 1
' Extract name of fields name
ftfldname$ = CStr(gLibDB.TableDefs("cellphone").Fields(fiIndex%).Name)
Debug.Print fiIndex% & " : " & ftfldname$
Next fiIndex%

Copy and paste, the codes above in a blank form, in the Form_Load()

Do not forget to add References in your project, Microsoft DAO 2.5/3.51 Compatibility Library.

The output in the debug windows will look like this:

D:\visual-basic-diploma-project\phone.mdb
Total of fields: 53
0 : Phone_ID
1 : Phone_Manufacturer
2 : Phone_Model
3 : Key_Feature_3G
4 : Key_Feature_Wifi
5 : Key_Feature_memory_card_slot
6 : Key_Feature_MP3
7 : Key_Feature_QWERTY
8 : Key_Feature_camera
9 : Key_Feature_Bluetooth
10 : Key_Feature_GPS
11 : From_factor
12 : Data
13 : Antenna_Design
14 : Operating_frequencies
15 : Global_Roaming
16 : Weight
17 : Dimensions
18 : Battery_Standby
19 : Battery_Talktime
20 : Battery_Type
21 : Display_Resolution
22 : Display_Type
23 : Camera_Features
24 : Camera_Video
25 : Camera_Resolutions
26 : Memory_Expansion
27 : Memory_Internal
28 : Conn_Infrared
29 : Conn_Bluetooth
30 : Conn_Sync
31 : Conn_USB
32 : Conn_Wifi
33 : MM_Headset_Jack
34 : MM_Video_Playback
35 : MM_FM_Radio
36 : MM_Streaming
37 : MM_Music_Player
38 : Size_Weight
39 : Size_Dimensions
40 : Messaging_E_Mail
41 : Messaging_Instant_Messaging
42 : Messaging_Predictive_Text_Input
43 : Messaging_MMS
44 : Software_to_do
45 : Software_Phonebook
46 : Software_Games
47 : Software_Java
48 : Software_Calculator
49 : Software_Alarm
50 : Software_Calendar
51 : Software_Other_Organizers
52 : Official_URL

No comments:

Post a Comment