home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic 4 Unleashed
/
Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso
/
codebsic
/
demosubs.bas
< prev
next >
Wrap
BASIC Source File
|
1995-02-01
|
8KB
|
319 lines
Option Explicit
'Global structure pointers
Global cb As Long, rc As Integer
Global fPath As String
Global studentDbf As Long, schoolDbf As Long, gradesDbf As Long
Global studentMaster As Long, schoolSlave As Long, gradesSlave As Long
Global schoolIdTag As Long, gradesIdTag As Long
Global schoolFldID As Long, studentFldID As Long
'Global variables
Global gbChangingRec As Integer, glPrevRecno As Long
Global gbAppending As Integer, gbAutoSave As Integer
Global gbQueryChanged As Integer, gbSortChanged As Integer
Global gsTempBuf As String, gbOpenExcl As Integer
Global giMsgResponse As Integer, gbFormPurpose As Integer
Global gsQueryExpr As String, gsSortExpr As String
'Loop counters
Global i As Integer, j As Integer
'Arrays of help information
Global studentHelp() As String
Global gradesHelp() As String
Global schoolHelp() As String
Global buttonHelp() As String
'Program Messages
Global Const TITLE = "CodeBasic 5.1"
Global Const INVALID_TAG_NAME = "Invalid Tag name."
Global Const LAST_SEEK_FAILED_MSG = "Would you like to return to your orginal position in database?"
Global Const NAT_ORDER = "NATURAL ORDER"
Global Const NAT_ORDER_INVALID_MSG = "You cannot use NATURAL ORDER in a seek operation. Select one of the other index tags from the list."
Global Const UNIQUE_MSG = "This Student ID already exists, and this value must be unique. Cannot update."
Global Const VALID_EXPR = "Expression(s) is valid."
Global Const CMD_OK = 0
Global Const CMD_CANCEL = 1
'Indexes of various button bars
'File
Global Const B_OPEN = 0
Global Const B_CLOSE = 1
Global Const B_EXIT = 2
Global Const B_UNDO = 3
Global Const B_SAVE = 4
'Order/Query
Global Const B_SEEK = 0
Global Const B_QUERY = 1
Global Const B_SORT = 2
'Record
Global Const B_APPEND = 0
Global Const B_DELETE = 1
Global Const B_PACK = 2
Global Const B_ZAP = 3
'Position
Global Const B_TOP = 0
Global Const B_NEXT = 2
Global Const B_LAST = 1
Global Const B_BOTTOM = 3
'Check Options
Global Const C_AUTO_SAVE = 0
Global Const C_HIDE_DEL = 1
Global Const C_CON_DEL = 2
Global Const C_OPEN_EXCL = 3
Global Const MED_BLUE = &H808000
Global Const DK_BLUE = &HC00000
Global Const DK_LAV = &H800080
Global Const MED_GRAY = &HC0C0C0
Global Const LT_YELLOW = &HFFFF&
Global Const MED_RED = &HC0
'Cursor values
Global Const DEFAULT = 0
Global Const HOURGLASS = 11
' MsgBox parameters
Global Const MB_OK = 0 ' OK button only
Global Const MB_OKCANCEL = 1 ' OK and Cancel buttons
Global Const MB_ABORTRETRYIGNORE = 2 ' Abort, Retry, and Ignore buttons
Global Const MB_YESNOCANCEL = 3 ' Yes, No, and Cancel buttons
Global Const MB_YESNO = 4 ' Yes and No buttons
Global Const MB_RETRYCANCEL = 5 ' Retry and Cancel buttons
Global Const MB_ICONSTOP = 16 ' Critical message
Global Const MB_ICONQUESTION = 32 ' Warning query
Global Const MB_ICONEXCLAMATION = 48 ' Warning message
Global Const MB_ICONINFORMATION = 64 ' Information message
' MsgBox return values
Global Const IDOK = 1 ' OK button pressed
Global Const IDCANCEL = 2 ' Cancel button pressed
Global Const IDABORT = 3 ' Abort button pressed
Global Const IDRETRY = 4 ' Retry button pressed
Global Const IDIGNORE = 5 ' Ignore button pressed
Global Const IDYES = 6 ' Yes button pressed
Global Const IDNO = 7 ' No button pressed
'Key codes
Global Const KEY_PRIOR = &H21
Global Const KEY_NEXT = &H22
Global Const KEY_END = &H23
Global Const KEY_HOME = &H24
'Flags for use of form 'GenForm'
Global Const ZAP_FORM = 0
Global Const GOTO_FORM = 1
Function atrim$ (s As String)
atrim = LTrim$(RTrim$(s))
End Function
Function cbErr ()
'This function resets error code to 0 ( non-error state)
'and returns true if an error state existed
If code4errorCode(cb, 0) < 0 Then cbErr = True
End Function
Sub CenterForm (frm As Form)
If frm.Width > Screen.Width Then
frm.Left = 0
Else
frm.Left = (Screen.Width - frm.Width) / 2
End If
If frm.Height > Screen.Height Then
frm.Top = 0
Else
frm.Top = (Screen.Height - frm.Height) / 2
End If
End Sub
Sub FillList (c As Control, ByVal fldPtr As Long)
'Fills a list box with field values
Dim dbf As Long
dbf = f4data(fldPtr) 'Get data pointer from field pointer info
rc = d4top(dbf)
'Skip through each record
For i = 1 To d4reccount(dbf)
c.AddItem f4str(fldPtr)
rc = d4skip(dbf, 1)
Next
End Sub
Function GetTagName$ ()
'This function returns the name of the currently selected tag
Dim tempBuf As String
tempBuf = tag4alias(d4tagSelected(studentDbf))
If InStr(tempBuf, "0") > 0 Then
GetTagName = Left$(tempBuf, Len(tempBuf) - 1)
Else
GetTagName = tempBuf
End If
End Function
Sub InitHelp ()
'This routine initializes various arrays of help information text
ReDim studentHelp(0 To 9)
ReDim schoolHelp(0 To 3)
ReDim gradesHelp(0)
ReDim buttonHelp(3, 4)
studentHelp(0) = "Enter student's first name"
studentHelp(1) = "Enter student's last name"
studentHelp(2) = "Enter student's ID"
studentHelp(3) = "Enter address"
studentHelp(4) = "Enter address"
studentHelp(5) = "Enter city"
studentHelp(6) = "Enter province or state abbreviation"
studentHelp(7) = "Enter postal or zip code"
studentHelp(8) = "Enter student's country"
studentHelp(9) = "Enter student's area code + ph. number"
schoolHelp(0) = "Enter school name"
schoolHelp(1) = "Enter school type"
schoolHelp(2) = "Enter name of principal"
schoolHelp(3) = "Select school ID"
gradesHelp(0) = "Enter grade for this class"
buttonHelp(0, 0) = "Position to top of file"
buttonHelp(0, 1) = "Skip back one record"
buttonHelp(0, 2) = "Skip forward one record"
buttonHelp(0, 3) = "Position to end of file"
buttonHelp(1, 0) = "Seek a record"
buttonHelp(1, 1) = "Perform a query"
buttonHelp(1, 2) = "Select record ordering via Index"
buttonHelp(2, 0) = "Add a new record"
buttonHelp(2, 1) = "Mark/Unmark a record for deletion"
buttonHelp(2, 2) = "Remove deleted records (Pack)"
buttonHelp(2, 3) = "Remove a range of records (Zap)"
buttonHelp(3, 0) = "Open demo files"
buttonHelp(3, 1) = "Close demo files"
buttonHelp(3, 2) = "Exit program"
buttonHelp(3, 3) = "Undo changes"
buttonHelp(3, 4) = "Save current changes"
End Sub
Sub ListTags (l As ComboBox)
'Fill combo box with index tag names
Dim tagPtr As Long
l.AddItem "NATURAL ORDER"
'Get first tag pointer, if any
tagPtr = d4tagNext(studentDbf, tagPtr)
Do While tagPtr <> 0
'Get tag name
gsTempBuf = tag4alias(tagPtr)
'Don't show 'Filtered' tag names, which end in "0"
If Right$(gsTempBuf, 1) <> "0" Then l.AddItem gsTempBuf
'Get next tag pointer if any
tagPtr = d4tagNext(studentDbf, tagPtr)
Loop
End Sub
Sub Main ()
'Initialize the CodeBasic 5.1 DLL
cb = d4init()
'Error if cb = 0
If cb = 0 Then Exit Sub
'Initialize arrays of help info
InitHelp
'Do it
MainForm.Show 1
'Free DLL resources
cb = d4initUndo(cb)
End
End Sub
Sub SelectText ()
Screen.ActiveControl.SelStart = 0
Screen.ActiveControl.SelLength = Len((Screen.ActiveControl.Text))
End Sub
Function UpperAlpha% (kAscii As Integer)
If kAscii >= 97 And kAscii <= 122 Then
UpperAlpha = kAscii - 32
Else
UpperAlpha = kAscii
End If
End Function
Function ValidTagName (TagName$, dbfPtr&)
'This function determines if 'TagName' is a valid tag for
'STUDENT.DBF
Dim tagPtr As Long
If atrim(TagName) = "" Then Exit Function
If UCase(TagName) = "NATURAL ORDER" Then
ValidTagName = True
Exit Function
End If
tagPtr = d4tagNext(dbfPtr, tagPtr)
Do While tagPtr <> 0
If UCase$(tag4alias(tagPtr)) = UCase$(atrim(TagName)) Then
ValidTagName = True
Exit Function
End If
tagPtr = d4tagNext(studentDbf, tagPtr)
Loop
End Function