Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Aug 21, 1997

A New Data Programming Style

While working on VB projects with associated Jet databases, I found that I was creating a lot of individual handling functions for reading, writing, and validating data. It was hard to keep track of changes made to the table structures and to their associated handling functions. As a result, I've developed new programming style. My read /write and special functions are all in one routine selected by case logic based on descriptive strings. The strings are used only within the programs and are self documenting to some extent. Data is passed through a Public WorkVariant array:
 
Public MyDB As Database
Public WorkVariant(10) As Variant
Dim Dummy As Integer
Set MyDB = OpenDatabase("testjet3db")
'Sample calls
Dummy = NameTableIO("writerecord")
Dummy = NameTableIO("readrecord")
Public Function NameTableIO_
	(ByVal whichAction As String) As Integer
'Assumes navigation to the record has 
'been made externally
Dim MyTable As Recordset
Dim ErrorStage As String
On Error GoTo NameTableIOError
	NameTableIO = True
	ErrorStage = "OpenRecordSet"
	Set MyTable = MyDB.OpenRecordset("NameTable")
	ErrorStage = "AfterOpen"
	Select Case whichAction
		Case "readrecord"
			WorkVariant(1) = MyTable![FirstName]
			WorkVariant(2) = MyTable![Age]
		Case "writerecord"
			MyTable.Edit
				MyTable![FirstName] = WorkVariant(1)
				MyTable![Age] = WorkVariant(2)
			MyTable.Update
Case "validateage"	'specialized routine
		'etc
End Select
NameTableIOErrorExit:

	If ErrorStage <> "OpenRecordSet" Then
		MyTable.Close
	End If
	Set MyTable = Nothing
Exit Function
NameTableIOError:

	NameTableIO = False
	MsgBox Error$ &_
		" Error trap in NameTableIO " & _
		"at " & ErrorStage & " Action: " & whichAction
	Resume NameTableIOErrorExit
End Function
Stan Mlynek
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date