Browse DevX
Sign up for e-mail newsletters from DevX

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



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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![FirstName] = WorkVariant(1)
				MyTable![Age] = WorkVariant(2)
Case "validateage"	'specialized routine
End Select

	If ErrorStage <> "OpenRecordSet" Then
	End If
	Set MyTable = Nothing
Exit Function

	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.



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