VB Code:
Option Explicit
Dim tmrVal As Long
Private Sub MDIForm_Load()
ResetSubWindows Me
SetPBarPos Me
End Sub
Private Sub pbxLedDisplay_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim s As Shape
Dim i As Integer
Set s = ShapeHitTest(X, Y)
If Not s Is Nothing Then
If shpLED(s.Index).BackColor = &H80& Then
shpLED(s.Index).BackColor = &HFF&
lblBinCode = Mid(lblBinCode, 1, (s.Index * 2) - 1) & Replace(lblBinCode, "0", "1", s.Index * 2, 1)
ElseIf shpLED(s.Index).BackColor = &HFF& Then
shpLED(s.Index).BackColor = &H80&
lblBinCode = Mid(lblBinCode, 1, (s.Index * 2) - 1) & Replace(lblBinCode, "1", "0", s.Index * 2, 1)
End If
End If
Dim store As String
For i = 1 To 8
store = store & Mid(lblBinCode, i * 2, 1)
Next
lblBinCode = Mid(lblBinCode, 1, 19) & BinToDec(store)
End Sub
Private Function ShapeHitTest(ByVal X As Single, ByVal Y As Single) As Shape
Dim c As Control
For Each c In Controls
If TypeOf c Is Shape Then
If ((X >= c.Left) And (X <= c.Left + c.Width)) And ((Y >= c.Top) And (Y <= c.Top + c.Height)) Then
Set ShapeHitTest = c
Exit Function
End If
End If
Next
End Function
Private Sub tmrCount_Timer()
Dim l As Integer
For l = -7 To 0
If Mid$(BinToDec(tmrVal), l + 8, 1) = "1" Then 'When I remove the BinToDec() from here...
If shpLED(l + 8).BackColor = &H80& Then
pbxLedDisplay_MouseUp 1, 0, 200 + ((l + 7) * 360), 225
End If
ElseIf Mid$(BinToDec(tmrVal), l + 8, 1) = "0" Then 'and from here, the counter works fine
If shpLED(l + 8).BackColor = &HFF& Then
pbxLedDisplay_MouseUp 1, 0, 200 + ((l + 7) * 360), 225
End If
End If
Next
If tmrVal = 255 Then
tmrVal = tmrVal - 255
Else
tmrVal = tmrVal + 1
End If
MsgBox tmrVal 'This always says 1
End Sub
VB Code:
Public Function BaseTwoCheck(DecimalCode As Long) As Long
i = 0
num = 0
Do Until DecimalCode <= num
num = num + 2 ^ i
i = i + 1
Loop
BaseTwoCheck = i - 1
End Function
Public Function DecToBin(DecimalCode As Long) As String
If DecimalCode = 0 Then
DecToBin = "00000000"
Exit Function
End If
For X = BaseTwoCheck(DecimalCode) To 0 Step -1
Y = 2 ^ X
If DecimalCode > (Y - 1) Then
DecToBin = DecToBin & "1"
DecimalCode = DecimalCode - Y
Else
DecToBin = DecToBin & "0"
End If
Next
DecToBin = Format$(DecToBin, "00000000")
End Function