Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Games in Visual Basic: Data base Catch up questions Data base: generalities & specifics on Visual Basic links Lab: work on projects.

Similar presentations


Presentation on theme: "Programming Games in Visual Basic: Data base Catch up questions Data base: generalities & specifics on Visual Basic links Lab: work on projects."— Presentation transcript:

1 Programming Games in Visual Basic: Data base Catch up questions Data base: generalities & specifics on Visual Basic links Lab: work on projects.

2 Questions? Hangman –‘word bank’ is an array of strings –Dynamically loading alphabet (label control array) –String operations Cannonball –moving ball (setup in Fire button Click, movement & checking for hitting target or ground in timer) –press button & drag

3 Suggestions Reflect [back] on a project. What was difficult? What was similar to another project? Similarities & differences between projects –Use of images in memory versus mixed & hangman –Use of Booleans (flags) for firstturn & follow-up in chance, first and second turns in memory –Clicking on labels –Data in labels (memory) versus internal variables –Counting: matches in memory; matches in hangman; turns in hangman –?

4 Data base terminology is a collection of files. A data base management system (DBMS) is a software application for creating & modifying databases and for producing report. Database Tables Records (‘rows’) Fields (attributes, ‘columns’)

5 Example (simpler than in quiz) Table = the questions A question holds: –Text of question –Answer –Value –Category So, in the simple case: 4 fields = 4 attributes. Datatype of 1 st and 2 nd and 4 th field is text. Datatype of 3 rd field is number.

6 Data base terminology, cont. A query is a request for information from a data base. SQL (structured query language) is the standard for queries to a data base. Select * from questions where category = ‘trivia’ Get the whole record (all attributes) from all the records from the questions table in which the category attribute equals ‘trivia’ Select question, answer from questions where used= ‘false’ Get the question and answer attributes from the questions table in which the used attribute is false Select distinct category from archive Get all the distinct (no duplicate) values of the category attribute

7 Advanced Warning Visual Basic statements involving Select statements have complex syntax: –A string containing the Select statement is sent to the database. –The string may be made by concatenating strings and the value of variables. –There may be single quotation marks and double quotation marks. –Long statements may need to be continued on the next line, requiring an underscore _

8 Quiz project VB to DB connection for –Controls on quiz form and DB edit form Set properties in the data control –Generating list of categories Generate a special recordset with just one field –Generating list of non-used questions within a specific category Generate a recordset for the controls. Use Rnd to advance the cursor to a random choice within this set.

9 Setting up VB to database connections Connecting data control to the database and the table (there is only one) in the database dbQuestions.DatabaseName = App.Path & "/quiz.mdb" dbQuestions.RecordSource = "archive" In the eventhandler for setting up the list of categories Dim dbQuestions as DataBase Dim rst as Recordset Set dbQuestions = OpenDatabase(App.Path & "/quiz.mdb") Set rst = _ dbQuestions.OpenRecordset("Select distinct category from archive")

10 Example of query Note: your code has already set up dbQuestions as the link to the database. dbQuestions.RecordSource = "Select * from " _ & "archive where category = '" & strCat _ & "' And " _ & "used = 0“ The words “Select * from archive where category = ‘” are taken literally. Then it is combined with the value of strCat and then the literal “’ And used = 0” The single quotation marks will surround the actual value in the variable strCat (namely the selected category).

11 Visual Basic / Data base Data control –at design time or run time, specify database AND table Database ‘aware’ controls –link to the data control AND link to specific field

12 Click & then select database Choose table in database

13 When the pulldown was clicked, the menu shows the only data control. Field in table in database

14 Visual Basic / database Recordset is set (sequence) of records! Implicit notion of the current record. This can be changed –movefirst –movenext –moveprev

15 Recordsets Can be associated with a data control and controls on the form OR can be independent of data control (and controls on the form)

16 Quiz project Database is one table, named questions A question is a record in the table. Question includes the following fields: Question text two model answers (more on this later) Point value (may be set as currency) category used switch (yes/no)

17 Comparing strings to patterns Various ways of using special characters for patterns. The patterns suggested in the text use just the wild card character * If strAns Like strModel then … If strAns holds “Christopher Columbus” and strModel holds “*Columbus” then the Like operator will return true Consult HELP for more possibilities

18 Homework/Lab Continue with projects Read text Note: chapter 7 / Quiz show is one of the 'advanced' projects. Your own project can be enhancement of one of the 6 projects, one of the advanced projects or an existing game or something totally of your own design.


Download ppt "Programming Games in Visual Basic: Data base Catch up questions Data base: generalities & specifics on Visual Basic links Lab: work on projects."

Similar presentations


Ads by Google