Application developed with Visual Basic, Part 7.

 

  1. The Book.Frm View Code - Part 2.

    Resume :
    • To initialize the TabStrip control.

      Note:
      Visual Basic automatically determines the size and position of the internal area and returns the Client-coordinate properties – ClientLeft, ClientTop, ClientHeight, and ClientWidth.

     

    View Code, examine these changes - the new text Code to be add is red.

    Dim WithEvents adoPrimaryRS As Recordset

    ' Type of strdatasource
    Dim strdatasource As String

    -----------------------------------------------------------------------------------------------------------------------
    Private Sub Form_Load()
    'Data Soure at current directory
    strdatasource = App.Path + "\res\KJV.mdb"

    'Declare the adoPrimaryRS
    Dim db As Connection
    Set db = New Connection
    db.CursorLocation = adUseClient
    db.Open "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=" & strdatasource

    Set adoPrimaryRS = New Recordset
    adoPrimaryRS.Open "select Book,BookTitle,Chapter,TextData,Verse from BibleTable", db, adOpenStatic, adLockOptimistic

    'Load icon - BookIco.ico
    Set Me.Icon = LoadPicture(App.Path & "\res\BookIco.ico")

    'Load the picture - forum.gif
    Set Image1.Picture = LoadPicture(App.Path & "\res\forum.gif")

    'Load the picture - Christus-th.gif
    Set Image2.Picture = LoadPicture(App.Path & "\res\Christus-th.gif")



    'The datasource value of TextBox
    Set Me.txtFields.DataSource = adoPrimaryRS

    'The database file Begin with the 2nd record
    adoPrimaryRS.Move (Str(2))

    ' Disable the CmdFirst and CmdPrevious CommandButtons with begin
    CmdFirst.Enabled = False
    CmdPrevious.Enabled = False

    'Calcul the values of book, title, chapter and verse
    Call LabelAddress


    'TabStrip1 - Tabstrip control, Frtb - Frame control
    For i = 0 To Frtb.Count - 1
    With Frtb(i)
    .Move TabStrip1.ClientLeft, _
    TabStrip1.ClientTop, _
    TabStrip1.ClientWidth, _
    TabStrip1.ClientHeight
    End With
    Next i
    ' Bring the first frTb control to the front.
    Frtb(0).ZOrder 0


    End Sub

    -----------------------------------------------------------------------------------------------------------------------
    Private Sub Form_Resize()
    'Image1 control size
    Image1.Left = (Picture1.Width - Image1.Width) / 2
    Image1.Top = (Picture1.Height - Image1.Height) / 2

    '
    Image2 control size
    Image2.Left = (Picture2.Width - Image2.Width) / 2
    Image2.Top = (Picture2.Height - Image2.Height) / 2

    End Sub

    ----------------------------------------------------------------------------------------------------------------------
    Private Sub Form_Unload(Cancel As Integer)
    Screen.MousePointer = vbDefault
    End Sub

    -----------------------------------------------------------------------------------------------------------------------
    Private Sub adoPrimaryRS_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
    'This will display the current record position for this recordset
    'In Visual Basic, the order of records begin with number 0
    lblStatus.Caption = "Record: " & CStr(adoPrimaryRS.AbsolutePosition - 1)
    End Sub

    ----------------------------------------------------------------------------------------------------------------------
    Private Sub cmdClose_Click()
    Unload Me
    End Sub

    -----------------------------------------------------------------------------------------------------------------------
    Private Sub cmdFirst_Click()
    On Error GoTo GoFirstError

    adoPrimaryRS.MoveFirst
    adoPrimaryRS.Move (2)

    CmdFirst.Enabled = False
    CmdPrevious.Enabled = False
    If CmdLast.Enabled = False Or CmdNext.Enabled = False Then
    CmdLast.Enabled = True
    CmdNext.Enabled = True
    End If

    Call LabelAddress

    Exit Sub

    GoFirstError:
    MsgBox Err.Description
    End Sub

    -----------------------------------------------------------------------------------------------------------------------
    Private Sub cmdLast_Click()
    On Error GoTo GoLastError

    adoPrimaryRS.MoveLast

    CmdLast.Enabled = False
    CmdNext.Enabled = False
    If CmdFirst.Enabled = False Or CmdPrevious.Enabled = False Then
    CmdFirst.Enabled = True
    CmdPrevious.Enabled = True
    End If

    Call LabelAddress

    Exit Sub

    GoLastError:
    MsgBox Err.Description
    End Sub

    -----------------------------------------------------------------------------------------------------------------------
    Private Sub cmdNext_Click()
    On Error GoTo GoNextError

    If Not adoPrimaryRS.EOF Then adoPrimaryRS.MoveNext
    If CmdFirst.Enabled = False Or CmdPrevious.Enabled = False Then
    CmdFirst.Enabled = True
    CmdPrevious.Enabled = True
    End If
    If adoPrimaryRS.EOF And adoPrimaryRS.RecordCount > 0 Then
    Beep

    CmdLast.Enabled = False
    CmdNext.Enabled = False
    End If

    Call LabelAddress

    Exit Sub
    GoNextError:
    MsgBox Err.Description
    End Sub

    -----------------------------------------------------------------------------------------------------------------------
    Private Sub cmdPrevious_Click()
    On Error GoTo GoPrevError

    If Not adoPrimaryRS.BOF And adoPrimaryRS.AbsolutePosition > 2 Then adoPrimaryRS.MovePrevious
    If CmdLast.Enabled = False Or CmdNext.Enabled = False Then
    CmdLast.Enabled = True
    CmdNext.Enabled = True
    End If

    If adoPrimaryRS.AbsolutePosition = 3 Then
    Beep
    CmdFirst.Enabled = False
    CmdPrevious.Enabled = False

    End If

    Call LabelAddress

    Exit Sub

    GoPrevError:
    MsgBox Err.Description
    End Sub

    -----------------------------------------------------------------------------------------------------------------------
    Private Sub SetButtons(bVal As Boolean)
    CmdClose.Visible = bVal
    CmdNext.Enabled = bVal
    CmdFirst.Enabled = bVal
    CmdLast.Enabled = bVal
    CmdPrevious.Enabled = bVal
    End Sub

    -----------------------------------------------------------------------------------------------------------------------
    'Calcul the values of book, title, chapter and verse
    Private Sub LabelAddress()
    Titre.Caption = "Book: " + Trim(adoPrimaryRS.Fields.Item(0).Value) + ", Title: " + Trim(adoPrimaryRS.Fields.Item(1).Value)
    Chapter.Caption = "Chapter: " + Trim(adoPrimaryRS.Fields.Item(2).Value) + ", Verse: " + Trim(adoPrimaryRS.Fields.Item(4).Value)
    End Sub

    -----------------------------------------------------------------------------------------------------------------------

    Private Sub TabStrip1_Click()
    Frtb(TabStrip1.SelectedItem.Index - 1).ZOrder 0
    End Sub


  2. To save this application; From File menu, choose and click Save Project.
  3. To run it; From Run menu, choose and click Start.

Previous
Home 7 Home
Next