home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / data_tbl / demo2.frm (.txt) < prev    next >
Visual Basic Form  |  1993-05-11  |  11KB  |  211 lines

  1. Form1
  2. !DataTable Example Program - DEMO2
  3. wwwwwwwwwwwwwp
  4. wwwwwwwwwwwwwww
  5. wwwwwp
  6. wwwwwp
  7. Form1
  8. Customer
  9.     DATATABLE
  10. C:\CUSTOMER
  11. Label1
  12. Name:
  13. CustomerName
  14. Label2
  15. Address:
  16. Address
  17. Label3
  18. City:
  19. Label4
  20. State:
  21. State
  22. Label5
  23. Label6
  24. Phone:
  25. Phone
  26.     TopButton
  27. NextButton
  28. InsertButton
  29. Insert
  30. DeleteButton
  31. Delete
  32. QuitButton
  33. BottomButton
  34. Bottom
  35. PreviousButton
  36. Previous
  37. UpdateButton
  38. Update
  39. ClearButton
  40. Clear
  41. QuitButton_Click
  42. Form_Click
  43.     Form_Load>
  44. Customer
  45.     OpenTableg
  46. Action
  47. CloseTable%
  48. FillForm
  49.     GetRecord
  50.     FieldName
  51. GetField
  52. CustomerName:
  53. Text$
  54. FieldValue
  55. Address
  56. StateW
  57. Phone}
  58.     InsertRecW
  59. PutField
  60. InsertRecord
  61. InsertButton_Click
  62. ClearButton_Click
  63. TopButton_Click
  64. FirstRecord
  65. BottomButton_Click
  66. LastRecord
  67. NextButton_Click
  68. NextRecord
  69. PreviousButton_ClickJ
  70. PreviousRecord
  71. DeleteButton_Click
  72. DeleteRecord
  73.     UpdateRec
  74. UpdateRecord
  75. UpdateButton_Click
  76. Reaction
  77. DisplayError
  78. TheError
  79. CustomerName_Change
  80. CustomerName_LostFocus
  81. SearchMode
  82. SEARCHFIRST
  83. SearchField
  84. TheNameTyped'
  85. database
  86. table
  87.     DataTable
  88. Form_Load
  89. Open up the database table
  90. Now fill the form with data 
  91. in the first record.
  92. QuitButton_Click
  93. Close the database table
  94. And quit the program
  95. FillForm
  96. We need to get the current record in the database:
  97. Ok, now lets get the values in the database fields for the
  98. record we just read in::
  99. We need to make a one-to-one relationship between the fields in the database table
  100. and the fields on our Visual Basic Form. We will read in the field values from the
  101. database record and place those values into the .TEXT property of our TEXT controlss
  102. on our Visual Basic form. For each field of interest this is a three-step process:
  103. 1. Specify the name of the database field of interest ---> DataTable.FieldName = "
  104. 2. Get the field value ---> DataTable.Action = GetFieldd
  105. 3. Place the field value in the TEXT control ---> Text1.TEXT = DataTable.FieldValuee
  106. Thats all there is to it!!
  107. You should make a FillForm like subroutine position independent. Notice that the first line of
  108. code in this subroutine reads in the current record. Use other routines to move around
  109. in the table (like the TOP,BOTTOM, NEXT and PREVIOUS buttons in this demo). Making the
  110. routine position independent means that it can be used and re-used at any time to fill inn
  111. your form with information from any record in your database.
  112. We will fill in the form now:o
  113. Address"
  114. State"
  115. Phone"
  116. InsertRec
  117. Here we transfer the information from the Visual Basic Form and insert itt
  118. into the database table.
  119. To do this requires a three-step process for each field in the database table:
  120. 1. Specify the name of the field of interest ---> DataTable.FieldNamee
  121. 2. Specify the field value ---> DataTable.FieldValue = A String valuee
  122. 3. Put the field into the DataTable record ---> DataTable.Action = PutFieldd
  123. We do this for each field in the database table.
  124. When we are finished we INSERT the record into the
  125. database table ---> DataTable.Action = InsertRecordd
  126. Address"
  127. State"
  128. Phone"
  129. InsertButton_Click
  130. ClearButton_Click
  131. This code simply clears the text in all of the Visual Basic form's Text controls..
  132. TopButton_Click
  133. The following code moves to the first record in the data basen
  134. and fills in our form with the information found in that first
  135. record
  136. Moveto the first record in the database
  137. Fill in the form with data
  138. BottomButton_Click
  139. The following code moves to the last record in the data base
  140. and fills in our form with the information found in that last
  141. record
  142. Move to the last recordd
  143. Fill the form 
  144. NextButton_Click
  145. The following code moves to the next record in the database table. If an
  146. error is encountered during the move to the next record an error message is displayed.
  147. The DisplayError subroutine is an example of the structure of a generalized 
  148. DataTable error handling routine. 
  149. Once the repositioning to the next record is successfull, we fill in our form
  150. with information from that record.
  151. Moving to the next record in the databaseu
  152. If an errort
  153. Display the DataTable errore
  154. If no error
  155. Fill in our form with the information in the record.
  156. PreviousButton_Click
  157. The following code moves to the previous record in the database table. If an
  158. error is encountered during the move to the record an error message is displayed.a
  159. The DisplayError subroutine is an example of the structure of a generalizedl
  160. DataTable error handling routine. 
  161. Once the repositioning to the previous record is successfull, we fill in our forma
  162. with information from that record.
  163. Moving to previous records
  164. If an errors
  165. Display the DataTable Errorr
  166. If no error
  167. Fill in our form with info from the record
  168. DeleteButton_Click
  169. This code deletes the current record from the database
  170. The current record after the delete is performed, is the record immediatelyr
  171. following the deleted record. We then fill in our form with info from that
  172. record.n
  173. We will delete the current record.
  174. Now fill in form with the current record.
  175. UpdateRec
  176. Here we transfer the information from the Visual Basic Form and update the current record
  177. in the database table.
  178. To do this requires a three-step process for each field in the database table:
  179. 1. Specify the name of the field of interest ---> DataTable.FieldNames
  180. 2. Specify the field value ---> DataTable.FieldValue = A String values
  181. 3. Put the field into the DataTable record ---> DataTable.Action = PutFieldl
  182. We do this for each field in the database table.
  183. When we are finished we UPDATE the record in the
  184. database table ---> DataTable.Action = UpdateRecordd
  185. Address"
  186. State"
  187. Phone"
  188. UpdateButton_Click
  189. DisplayError
  190. Here we show how to build a general purpose error routine for the DataTablee
  191. it is not complete but gives you the basic idea of how to build such a routine..
  192. For a listting of all DataTable error codes see the Working Model documentation.
  193. Drive not ready!
  194. Directory not found!
  195. File is busy!"
  196. File is Locked!"
  197. File not Found!"
  198.  Record not Found!
  199. End of Table!"
  200. Start of Table!"
  201. Unknown Error!
  202. CustomerName_LostFocus
  203. This code demonstrates how to search a database on a specific field for a given value.
  204. When you leave this field, this lost focus subroutine is executed.
  205. The value in the CustomerName.Text is then searched for in the database table.
  206. The database field searched is "Name".
  207. If the search is successfull the record is displayed on the form. If the searchh
  208. fails an error message is displayed, the form is cleared (with the typed in value)
  209. replaced in the CustomerName.Text expecting to get a new customer's information.
  210. Temporary variable to hold Customer's name.d
  211.