home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Mileage_Co710014112002.psc / Counter.ctl (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2002-04-11  |  14.2 KB  |  384 lines

  1. VERSION 5.00
  2. Begin VB.UserControl Counter 
  3.    Appearance      =   0  '2D
  4.    BackColor       =   &H80000005&
  5.    ClientHeight    =   2040
  6.    ClientLeft      =   0
  7.    ClientTop       =   0
  8.    ClientWidth     =   2325
  9.    ForwardFocus    =   -1  'True
  10.    PropertyPages   =   "Counter.ctx":0000
  11.    ScaleHeight     =   136
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   155
  14.    ToolboxBitmap   =   "Counter.ctx":0032
  15.    Begin VB.PictureBox pcSource 
  16.       Appearance      =   0  '2D
  17.       AutoRedraw      =   -1  'True
  18.       BackColor       =   &H00FFFFFF&
  19.       BorderStyle     =   0  'Kein
  20.       ForeColor       =   &H00000000&
  21.       Height          =   1935
  22.       Left            =   420
  23.       ScaleHeight     =   129
  24.       ScaleMode       =   3  'Pixel
  25.       ScaleWidth      =   27
  26.       TabIndex        =   1
  27.       Top             =   0
  28.       Visible         =   0   'False
  29.       Width           =   405
  30.    End
  31.    Begin VB.PictureBox pcDigit 
  32.       Appearance      =   0  '2D
  33.       AutoRedraw      =   -1  'True
  34.       BackColor       =   &H00FFFFFF&
  35.       CausesValidation=   0   'False
  36.       DrawWidth       =   2
  37.       BeginProperty Font 
  38.          Name            =   "MS Sans Serif"
  39.          Size            =   9.75
  40.          Charset         =   0
  41.          Weight          =   700
  42.          Underline       =   0   'False
  43.          Italic          =   0   'False
  44.          Strikethrough   =   0   'False
  45.       EndProperty
  46.       FontTransparent =   0   'False
  47.       ForeColor       =   &H00000000&
  48.       Height          =   330
  49.       Index           =   0
  50.       Left            =   0
  51.       ScaleHeight     =   20
  52.       ScaleMode       =   3  'Pixel
  53.       ScaleWidth      =   9
  54.       TabIndex        =   0
  55.       TabStop         =   0   'False
  56.       ToolTipText     =   "Rolling Counter"
  57.       Top             =   0
  58.       Width           =   165
  59.    End
  60. Attribute VB_Name = "Counter"
  61. Attribute VB_GlobalNameSpace = False
  62. Attribute VB_Creatable = True
  63. Attribute VB_PredeclaredId = False
  64. Attribute VB_Exposed = True
  65. Attribute VB_Ext_KEY = "PropPageWizardRun" ,"Yes"
  66. Option Explicit
  67. DefLng A-Z
  68. 'Property Variables
  69. Private myValue          As Currency
  70. Private myDigits         As Long
  71. Private myExtraX         As Long
  72. Private myExtraY         As Long
  73. Private myPosnX          As Long
  74. Private myPosnY          As Long
  75. 'Working Variables
  76. Private IntValue         As Currency
  77. Private PreviousValue    As Currency
  78. Private ThisValue        As Currency
  79. Private Overflow         As Currency 'value where overflow occurs
  80. Private Delta            As Currency
  81. Private MinDelta         As Currency
  82. Private Digit            As Long
  83. Private LenPres          As Long
  84. Private Roll             As Currency
  85. Private BoxWidth         As Long
  86. Private BoxHeight        As Long
  87. Private CharWidth        As Long
  88. Private Recur            As Long  'Control_Resize Recursion Depth
  89. Private i
  90. 'Events
  91. Public Event ReachedZero()
  92. Public Event Reached100()
  93. Private Declare Sub BitBlt Lib "gdi32" (ByVal DstDC As Long, ByVal DstX As Long, ByVal DstY As Long, ByVal DstW As Long, ByVal DstH As Long, ByVal SrcDC As Long, ByVal SrcX As Long, ByVal SrcY As Long, ByVal OpCode As Long)
  94. Private Const CopySrc As Long = &HCC0020  'OpCode for BitBlt
  95. Public Property Get BackColor() As OLE_COLOR
  96. Attribute BackColor.VB_Description = "Sets / Returns the Control's BackColor."
  97. Attribute BackColor.VB_HelpID = 10000
  98. Attribute BackColor.VB_ProcData.VB_Invoke_Property = ";Darstellung"
  99. Attribute BackColor.VB_UserMemId = -501
  100.     BackColor = pcSource.BackColor
  101. End Property
  102. Public Property Let BackColor(ByVal nwBackColor As OLE_COLOR)
  103.     pcSource.BackColor = nwBackColor
  104.     For i = 0 To myDigits - 1
  105.         pcDigit(i).BackColor = nwBackColor
  106.     Next i
  107.     Set Font = pcSource.Font                'repaint pcSource
  108.     PropertyChanged "BackColor"
  109. End Property
  110. Public Property Get ForeColor() As OLE_COLOR
  111. Attribute ForeColor.VB_Description = "Sets / Returns the Control's ForeColor."
  112. Attribute ForeColor.VB_HelpID = 10006
  113. Attribute ForeColor.VB_ProcData.VB_Invoke_Property = ";Darstellung"
  114. Attribute ForeColor.VB_UserMemId = -513
  115.     ForeColor = pcSource.ForeColor
  116. End Property
  117. Public Property Let ForeColor(ByVal nwForeColor As OLE_COLOR)
  118.     pcSource.ForeColor = nwForeColor
  119.     Set Font = pcSource.Font                'repaint pcSource
  120.     PropertyChanged "ForeColor"
  121. End Property
  122. Public Property Get CharacterExtraX() As Long
  123. Attribute CharacterExtraX.VB_Description = "Sets / Returns extra horizontal spacing for each digit."
  124. Attribute CharacterExtraX.VB_HelpID = 10001
  125. Attribute CharacterExtraX.VB_ProcData.VB_Invoke_Property = ";Darstellung"
  126.     CharacterExtraX = myExtraX
  127. End Property
  128. Public Property Let PosnX(ByVal nwPosn As Long)
  129. Attribute PosnX.VB_Description = "Sets / Returns the horizontal placement of each digit in its box."
  130. Attribute PosnX.VB_HelpID = 10007
  131. Attribute PosnX.VB_ProcData.VB_Invoke_PropertyPut = ";Darstellung"
  132.     If nwPosn < -16 Or nwPosn > 16 Then
  133.         Err.Raise 380
  134.       Else 'NOT NWPOSN...
  135.         myPosnX = nwPosn
  136.         Set Font = pcSource.Font
  137.         PropertyChanged "PosnX"
  138.     End If
  139. End Property
  140. Public Property Get PosnX() As Long
  141.     PosnX = myPosnX
  142. End Property
  143. Public Property Let PosnY(ByVal nwPosn As Long)
  144. Attribute PosnY.VB_Description = "Sets / Returns the vertical placement of each digit in its box."
  145. Attribute PosnY.VB_HelpID = 10008
  146. Attribute PosnY.VB_ProcData.VB_Invoke_PropertyPut = ";Darstellung"
  147.     If nwPosn < -20 Or nwPosn > 20 Then
  148.         Err.Raise 380
  149.       Else 'NOT NWPOSN...
  150.         myPosnY = nwPosn
  151.         Set Font = pcSource.Font
  152.         PropertyChanged "PosnY"
  153.     End If
  154. End Property
  155. Public Property Get PosnY() As Long
  156.     PosnY = myPosnY
  157. End Property
  158. Public Property Let CharacterExtraX(ByVal nwExtra As Long)
  159.     If nwExtra < (2 - BoxWidth) Or nwExtra > 30 Then
  160.         Err.Raise 380
  161.       Else 'NOT NWEXTRA...
  162.         myExtraX = nwExtra
  163.         Set Font = pcSource.Font
  164.         PropertyChanged "CaracterExtraX"
  165.     End If
  166. End Property
  167. Public Property Get CharacterExtraY() As Long
  168. Attribute CharacterExtraY.VB_Description = "Sets / Returns extra vertical spacing for each digit."
  169. Attribute CharacterExtraY.VB_HelpID = 10002
  170. Attribute CharacterExtraY.VB_ProcData.VB_Invoke_Property = ";Darstellung"
  171.     CharacterExtraY = myExtraY
  172. End Property
  173. Public Property Let CharacterExtraY(ByVal nwExtra As Long)
  174.     If nwExtra < (2 - BoxHeight) Or nwExtra > 30 Then
  175.         Err.Raise 380
  176.       Else 'NOT NWEXTRA...
  177.         myExtraY = nwExtra
  178.         Set Font = pcSource.Font
  179.         PropertyChanged "CaracterExtraY"
  180.     End If
  181. End Property
  182. Public Property Get ControlName() As String
  183. Attribute ControlName.VB_Description = "Returns the real name of the Control."
  184. Attribute ControlName.VB_HelpID = 10003
  185.   Dim CntrlName As String
  186.     CntrlName = Parent.ActiveControl.Name
  187.     i = Parent.ActiveControl.Index
  188.     If i >= 0 Then
  189.         CntrlName = CntrlName & "(" & Format$(i) & ")"
  190.     End If
  191.     ControlName = CntrlName
  192. End Property
  193. Public Property Get Font() As Font
  194. Attribute Font.VB_Description = "Sets / Returns the font for the Control."
  195. Attribute Font.VB_HelpID = 10005
  196. Attribute Font.VB_ProcData.VB_Invoke_Property = ";Darstellung"
  197. Attribute Font.VB_UserMemId = -512
  198.     Set Font = pcSource.Font
  199. End Property
  200. Public Property Set Font(ByVal nwFont As Font)
  201.   Dim Dgt As String * 1
  202.     With pcSource
  203.         Set .Font = nwFont
  204.         BoxWidth = 0
  205.         For i = 0 To 9
  206.             '         find widest Char
  207.             CharWidth = .TextWidth(Format$(i))
  208.             If CharWidth > BoxWidth Then
  209.                 BoxWidth = CharWidth
  210.             End If
  211.         Next i
  212.         .Width = BoxWidth
  213.         BoxWidth = BoxWidth + myExtraX + 3    '1 pixel each side plus 1 border
  214.         BoxHeight = .TextHeight("0") + myExtraY
  215.         .Height = BoxHeight * 11              '0 1 2 3 4 5 6 7 8 9 0
  216.         .Cls
  217.         .CurrentY = (myExtraY / 2) - 1        'start for vertical
  218.         For i = 0 To 10
  219.             Dgt = Right$(Format$(i), 1)
  220.             .CurrentX = (CharWidth - .TextWidth(Dgt)) / 2 'to place Char in the middle
  221.             pcSource.Print Dgt                '.Print is not exposed by 'With pcSource' (funny, ain't it)
  222.             .CurrentY = .CurrentY + myExtraY  'vertical spacing
  223.         Next i
  224.     End With 'PCSOURCE
  225.     For i = 0 To myDigits - 1                 'prepare pcDigit's
  226.         With pcDigit(i)
  227.             .Width = BoxWidth
  228.             .Height = BoxHeight
  229.             .Cls
  230.             If i = 0 Then
  231.                 .Left = 0
  232.               Else 'NOT I...
  233.                 .Left = (pcDigit(i - 1).Left + BoxWidth - 1)
  234.             End If
  235.         End With 'PCDIGIT(I)
  236.     Next i
  237.     MinDelta = 1 / BoxHeight                'skip Display if Delta is less
  238.     PropertyChanged "Font"
  239.     Digits = myDigits                       'repaint Control
  240. End Property
  241. Public Property Get Digits() As Long
  242. Attribute Digits.VB_Description = "Sets / Returns the Control's number of digits."
  243. Attribute Digits.VB_HelpID = 10004
  244. Attribute Digits.VB_ProcData.VB_Invoke_Property = ";Darstellung"
  245. Attribute Digits.VB_MemberFlags = "200"
  246.     Digits = myDigits
  247. End Property
  248. Public Property Let Digits(ByVal nwDigits As Long)
  249.     If nwDigits = 0 Or nwDigits > 9 Then
  250.         Err.Raise 380
  251.       Else 'NOT NWDIGITS...
  252.         Select Case nwDigits
  253.           Case Is > myDigits
  254.             For i = myDigits To nwDigits - 1
  255.                 Load pcDigit(i)
  256.                 With pcDigit(i)
  257.                     .Top = pcDigit(i - 1).Top
  258.                     .Left = pcDigit(i - 1).Left + BoxWidth - 1
  259.                     .Visible = True
  260.                 End With 'PCDIGIT(I)
  261.             Next i
  262.           Case Is < myDigits
  263.             For i = myDigits To nwDigits + 1 Step -1
  264.                 Unload pcDigit(i - 1)
  265.             Next i
  266.         End Select
  267.         myDigits = nwDigits
  268.         PropertyChanged "Digits"
  269.         UserControl_Resize
  270.     End If
  271. End Property
  272. Public Property Get Value() As Currency
  273. Attribute Value.VB_Description = "Sets / Returns the displayed value."
  274. Attribute Value.VB_HelpID = 10012
  275. Attribute Value.VB_ProcData.VB_Invoke_Property = ";Daten"
  276. Attribute Value.VB_UserMemId = 0
  277.     Value = myValue
  278. End Property
  279. Public Property Let Value(ByVal nwValue As Currency)
  280.     If nwValue > 2147483647 Or myValue < -2147483647 Then
  281.         Err.Raise 380
  282.       Else 'NOT NWVALUE...
  283.         myValue = nwValue
  284.         PropertyChanged "Value"
  285.         Display                              'repaint Display Value
  286.     End If
  287. End Property
  288. Public Sub Refresh()
  289. Attribute Refresh.VB_Description = "Displays the accurate value."
  290. Attribute Refresh.VB_HelpID = 10011
  291.     PreviousValue = Overflow
  292.     Display
  293. End Sub
  294. Private Sub UserControl_Initialize()
  295.     myDigits = 1
  296.     BoxWidth = 1
  297. End Sub
  298. Private Sub UserControl_InitProperties()
  299.     myExtraX = 6
  300.     myExtraY = 6
  301.     myValue = 0
  302.     Set Font = Ambient.Font
  303.     Digits = 3
  304. End Sub
  305. Private Sub UserControl_Resize()
  306.     Recur = Recur + 1
  307.     Size (BoxWidth - 1) * myDigits * 15 + 15, BoxHeight * 15
  308.     Recur = Recur - 1
  309.     If Recur = 0 Then
  310.         Overflow = 10 ^ myDigits
  311.         PreviousValue = -Overflow            'force repaint
  312.         Display                              'repaint Display Value
  313.     End If
  314. End Sub
  315. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  316.     With PropBag
  317.         pcSource.BackColor = .ReadProperty("BackColor", &HFFFFFF)
  318.         pcDigit(0).BackColor = pcSource.BackColor
  319.         pcSource.ForeColor = .ReadProperty("ForeColor", &H0&)
  320.         myExtraX = .ReadProperty("CharacterExtraX", 6)
  321.         myPosnX = .ReadProperty("PosnX", 0)
  322.         myExtraY = .ReadProperty("CharacterExtraY", 6)
  323.         myPosnY = .ReadProperty("PosnY", 0)
  324.         myValue = .ReadProperty("Value", 0)
  325.         Set Font = .ReadProperty("Font", Ambient.Font)
  326.         Digits = .ReadProperty("Digits", 3)
  327.     End With 'PROPBAG
  328. End Sub
  329. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  330.     With PropBag
  331.         .WriteProperty "BackColor", pcSource.BackColor, &HFFFFFF
  332.         .WriteProperty "ForeColor", pcSource.ForeColor, &H0&
  333.         .WriteProperty "CharacterExtraX", myExtraX, 6
  334.         .WriteProperty "PosnX", myPosnX, 0
  335.         .WriteProperty "CharacterExtraY", myExtraY, 6
  336.         .WriteProperty "PosnY", myPosnY, 0
  337.         .WriteProperty "Value", myValue, 0
  338.         .WriteProperty "Font", pcSource.Font, Ambient.Font
  339.         .WriteProperty "Digits", myDigits, 3
  340.     End With 'PROPBAG
  341. End Sub
  342. Private Sub UserControl_Terminate()
  343.     For i = myDigits - 1 To 1 Step -1
  344.         Unload pcDigit(i)
  345.     Next i
  346. End Sub
  347. Private Sub Display()
  348.     Delta = Abs(myValue - PreviousValue)
  349.     If Delta >= MinDelta Then
  350.         ThisValue = myValue
  351.         If ThisValue < 0 Then
  352.             ThisValue = ThisValue + Overflow
  353.         End If
  354.         IntValue = Int(ThisValue)
  355.         Roll = ThisValue - IntValue
  356.         Digit = IntValue Mod 10
  357.         i = myDigits - 1
  358.         With pcDigit(i)
  359.             BitBlt .hDC, myExtraX \ 2 + myPosnX, myPosnY, CharWidth, BoxHeight, pcSource.hDC, 0, (Digit + Roll) * BoxHeight, CopySrc
  360.             .Refresh
  361.         End With 'PCDIGIT(I)
  362.         For i = myDigits - 2 To 0 Step -1
  363.             If Digit <> 9 Then
  364.                 Roll = 0
  365.             End If
  366.             IntValue = IntValue \ 10
  367.             Digit = IntValue Mod 10
  368.             With pcDigit(i)
  369.                 BitBlt .hDC, myExtraX \ 2 + myPosnX, myPosnY, CharWidth, BoxHeight, pcSource.hDC, 0, (Digit + Roll) * BoxHeight, CopySrc
  370.                 .Refresh
  371.             End With 'PCDIGIT(I)
  372.         Next i
  373.         Select Case True
  374.           Case (PreviousValue < 0 And myValue >= 0) Or (PreviousValue > 0 And myValue <= 0)
  375.             RaiseEvent ReachedZero
  376.           Case (PreviousValue < 100 And myValue >= 100) Or (PreviousValue > 100 And myValue <= 100)
  377.             RaiseEvent Reached100
  378.         End Select
  379.         pcDigit(0).PSet (1, 1), IIf(myValue < 0, pcSource.ForeColor, pcSource.BackColor)
  380.         PreviousValue = myValue
  381.     End If
  382. End Sub
  383. ':) Ulli's VB Code Formatter V2.11.3 (11.04.2002 14:11:47) 29 + 337 = 366 Lines
  384.