home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Yet_anothe2099551282008.psc / Counter.ctl < prev    next >
Text File  |  2008-01-28  |  14KB  |  466 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. End
  61. Attribute VB_Name = "Counter"
  62. Attribute VB_GlobalNameSpace = False
  63. Attribute VB_Creatable = True
  64. Attribute VB_PredeclaredId = False
  65. Attribute VB_Exposed = False
  66. Attribute VB_Ext_KEY = "PropPageWizardRun" ,"Yes"
  67. Option Explicit
  68. DefLng A-Z
  69. 'Property Variables
  70. Private myValue          As Currency
  71. Private myDigits         As Long
  72. Private myExtraX         As Long
  73. Private myExtraY         As Long
  74. Private myPosnX          As Long
  75. Private myPosnY          As Long
  76. 'Working Variables
  77. Private IntValue         As Currency
  78. Private PreviousValue    As Currency
  79. Private ThisValue        As Currency
  80. Private Overflow         As Currency 'value where overflow occurs
  81. Private Delta            As Currency
  82. Private MinDelta         As Currency
  83. Private Digit            As Long
  84. Private LenPres          As Long
  85. Private Roll             As Currency
  86. Private BoxWidth         As Long
  87. Private BoxHeight        As Long
  88. Private CharWidth        As Long
  89. Private Recur            As Long 'Control_Resize Recursion Depth
  90. Private i
  91. 'Events
  92. Public Event ReachedZero()
  93. Public Event Reached100()
  94. Public Event MouseMove()
  95. 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)
  96.  
  97. Public Property Let BackColor(ByVal nwBackColor As OLE_COLOR)
  98. Attribute BackColor.VB_Description = "Sets / Returns the Control's BackColor."
  99. Attribute BackColor.VB_HelpID = 10000
  100. Attribute BackColor.VB_UserMemId = -501
  101.  
  102.     pcSource.BackColor = nwBackColor
  103.     For i = 0 To myDigits - 1
  104.         pcDigit(i).BackColor = nwBackColor
  105.     Next i
  106.     Set Font = pcSource.Font 'repaint pcSource
  107.     PropertyChanged "BackColor"
  108.  
  109. End Property
  110.  
  111. Public Property Get BackColor() As OLE_COLOR
  112.  
  113.     BackColor = pcSource.BackColor
  114.  
  115. End Property
  116.  
  117. Public Property Get CharacterExtraX() As Long
  118. Attribute CharacterExtraX.VB_Description = "Sets / Returns extra horizontal spacing for each digit."
  119. Attribute CharacterExtraX.VB_HelpID = 10001
  120.  
  121.     CharacterExtraX = myExtraX
  122.  
  123. End Property
  124.  
  125. Public Property Let CharacterExtraX(ByVal nwExtra As Long)
  126.  
  127.     If nwExtra < (2 - BoxWidth) Or nwExtra > 30 Then
  128.         Err.Raise 380
  129.       Else 'NOT NWEXTRA...
  130.         myExtraX = nwExtra
  131.         Set Font = pcSource.Font
  132.         PropertyChanged "CaracterExtraX"
  133.     End If
  134.  
  135. End Property
  136.  
  137. Public Property Get CharacterExtraY() As Long
  138. Attribute CharacterExtraY.VB_Description = "Sets / Returns extra vertical spacing for each digit."
  139. Attribute CharacterExtraY.VB_HelpID = 10002
  140.  
  141.     CharacterExtraY = myExtraY
  142.  
  143. End Property
  144.  
  145. Public Property Let CharacterExtraY(ByVal nwExtra As Long)
  146.  
  147.     If nwExtra < (2 - BoxHeight) Or nwExtra > 30 Then
  148.         Err.Raise 380
  149.       Else 'NOT NWEXTRA...
  150.         myExtraY = nwExtra
  151.         Set Font = pcSource.Font
  152.         PropertyChanged "CaracterExtraY"
  153.     End If
  154.  
  155. End Property
  156.  
  157. Public Property Get ControlName() As String
  158. Attribute ControlName.VB_Description = "Returns the real name of the Control."
  159. Attribute ControlName.VB_HelpID = 10003
  160.  
  161.   Dim CntrlName As String
  162.  
  163.     CntrlName = Parent.ActiveControl.Name
  164.     i = Parent.ActiveControl.Index
  165.     If i >= 0 Then
  166.         CntrlName = CntrlName & "(" & Format$(i) & ")"
  167.     End If
  168.     ControlName = CntrlName
  169.  
  170. End Property
  171.  
  172. Public Property Get Digits() As Long
  173. Attribute Digits.VB_Description = "Sets / Returns the Control's number of digits."
  174. Attribute Digits.VB_HelpID = 10004
  175. Attribute Digits.VB_MemberFlags = "200"
  176.  
  177.     Digits = myDigits
  178.  
  179. End Property
  180.  
  181. Public Property Let Digits(ByVal nwDigits As Long)
  182.  
  183.     If nwDigits = 0 Or nwDigits > 9 Then
  184.         Err.Raise 380
  185.       Else 'NOT NWDIGITS...
  186.         Select Case nwDigits
  187.           Case Is > myDigits
  188.             For i = myDigits To nwDigits - 1
  189.                 Load pcDigit(i)
  190.                 With pcDigit(i)
  191.                     .Top = pcDigit(i - 1).Top
  192.                     .Left = pcDigit(i - 1).Left + BoxWidth - 1
  193.                     .Visible = True
  194.                 End With 'PCDIGIT(I)
  195.             Next i
  196.           Case Is < myDigits
  197.             For i = myDigits To nwDigits + 1 Step -1
  198.                 Unload pcDigit(i - 1)
  199.             Next i
  200.         End Select
  201.         myDigits = nwDigits
  202.         PropertyChanged "Digits"
  203.         UserControl_Resize
  204.     End If
  205.  
  206. End Property
  207.  
  208. Private Sub Display()
  209.  
  210.     Delta = Abs(myValue - PreviousValue)
  211.     If Delta >= MinDelta Then
  212.         ThisValue = myValue
  213.         If ThisValue < 0 Then
  214.             ThisValue = ThisValue + Overflow
  215.         End If
  216.         IntValue = Int(ThisValue)
  217.         Roll = ThisValue - IntValue
  218.         Digit = IntValue Mod 10
  219.         i = myDigits - 1
  220.         With pcDigit(i)
  221.             BitBlt .hDC, myExtraX \ 2 + myPosnX, myPosnY, CharWidth, BoxHeight, pcSource.hDC, 0, (Digit + Roll) * BoxHeight, vbSrcCopy
  222.             .Refresh
  223.         End With 'PCDIGIT(I)
  224.         For i = myDigits - 2 To 0 Step -1
  225.             If Digit <> 9 Then
  226.                 Roll = 0
  227.             End If
  228.             IntValue = IntValue \ 10
  229.             Digit = IntValue Mod 10
  230.             With pcDigit(i)
  231.                 BitBlt .hDC, myExtraX \ 2 + myPosnX, myPosnY, CharWidth, BoxHeight, pcSource.hDC, 0, (Digit + Roll) * BoxHeight, vbSrcCopy
  232.                 .Refresh
  233.             End With 'PCDIGIT(I)
  234.         Next i
  235.         Select Case True
  236.           Case (PreviousValue < 0 And myValue >= 0) Or (PreviousValue > 0 And myValue <= 0)
  237.             RaiseEvent ReachedZero
  238.           Case (PreviousValue < 100 And myValue >= 100) Or (PreviousValue > 100 And myValue <= 100)
  239.             RaiseEvent Reached100
  240.         End Select
  241.         pcDigit(0).PSet (1, 1), IIf(myValue < 0, pcSource.ForeColor, pcSource.BackColor)
  242.         PreviousValue = myValue
  243.     End If
  244.  
  245. End Sub
  246.  
  247. Public Property Get Font() As Font
  248. Attribute Font.VB_Description = "Sets / Returns the font for the Control."
  249. Attribute Font.VB_HelpID = 10005
  250. Attribute Font.VB_UserMemId = -512
  251.  
  252.     Set Font = pcSource.Font
  253.  
  254. End Property
  255.  
  256. Public Property Set Font(ByVal nwFont As Font)
  257.  
  258.   Dim Dgt As String * 1
  259.  
  260.     With pcSource
  261.         Set .Font = nwFont
  262.         BoxWidth = 0
  263.         For i = 0 To 9 'find widest Char
  264.             CharWidth = .TextWidth(Format$(i))
  265.             If CharWidth > BoxWidth Then
  266.                 BoxWidth = CharWidth
  267.             End If
  268.         Next i
  269.         .Width = BoxWidth
  270.         BoxWidth = BoxWidth + myExtraX + 3 '1 pixel each side plus 1 border
  271.         BoxHeight = .TextHeight("0") + myExtraY
  272.         .Height = BoxHeight * 11 '0 1 2 3 4 5 6 7 8 9 0
  273.         .Cls
  274.         .CurrentY = (myExtraY / 2) - 1 'start for vertical
  275.         For i = 0 To 10
  276.             Dgt = Right$(Format$(i), 1)
  277.             .CurrentX = (CharWidth - .TextWidth(Dgt)) / 2 'to place Char in the middle
  278.             pcSource.Print Dgt '.Print is not exposed by 'With pcSource' (funny, ain't it)
  279.             .CurrentY = .CurrentY + myExtraY 'vertical spacing
  280.         Next i
  281.     End With 'PCSOURCE
  282.     For i = 0 To myDigits - 1 'prepare pcDigit's
  283.         With pcDigit(i)
  284.             .Width = BoxWidth
  285.             .Height = BoxHeight
  286.             .Cls
  287.             If i = 0 Then
  288.                 .Left = 0
  289.               Else 'NOT I...
  290.                 .Left = (pcDigit(i - 1).Left + BoxWidth - 1)
  291.             End If
  292.         End With 'PCDIGIT(I)
  293.     Next i
  294.     MinDelta = 0.5 / BoxHeight 'skips Display if Delta is less
  295.     PropertyChanged "Font"
  296.     Digits = myDigits 'repaint Control
  297.  
  298. End Property
  299.  
  300. Public Property Get ForeColor() As OLE_COLOR
  301. Attribute ForeColor.VB_Description = "Sets / Returns the Control's ForeColor."
  302. Attribute ForeColor.VB_HelpID = 10006
  303. Attribute ForeColor.VB_UserMemId = -513
  304.  
  305.     ForeColor = pcSource.ForeColor
  306.  
  307. End Property
  308.  
  309. Public Property Let ForeColor(ByVal nwForeColor As OLE_COLOR)
  310.  
  311.     pcSource.ForeColor = nwForeColor
  312.     Set Font = pcSource.Font 'repaint pcSource
  313.     PropertyChanged "ForeColor"
  314.  
  315. End Property
  316.  
  317. Private Sub pcDigit_MouseMove(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
  318.  
  319.     RaiseEvent MouseMove
  320.  
  321. End Sub
  322.  
  323. Public Property Let PosnX(ByVal nwPosn As Long)
  324. Attribute PosnX.VB_Description = "Sets / Returns the horizontal placement of each digit in its box."
  325. Attribute PosnX.VB_HelpID = 10007
  326.  
  327.     If nwPosn < -16 Or nwPosn > 16 Then
  328.         Err.Raise 380
  329.       Else 'NOT NWPOSN...
  330.         myPosnX = nwPosn
  331.         Set Font = pcSource.Font
  332.         PropertyChanged "PosnX"
  333.     End If
  334.  
  335. End Property
  336.  
  337. Public Property Get PosnX() As Long
  338.  
  339.     PosnX = myPosnX
  340.  
  341. End Property
  342.  
  343. Public Property Let PosnY(ByVal nwPosn As Long)
  344. Attribute PosnY.VB_Description = "Sets / Returns the vertical placement of each digit in its box."
  345. Attribute PosnY.VB_HelpID = 10008
  346.  
  347.     If nwPosn < -20 Or nwPosn > 20 Then
  348.         Err.Raise 380
  349.       Else 'NOT NWPOSN...
  350.         myPosnY = nwPosn
  351.         Set Font = pcSource.Font
  352.         PropertyChanged "PosnY"
  353.     End If
  354.  
  355. End Property
  356.  
  357. Public Property Get PosnY() As Long
  358.  
  359.     PosnY = myPosnY
  360.  
  361. End Property
  362.  
  363. Public Sub Refresh()
  364. Attribute Refresh.VB_Description = "Displays the accurate value."
  365. Attribute Refresh.VB_HelpID = 10011
  366.  
  367.     PreviousValue = Overflow
  368.     Display
  369.  
  370. End Sub
  371.  
  372. Private Sub UserControl_Initialize()
  373.  
  374.     myDigits = 1
  375.     BoxWidth = 1
  376.  
  377. End Sub
  378.  
  379. Private Sub UserControl_InitProperties()
  380.  
  381.     myExtraX = 6
  382.     myExtraY = 6
  383.     myValue = 0
  384.     Set Font = Ambient.Font
  385.     Digits = 3
  386.  
  387. End Sub
  388.  
  389. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  390.  
  391.     With PropBag
  392.         pcSource.BackColor = .ReadProperty("BackColor", &HFFFFFF)
  393.         pcDigit(0).BackColor = pcSource.BackColor
  394.         pcSource.ForeColor = .ReadProperty("ForeColor", &H0&)
  395.         myExtraX = .ReadProperty("CharacterExtraX", 6)
  396.         myPosnX = .ReadProperty("PosnX", 0)
  397.         myExtraY = .ReadProperty("CharacterExtraY", 6)
  398.         myPosnY = .ReadProperty("PosnY", 0)
  399.         myValue = .ReadProperty("Value", 0)
  400.         Set Font = .ReadProperty("Font", Ambient.Font)
  401.         Digits = .ReadProperty("Digits", 3)
  402.     End With 'PROPBAG
  403.  
  404. End Sub
  405.  
  406. Private Sub UserControl_Resize()
  407.  
  408.     Recur = Recur + 1
  409.     Size (BoxWidth - 1) * myDigits * 15 + 15, BoxHeight * 15
  410.     Recur = Recur - 1
  411.     If Recur = 0 Then
  412.         Overflow = 10 ^ myDigits
  413.         PreviousValue = -Overflow 'force repaint
  414.         Display 'repaint Display Value
  415.     End If
  416.  
  417. End Sub
  418.  
  419. Private Sub UserControl_Terminate()
  420.  
  421.     For i = myDigits - 1 To 1 Step -1
  422.         Unload pcDigit(i)
  423.     Next i
  424.  
  425. End Sub
  426.  
  427. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  428.  
  429.     With PropBag
  430.         .WriteProperty "BackColor", pcSource.BackColor, &HFFFFFF
  431.         .WriteProperty "ForeColor", pcSource.ForeColor, &H0&
  432.         .WriteProperty "CharacterExtraX", myExtraX, 6
  433.         .WriteProperty "PosnX", myPosnX, 0
  434.         .WriteProperty "CharacterExtraY", myExtraY, 6
  435.         .WriteProperty "PosnY", myPosnY, 0
  436.         .WriteProperty "Value", myValue, 0
  437.         .WriteProperty "Font", pcSource.Font, Ambient.Font
  438.         .WriteProperty "Digits", myDigits, 3
  439.     End With 'PROPBAG
  440.  
  441. End Sub
  442.  
  443. Public Property Get Value() As Currency
  444. Attribute Value.VB_Description = "Sets / Returns the displayed value."
  445. Attribute Value.VB_HelpID = 10012
  446. Attribute Value.VB_UserMemId = 0
  447.  
  448.     Value = myValue
  449.  
  450. End Property
  451.  
  452. Public Property Let Value(ByVal nwValue As Currency)
  453.  
  454.     If nwValue > 2147483647 Or myValue < -2147483647 Then
  455.         Err.Raise 380
  456.       Else 'NOT NWVALUE...
  457.         myValue = nwValue
  458.         PropertyChanged "Value"
  459.         Display 'repaint Display Value
  460.     End If
  461.  
  462. End Property
  463.  
  464. ':) Ulli's VB Code Formatter V2.23.17 (2008-Jan-28 11:28)  Decl: 29  Code: 343  Total: 372 Lines
  465. ':) CommentOnly: 5 (1,3%)  Commented: 31 (8,3%)  Empty: 87 (23,4%)  Max Logic Depth: 5
  466.