home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Basic / Visual Basic.60 / COMMON / TOOLS / VCM / VCM.MDB / VcmComponentContainer / 01_Cabinet / CtlView.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-05-18  |  5.6 KB  |  159 lines

  1. VERSION 5.00
  2. Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDatLst.OCX"
  3. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "ComDlg32.OCX"
  4. Begin VB.Form frmCtlView 
  5.    BackColor       =   &H8000000C&
  6.    Caption         =   "Control Viewer Sample"
  7.    ClientHeight    =   8595
  8.    ClientLeft      =   165
  9.    ClientTop       =   450
  10.    ClientWidth     =   10680
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   573
  13.    ScaleMode       =   3  'Pixel
  14.    ScaleWidth      =   712
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin MSComDlg.CommonDialog dlgFind 
  17.       Left            =   7800
  18.       Top             =   480
  19.       _ExtentX        =   847
  20.       _ExtentY        =   847
  21.       _Version        =   393216
  22.    End
  23.    Begin MSDataListLib.DataList lstControls 
  24.       Height          =   9030
  25.       Left            =   0
  26.       TabIndex        =   1
  27.       Top             =   420
  28.       Width           =   2595
  29.       _ExtentX        =   4577
  30.       _ExtentY        =   15928
  31.       _Version        =   393216
  32.    End
  33.    Begin VB.Label lblInfo 
  34.       Appearance      =   0  'Flat
  35.       AutoSize        =   -1  'True
  36.       BorderStyle     =   1  'Fixed Single
  37.       Caption         =   $"CtlView.frx":0000
  38.       ForeColor       =   &H8000000D&
  39.       Height          =   420
  40.       Left            =   0
  41.       TabIndex        =   0
  42.       Top             =   0
  43.       Width           =   10635
  44.       WordWrap        =   -1  'True
  45.    End
  46. Attribute VB_Name = "frmCtlView"
  47. Attribute VB_GlobalNameSpace = False
  48. Attribute VB_Creatable = False
  49. Attribute VB_PredeclaredId = True
  50. Attribute VB_Exposed = False
  51. Option Explicit
  52. Dim rsControls As New ADODB.Recordset
  53. Dim cnControls As New ADODB.Connection
  54. Dim oControl As Object
  55. Private Sub Form_Load()
  56.     On Error GoTo FindErr
  57.     Dim strQ As String ' query string
  58.     strQ = "Provider=Microsoft.Jet.OLEDB.3.51;Data source=" & App.Path & "\controls.mdb"
  59.     cnControls.Open strQ
  60.     rsControls.Open "select * from controls order by description", cnControls, adOpenKeyset, adLockOptimistic
  61.     lstControls.ListField = "Description"
  62.     Set lstControls.RowSource = rsControls
  63.     Exit Sub
  64. FindErr:
  65.     ' If the database isn't found, use the FindDB function to find it.
  66.     If Err.Number = -2147467259 Then
  67.     cnControls.Open "Provider=Microsoft.Jet.OLEDB.3.51;Data source=" & FindDB("controls.mdb")
  68.     Resume Next
  69.     End If
  70.     Exit Sub
  71. End Sub
  72. Private Function FindDB(dbName As String) As String
  73.     On Error GoTo ErrHandler
  74.     ' Configure cmdDialog in case the database can't be found.
  75.     With dlgFind
  76.         .DialogTitle = "Can't Find " & dbName
  77.         .Filter = "(*.MDB)|*.mdb"
  78.         .CancelError = True   'Causes an error if user clicks on cancel
  79.         .ShowOpen
  80.     End With
  81.     ' Test the string to ensure it's the sought database.
  82.     Do While Right(Trim(dlgFind.FileName), Len(dbName)) <> dbName
  83.        MsgBox "File Name is not equal to " & dbName
  84.        dlgFind.ShowOpen
  85.     Loop
  86.     FindDB = dlgFind.FileName ' return the full path.
  87.     Exit Function
  88. ErrHandler:
  89.     If Err = 32755 Then
  90.       Unload Me
  91.     End If
  92. End Function
  93. Private Sub Form_Resize()
  94.   lblInfo.Width = ScaleWidth
  95.   lstControls.Move 0, lblInfo.Height, lstControls.Width, ScaleHeight - lblInfo.Height
  96. End Sub
  97. Private Sub lstControls_Click()
  98.   Dim vControlLicense As Variant
  99.   Dim vControlType As Variant
  100.   Dim vPropertyName As Variant
  101.   Dim vPropertyValue As Variant
  102.   Dim vControlWidth As Variant
  103.   Dim vControlHeight As Variant
  104.   Dim sError As String
  105.   If Not oControl Is Nothing Then
  106.     Controls.Remove oControl
  107.     Set oControl = Nothing
  108.   End If
  109.   rsControls.MoveFirst
  110.     If rsControls.EOF Then Exit Do
  111.     If rsControls.Fields("Description") = lstControls.BoundText Then
  112.       Exit Do
  113.     End If
  114.     rsControls.MoveNext
  115.   Loop
  116.   vPropertyName = rsControls.Fields("PropertyName")
  117.   vPropertyValue = rsControls.Fields("PropertyValue")
  118.   vControlLicense = rsControls.Fields("ControlLicense")
  119.   vControlType = rsControls.Fields("ControlType")
  120.   vControlWidth = rsControls.Fields("ControlWidth")
  121.   vControlHeight = rsControls.Fields("ControlWidth")
  122.   On Error GoTo CantFindControl
  123.   If (Not IsNull(vControlLicense)) Then
  124.     sError = "unable to add license"
  125.     Licenses.Add vControlType, vControlLicense
  126.   End If
  127.   sError = "unable to create control license"
  128.   Set oControl = Controls.Add(vControlType, "MyControl")
  129.   If (Not IsNull(vControlLicense)) Then
  130.     sError = "unable to remove license"
  131.     Licenses.Remove vControlType
  132.   End If
  133.   If (Not IsNull(vControlWidth)) Then
  134.     sError = "unable to set Width"
  135.     oControl.Width = vControlWidth
  136.   End If
  137.   If (Not IsNull(vControlHeight)) Then
  138.     sError = "unable to set Height"
  139.     oControl.Height = vControlHeight
  140.   End If
  141.   sError = "unable to set Left"
  142.   oControl.Left = lstControls.Width + ((ScaleWidth - lstControls.Width) - oControl.Width) / 2
  143.   sError = "unable to set Top"
  144.   oControl.Top = lblInfo.Height + ((ScaleHeight - lblInfo.Height) - oControl.Height) / 2
  145.   sError = "unable to set Visible"
  146.   oControl.Visible = True
  147.   If (Not IsNull(vPropertyName)) Then
  148.     sError = "unable to set Property '" & vPropertyName & "'"
  149.     If (Left$(vControlType, 3) = "VB.") Then
  150.       CallByName oControl, vPropertyName, VbLet, vPropertyValue
  151.     Else
  152.       CallByName oControl.object, vPropertyName, VbLet, vPropertyValue
  153.     End If
  154.   End If
  155.   Exit Sub
  156. CantFindControl:
  157.   MsgBox "Error adding control '" & vControlType & "', " & sError & ", " & Err.Description
  158. End Sub
  159.