home *** CD-ROM | disk | FTP | other *** search
/ Master 95 #1 / MASTER95_1.iso / microsof / vbasic4 / vb4-6.cab / propsht.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-07-26  |  11.8 KB  |  373 lines

  1. VERSION 4.00
  2. Begin VB.Form frmPropertySheet 
  3.    ClientHeight    =   1215
  4.    ClientLeft      =   1815
  5.    ClientTop       =   2325
  6.    ClientWidth     =   7140
  7.    Height          =   1620
  8.    HelpContextID   =   2016139
  9.    Icon            =   "PROPSHT.frx":0000
  10.    Left            =   1755
  11.    LinkTopic       =   "Form2"
  12.    LockControls    =   -1  'True
  13.    MDIChild        =   -1  'True
  14.    ScaleHeight     =   1215
  15.    ScaleWidth      =   7140
  16.    Tag             =   "Properties"
  17.    Top             =   1980
  18.    Width           =   7260
  19.    Begin VB.PictureBox picPropHeader 
  20.       Align           =   1  'Align Top
  21.       Appearance      =   0  'Flat
  22.       BorderStyle     =   0  'None
  23.       ForeColor       =   &H80000008&
  24.       Height          =   315
  25.       Left            =   0
  26.       ScaleHeight     =   315
  27.       ScaleMode       =   0  'User
  28.       ScaleWidth      =   7144.253
  29.       TabIndex        =   0
  30.       Top             =   0
  31.       Width           =   7140
  32.       Begin VB.CommandButton cmdAddUDP 
  33.          Caption         =   "&Add UDP"
  34.          Height          =   300
  35.          Left            =   4080
  36.          TabIndex        =   9
  37.          Top             =   0
  38.          Width           =   1335
  39.       End
  40.       Begin VB.CommandButton cmdClose 
  41.          Caption         =   "&Close"
  42.          Height          =   300
  43.          Left            =   5400
  44.          TabIndex        =   8
  45.          Top             =   0
  46.          Width           =   1335
  47.       End
  48.       Begin VB.Label lblPropValue 
  49.          Caption         =   " Value:"
  50.          Height          =   255
  51.          Left            =   2280
  52.          TabIndex        =   2
  53.          Top             =   30
  54.          Width           =   735
  55.       End
  56.       Begin VB.Label lblPropHeader 
  57.          Caption         =   "Prop Name:"
  58.          Height          =   252
  59.          Left            =   120
  60.          TabIndex        =   1
  61.          Top             =   30
  62.          Width           =   1212
  63.       End
  64.    End
  65.    Begin VB.VScrollBar vsbScrollBar 
  66.       Height          =   2085
  67.       LargeChange     =   3000
  68.       Left            =   7200
  69.       SmallChange     =   300
  70.       TabIndex        =   7
  71.       Top             =   360
  72.       Visible         =   0   'False
  73.       Width           =   255
  74.    End
  75.    Begin VB.PictureBox picProps 
  76.       Appearance      =   0  'Flat
  77.       BorderStyle     =   0  'None
  78.       ForeColor       =   &H80000008&
  79.       Height          =   735
  80.       Left            =   0
  81.       ScaleHeight     =   729.119
  82.       ScaleMode       =   0  'User
  83.       ScaleWidth      =   7120.563
  84.       TabIndex        =   3
  85.       TabStop         =   0   'False
  86.       Top             =   360
  87.       Width           =   7125
  88.       Begin VB.TextBox txtPropData 
  89.          BackColor       =   &H00FFFFFF&
  90.          DataSource      =   "datDataCtl"
  91.          ForeColor       =   &H00000000&
  92.          Height          =   285
  93.          Index           =   0
  94.          Left            =   2280
  95.          TabIndex        =   5
  96.          Top             =   30
  97.          Visible         =   0   'False
  98.          Width           =   4575
  99.       End
  100.       Begin VB.CheckBox chkPropData 
  101.          DataSource      =   "datDataCtl"
  102.          Height          =   282
  103.          Index           =   0
  104.          Left            =   2280
  105.          TabIndex        =   4
  106.          Top             =   360
  107.          Visible         =   0   'False
  108.          Width           =   3270
  109.       End
  110.       Begin VB.Label lblPropName 
  111.          ForeColor       =   &H00000000&
  112.          Height          =   255
  113.          Index           =   0
  114.          Left            =   105
  115.          TabIndex        =   6
  116.          Top             =   40
  117.          Visible         =   0   'False
  118.          Width           =   2055
  119.       End
  120.    End
  121. Attribute VB_Name = "frmPropertySheet"
  122. Attribute VB_Creatable = False
  123. Attribute VB_Exposed = False
  124. Option Explicit
  125. '============================================================================
  126. ' This is a fairly generic form that can be used in most cases with any
  127. ' Data Access Object to display its Properties.
  128. '============================================================================
  129. Dim maPropArr() As Object
  130. Dim mPropObject As Object
  131. Dim mnNumProps As Integer       'number of Props
  132. Dim mbResizing As Integer       'flag to avoid resize recursion
  133. Dim mnPropTop As Integer        'top Prop position
  134. Sub chkPropData_Click(Index As Integer)
  135.   On Error GoTo CPDErr
  136.   If mPropObject.Properties(Index).Value = True And chkPropData(Index).Value = vbChecked Then
  137.     'first time set of value so we should just exit
  138.     Exit Sub
  139.   End If
  140.   'try to set the value if the user changed it
  141.   mPropObject.Properties(Index).Value = IIf(chkPropData(Index).Value = 1, True, False)
  142.   Exit Sub
  143. CPDErr:
  144.   ShowError
  145.   'set the control back to the original value
  146.   chkPropData(Index).Value = IIf(mPropObject.Properties(Index).Value = True, 1, 0)
  147.   Exit Sub
  148. End Sub
  149. Sub cmdAddUDP_Click()
  150.   frmAddUDP.Show vbModal
  151.   If gPropObject.Properties.Count > mnNumProps Then
  152.     LoadProps
  153.   End If
  154. End Sub
  155. Private Sub txtPropData_KeyPress(Index As Integer, KeyAscii As Integer)
  156.   'go to next Prop on an enter keypress
  157.   If KeyAscii = 13 Then
  158.     KeyAscii = 0
  159.     SendKeys "{Tab}"
  160.   End If
  161. End Sub
  162. Private Sub cmdClose_Click()
  163.   On Error Resume Next
  164.   Unload Me
  165. End Sub
  166. Sub txtPropData_LostFocus(Index As Integer)
  167.   On Error GoTo TPDErr
  168.   'don't try to set an Err value
  169.   If Left(txtPropData(Index).Text, 4) = "ERR:" Then Exit Sub
  170.   'try to set the value if the user changed it
  171.   If TypeName(mPropObject.Properties(Index).Value) = "Boolean" Then
  172.     If mPropObject.Properties(Index).Value <> CBool(txtPropData(Index).Text) Then
  173.       mPropObject.Properties(Index).Value = txtPropData(Index).Text
  174.     End If
  175.   Else
  176.     If CStr(mPropObject.Properties(Index).Value) <> txtPropData(Index).Text Then
  177.       mPropObject.Properties(Index).Value = txtPropData(Index).Text
  178.     End If
  179.   End If
  180.   Exit Sub
  181. ResetIt:
  182.   On Error Resume Next
  183.   'try to set the control back to the original value
  184.   'because an error occured
  185.   txtPropData(Index).Text = mPropObject.Properties(Index).Value
  186.   Exit Sub
  187. TPDErr:
  188.   ShowError
  189.   Resume ResetIt
  190.   Exit Sub
  191. End Sub
  192. Sub txtPropData_MouseUp(Index As Integer, Button As Integer, Shift As Integer, x As Single, Y As Single)
  193.   If Button <> 2 Then Exit Sub
  194.   SetHourglass
  195.   ShowProperties "Property", mPropObject.Properties(Index)
  196. End Sub
  197. Private Sub vsbScrollBar_Change()
  198.   Dim nCurrVal As Integer
  199.   nCurrVal = vsbScrollBar
  200.   If (nCurrVal - mnPropTop) Mod gnCTLARRAYHEIGHT = 0 Then
  201.     picProps.Top = nCurrVal
  202.   Else
  203.     picProps.Top = ((nCurrVal - mnPropTop) \ gnCTLARRAYHEIGHT) * gnCTLARRAYHEIGHT + mnPropTop
  204.   End If
  205. End Sub
  206. Private Sub Form_Load()
  207.   Dim Start As Long, Finish As Long
  208.   On Error GoTo LoadErr
  209.   Set mPropObject = gPropObject
  210.   Me.Width = 7050
  211.   LoadProps
  212.   Me.Show
  213.   maPropArr(0).SetFocus
  214.   Screen.MousePointer = vbDefault
  215.   Exit Sub
  216. LoadErr:
  217.   Screen.MousePointer = vbDefault
  218.   MsgBox "Error:" & Err & " " & Error
  219.   Unload Me
  220.   Exit Sub
  221. End Sub
  222. Private Sub Form_Resize()
  223.   On Error Resume Next
  224.   If mbResizing = True Then Exit Sub
  225.   Dim nHeight As Integer
  226.   Dim i As Integer
  227.   Dim nTotalWidth As Integer
  228.   mbResizing = True
  229.   If Me.WindowState <> 1 And lblPropName(0).Visible = True Then 'not minimized
  230.     'make sure the form is lined up on a Prop
  231.     nHeight = Me.Height
  232.     If (nHeight - 1400) Mod gnCTLARRAYHEIGHT <> 0 Then
  233.       Me.Height = ((nHeight - 1400) \ gnCTLARRAYHEIGHT) * gnCTLARRAYHEIGHT + 1400
  234.     End If
  235.     'resize the scrollbar
  236.     vsbScrollBar.Height = Me.Height - 740
  237.     vsbScrollBar.Left = Me.Width - 360
  238.     If mPropObject.Properties.Count > 10 Then
  239.       picProps.Width = Me.Width - 260
  240.       nTotalWidth = vsbScrollBar.Left - 20
  241.     Else
  242.       picProps.Width = Me.Width - 20
  243.       nTotalWidth = Me.Width - 50
  244.     End If
  245.     picPropHeader.Width = Me.Width - 20
  246.     'widen the Props if possible
  247.     For i = 0 To mPropObject.Properties.Count - 1
  248.       lblPropName(i).Width = (0.3 * nTotalWidth) - 20
  249.       maPropArr(i).Left = lblPropName(i).Width + 40
  250.       If gPropObject.Properties(i).Type > 9 Then
  251.         maPropArr(i).Width = 0.7 * nTotalWidth - 270
  252.       End If
  253.     Next
  254.     lblPropValue.Left = maPropArr(0).Left
  255.   End If
  256.   mbResizing = False
  257. End Sub
  258. Private Function GetPropWidth(rnType As Integer)
  259.   'determines the form control width
  260.   'based on the Prop type
  261.   Select Case rnType
  262.     Case dbBoolean
  263.       GetPropWidth = 850
  264.     Case dbByte
  265.       GetPropWidth = 650
  266.     Case dbInteger
  267.       GetPropWidth = 900
  268.     Case dbLong
  269.       GetPropWidth = 1100
  270.     Case dbCurrency
  271.       GetPropWidth = 1800
  272.     Case dbSingle
  273.       GetPropWidth = 1800
  274.     Case dbDouble
  275.       GetPropWidth = 2200
  276.     Case dbDate
  277.       GetPropWidth = 2000
  278.     Case dbText
  279.       GetPropWidth = 3250
  280.     Case dbMemo
  281.       GetPropWidth = 3250
  282.     Case Else
  283.       GetPropWidth = 3250
  284.   End Select
  285. End Function
  286. Private Sub LoadProps()
  287.    Dim nPropType As Integer
  288.    Dim i As Integer
  289.    On Error GoTo LoadPropsErr
  290.    'load the controls on the form
  291.    mnNumProps = mPropObject.Properties.Count
  292.    ReDim maPropArr(mnNumProps) As Object
  293.    lblPropName(0).Visible = True
  294.    nPropType = mPropObject.Properties(0).Type
  295.    If nPropType = dbBoolean Then
  296.      Set maPropArr(0) = chkPropData(0)
  297.    Else
  298.      Set maPropArr(0) = txtPropData(0)
  299.    End If
  300.    maPropArr(0).Visible = True
  301.    maPropArr(0).Top = 0
  302.    maPropArr(0).Width = GetPropWidth(nPropType)
  303.    maPropArr(0).TabIndex = 0
  304.    On Error Resume Next
  305.    For i = 1 To mPropObject.Properties.Count - 1
  306.      picProps.Height = picProps.Height + gnCTLARRAYHEIGHT
  307.      Load lblPropName(i)
  308.      lblPropName(i).Top = lblPropName(i - 1).Top + gnCTLARRAYHEIGHT
  309.      lblPropName(i).Visible = True
  310.      nPropType = mPropObject.Properties(i).Type
  311.      If nPropType = dbBoolean Then
  312.        Load chkPropData(i)
  313.        Set maPropArr(i) = chkPropData(i)
  314.      Else
  315.        Load txtPropData(i)
  316.        Set maPropArr(i) = txtPropData(i)
  317.      End If
  318.      maPropArr(i).Top = maPropArr(i - 1).Top + gnCTLARRAYHEIGHT
  319.      maPropArr(i).Visible = True
  320.      maPropArr(i).Width = GetPropWidth(nPropType)
  321.      maPropArr(i).TabIndex = i
  322.    Next
  323.    On Error GoTo LoadPropsErr
  324.    'resize main window
  325.    picProps.Top = picPropHeader.Top + picPropHeader.Height
  326.    mnPropTop = picProps.Top
  327.    vsbScrollBar.Value = mnPropTop
  328.    If i <= 11 Then
  329.      Me.Height = i * gnCTLARRAYHEIGHT + 1000
  330.      vsbScrollBar.Visible = False
  331.    Else
  332.      Me.Height = 4500
  333.      Me.Width = Me.Width + 260
  334.      vsbScrollBar.Visible = True
  335.      vsbScrollBar.Min = mnPropTop
  336.      vsbScrollBar.Max = mnPropTop - (i * gnCTLARRAYHEIGHT) + 3000
  337.    End If
  338.    'display the Prop names
  339.    For i = 0 To mPropObject.Properties.Count - 1
  340.      lblPropName(i).Caption = mPropObject.Properties(i).Name & ":"
  341.    Next
  342.    LoadPropValues
  343.    Exit Sub
  344. LoadPropsErr:
  345.    MsgBox "Error:" & Err & " " & Error
  346.    Exit Sub
  347. End Sub
  348. Private Sub LoadPropValues()
  349.   On Error GoTo LPVErr
  350.   Dim i As Integer
  351.   Dim vntTmp As Variant
  352.   For i = 0 To mPropObject.Properties.Count - 1
  353.     vntTmp = mPropObject.Properties(i).Value
  354.     If mPropObject.Properties(i).Type = dbBoolean Then
  355.       If Left(vntTmp, 4) = "ERR:" Then
  356.         chkPropData(i).Value = 2
  357.       Else
  358.         chkPropData(i).Value = IIf(vntTmp = True, 1, 0)
  359.       End If
  360.     Else
  361.       txtPropData(i).Text = vntTmp
  362.       If Left(vntTmp, 4) = "ERR:" Then
  363.         txtPropData(i).Locked = True 'disable Errors
  364.         txtPropData(i).TabStop = False
  365.       End If
  366.     End If
  367.   Next
  368.   Exit Sub
  369. LPVErr:
  370.   vntTmp = "ERR:" & Err & " " & Error
  371.   Resume Next
  372. End Sub
  373.