home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / code / database / dbase / dbsample.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-02-27  |  10.7 KB  |  328 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Dbase -III Sample"
  4.    ClientHeight    =   3525
  5.    ClientLeft      =   870
  6.    ClientTop       =   1845
  7.    ClientWidth     =   7920
  8.    Height          =   4455
  9.    Left            =   810
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   3525
  12.    ScaleWidth      =   7920
  13.    Top             =   975
  14.    Width           =   8040
  15.    Begin ListBox List1 
  16.       Height          =   1560
  17.       Index           =   2
  18.       Left            =   6132
  19.       TabIndex        =   16
  20.       Top             =   216
  21.       Width           =   1668
  22.    End
  23.    Begin ListBox List1 
  24.       Height          =   1560
  25.       Index           =   1
  26.       Left            =   4476
  27.       TabIndex        =   15
  28.       Top             =   216
  29.       Width           =   1668
  30.    End
  31.    Begin ListBox List1 
  32.       Height          =   1560
  33.       Index           =   0
  34.       Left            =   2832
  35.       TabIndex        =   14
  36.       Top             =   216
  37.       Width           =   1668
  38.    End
  39.    Begin Frame Frame1 
  40.       Caption         =   "Sort by:"
  41.       Height          =   1428
  42.       Left            =   2868
  43.       TabIndex        =   7
  44.       Top             =   2004
  45.       Width           =   1584
  46.       Begin OptionButton Option3 
  47.          Caption         =   "P.O. Box"
  48.          Height          =   192
  49.          Left            =   108
  50.          TabIndex        =   10
  51.          Top             =   1080
  52.          Width           =   1450
  53.       End
  54.       Begin OptionButton Option2 
  55.          Caption         =   "First name"
  56.          Height          =   288
  57.          Left            =   96
  58.          TabIndex        =   9
  59.          Top             =   672
  60.          Width           =   1450
  61.       End
  62.       Begin OptionButton Option1 
  63.          Caption         =   "Name"
  64.          Height          =   192
  65.          Left            =   108
  66.          TabIndex        =   8
  67.          Top             =   372
  68.          Value           =   -1  'True
  69.          Width           =   1450
  70.       End
  71.    End
  72.    Begin CommandButton Command4 
  73.       Caption         =   "Delete"
  74.       Height          =   252
  75.       Left            =   192
  76.       TabIndex        =   3
  77.       Top             =   3048
  78.       Width           =   900
  79.    End
  80.    Begin CommandButton Command3 
  81.       Caption         =   "Add"
  82.       Height          =   252
  83.       Left            =   192
  84.       TabIndex        =   6
  85.       Top             =   2772
  86.       Width           =   900
  87.    End
  88.    Begin CommandButton Command2 
  89.       Caption         =   "<< Prev."
  90.       Height          =   264
  91.       Left            =   204
  92.       TabIndex        =   5
  93.       Top             =   2112
  94.       Width           =   900
  95.    End
  96.    Begin CommandButton Command1 
  97.       Caption         =   "Next>>"
  98.       Height          =   264
  99.       Left            =   1716
  100.       TabIndex        =   4
  101.       Top             =   2112
  102.       Width           =   876
  103.    End
  104.    Begin Line Line2 
  105.       X1              =   2712
  106.       X2              =   2712
  107.       Y1              =   3456
  108.       Y2              =   24
  109.    End
  110.    Begin Line Line1 
  111.       X1              =   24
  112.       X2              =   7860
  113.       Y1              =   1932
  114.       Y2              =   1932
  115.    End
  116.    Begin Label datalabel3 
  117.       BorderStyle     =   1  'Fixed Single
  118.       Height          =   324
  119.       Left            =   156
  120.       TabIndex        =   13
  121.       Top             =   1524
  122.       Width           =   2460
  123.    End
  124.    Begin Label datalabel2 
  125.       BorderStyle     =   1  'Fixed Single
  126.       Height          =   324
  127.       Left            =   156
  128.       TabIndex        =   12
  129.       Top             =   864
  130.       Width           =   2460
  131.    End
  132.    Begin Label datalabel1 
  133.       BorderStyle     =   1  'Fixed Single
  134.       Height          =   324
  135.       Left            =   180
  136.       TabIndex        =   11
  137.       Top             =   216
  138.       Width           =   2460
  139.    End
  140.    Begin Label Label3 
  141.       Caption         =   "P.O.Box:"
  142.       Height          =   276
  143.       Left            =   204
  144.       TabIndex        =   2
  145.       Top             =   1272
  146.       Width           =   2496
  147.    End
  148.    Begin Label Label2 
  149.       Caption         =   "First Name:"
  150.       Height          =   276
  151.       Left            =   204
  152.       TabIndex        =   1
  153.       Top             =   600
  154.       Width           =   2496
  155.    End
  156.    Begin Label Label1 
  157.       Caption         =   "Name:"
  158.       Height          =   192
  159.       Left            =   204
  160.       TabIndex        =   0
  161.       Top             =   -12
  162.       Width           =   2496
  163.    End
  164.    Begin Menu FILE 
  165.       Caption         =   "File"
  166.       Begin Menu about 
  167.          Caption         =   "About"
  168.       End
  169.       Begin Menu separator 
  170.          Caption         =   "-"
  171.       End
  172.       Begin Menu endprogram 
  173.          Caption         =   "End"
  174.       End
  175.    End
  176. Dim database As database  'declare DATABASE as a databasevariable
  177. Dim table1 As table       'declare TABLE1 as table variable
  178. Sub about_Click ()
  179. tex$ = "DBASE-III File and Index access with VB-3." + Chr$(13) + Chr$(10) + "Little demoprogram by Peter Schulze, TY1PS. 72253,2602@compuserve.com"
  180. s% = MsgBox(tex$, 64, "Dbase-III Sample")
  181. End Sub
  182. Sub Command1_Click ()
  183. 'this moves to the next record in the database according to the current index
  184. On Error Resume Next
  185. table1.MoveNext
  186. refresh_display
  187. End Sub
  188. Sub Command2_Click ()
  189. 'this moves to the previous record in the database according to the current index
  190. On Error Resume Next
  191. table1.MovePrevious
  192. refresh_display
  193. End Sub
  194. Sub Command3_Click ()
  195. 'this adds a new record to the table
  196. ' all index files will be updated automatically
  197. table1.AddNew
  198. table1("NAME") = InputBox("Name")
  199. datalabel1.Caption = table1("NAME")
  200. table1("FIRST_NAME") = InputBox("First Name")
  201. datalabel2.Caption = table1("FIRST_NAME")
  202. table1("POBOX") = InputBox("PO BOX")
  203. datalabel3.Caption = table1("POBOX")
  204. table1.Update
  205. refresh_list
  206. End Sub
  207. Sub Command4_Click ()
  208. ' this removes the current record from the database
  209. On Error Resume Next
  210. table1.Delete
  211. table1.MoveFirst
  212. refresh_list
  213. refresh_display
  214. End Sub
  215. Sub endprogram_Click ()
  216. Unload form1  'END the program
  217. End Sub
  218. Sub Form_Load ()
  219. On Error Resume Next
  220. ' We first have to open the database.
  221. ' VB-3 treats the directory containing all database file as 'The Database'
  222. ' therefore the OpenDatabase command points to a disk directory
  223. ' make sure to have the DBF and NDX files in the c:\dbsample directory
  224. ' the two 'false', 'false' declarations assure that the file is open
  225. ' in multiuser mode and for read and write operations
  226. pat$ = "C:\DBSAMPLE"
  227. newpat:
  228. Set database = OpenDatabase(pat$, False, False, "Dbase III;")
  229. If Err Then
  230. catcherror:
  231.     pat$ = InputBox("Please indicate the path where the BBS.DBF file can be found", pat$)
  232.         If Len(pat$) = 0 Then End
  233.     Err = 0
  234.     GoTo newpat
  235. End If
  236. ' now VB knows where to find all information releated to the database. All DBF and NDX files
  237. ' must be in the same directory.
  238. ' Next we select the data we want to work with. This is called a table.
  239. ' Each table is represented as a .DBF file. You can have as many tables as you like in
  240. ' a database (=disk directory).
  241. ' Each table is kept in a seperate .DBF file.
  242. ' in this example we access a Table called BBS.DBF
  243. ' A table contains the actual data as well as the field structures.
  244. ' You can create new tables using VB commands but it is much easier
  245. ' to use the Datamgr.Exe program that comes with VB for this purpose.
  246. ' To create a new table (DBF) file with datamgr select 'Open Database' from the 'FILE' menu.
  247. ' Yes this is a bit strange, the 'new database' menu will not allow for the
  248. ' creation of new tables in dbase format, but' 'Open Database' does
  249. ' now select 'DBASE-III' and then choose the directory where you want to create the files.
  250. ' The 'new table' button now creates new DBF files, whereas you can add .NDX index files with the
  251. ' 'ADD/DELETE INDEXES' options. More about indexs later.
  252. Err = 0
  253. Set table1 = database.OpenTable("BBS")
  254. If Err Then GoTo catcherror
  255. ' now we have opened the BBS.DBF datafile and it is ready for use
  256. ' in order to speed up searches in a database, we have to use what is called Indexes.
  257. ' a index is nothing else but sort key for your data.
  258. ' This allows us to quickly change the sort order and search for records without
  259. ' the need to call a lenghtly sort routine.
  260. ' Dbase uses .NDX files to keep indexes. Each index has its own .NDX file.
  261. ' You can have as many NDX files as you wish, but you should keep them to the minimum needed
  262. ' as otherwise keeping track of all the .NDX files will slow your program down.
  263. ' in this sample i have declared 3 Indexes:
  264. ' NAME (NAME.NDX) contains the data sorted by name
  265. ' FIRSTNAM (FIRSTNAM.NDX) sorts by the first name
  266. ' POBOX (POBOX.NDX) sorts by the boxnumber
  267. ' with these 3 indexes avaiable i can easily change the order of my records by changing
  268. ' the index used, without the need to re-sort all data.
  269. ' at startup i select 'name' as index. this means the data will be sorted by name.
  270. ' indexing is also essential to quickly find data in the database.
  271. ' with indexes i can use the very quick 'SEEK' command.
  272. ' without indexes i woul have to use 'Findfirst' which is a lot slower.
  273. table1.Index = "NAME"
  274. ' now i want to have something on the screen at program start, so i call the
  275. ' routine that refreshes
  276. ' my screen
  277. refresh_display
  278. refresh_list
  279. ' this ends the initialisation
  280. End Sub
  281. Sub Form_Unload (Cancel As Integer)
  282. ' before ending i have to close my tables and database
  283. ' this assures that all is written to disk and no data lost
  284. table1.Close
  285. database.Close
  286. End Sub
  287. Sub Option1_Click ()
  288. ' i want the data to be sorted by name.
  289. ' setting the index to "NAME" does the job
  290. table1.Index = "NAME"
  291. refresh_list
  292. refresh_display
  293. End Sub
  294. Sub Option2_Click ()
  295. ' i want the data to be sorted by First name.
  296. ' setting the index to "FIRSTNAM" does the job
  297. table1.Index = "FIRSTNAM"
  298. refresh_list
  299. refresh_display
  300. End Sub
  301. Sub Option3_Click ()
  302. ' i want the data to be sorted by PO-BOX number
  303. ' setting the index to "POBOX" does the job
  304. table1.Index = "POBOX"
  305. refresh_list
  306. refresh_display
  307. End Sub
  308. Sub refresh_display ()
  309. 'this updates my screen
  310. On Error Resume Next
  311. datalabel1.Caption = table1("NAME")
  312. datalabel2.Caption = table1("FIRST_NAME")
  313. datalabel3.Caption = table1("POBOX")
  314. End Sub
  315. Sub refresh_list ()
  316. ' this updates the list boxes
  317. list1(0).Clear
  318. list1(1).Clear
  319. list1(2).Clear
  320. table1.MoveFirst
  321. Do While Not table1.EOF
  322. list1(0).AddItem table1("NAME")
  323. list1(1).AddItem table1("FIRST_NAME")
  324. list1(2).AddItem table1("POBOX")
  325. table1.MoveNext
  326. table1.MoveFirst
  327. End Sub
  328.