Sub jian() Dim xx As Double Dim ji As Double Dim b1 As String Dim arr(8) As Variant For xx = 255 To 0 Step -1 ji = xx b1 = DECtoBINa(ji) For a = 1 To 8 arr(a - 1) = Mid(b1, a, 1) If arr(a - 1) = "" Then arr(a - 1) = 0 End If If arr(a - 1) = 1 Then yanselan (a) ElseIf arr(a - 1) = 0 Then yansehong (a) End If wait (50) Next wait (50) Next End Sub
Public Function DECtoBIN(Dec As Double) As String DECtoBIN = "" Do While Dec > 0 '这个循环就是辗转相除法的循环 DECtoBIN = Dec Mod 2 & DECtoBIN 'DECtoBIN 是每次产生的余数连成的字符串 Dec = Dec \ 2 'dec为下次要进行除法的被除数。 Loop End Function Public Function DECtoBINa(Dec As Double) As String DECtoBINa = "" Do While Dec > 0 '这个循环就是辗转相除法的循环 DECtoBINa = Dec Mod 2 & DECtoBINa 'DECtoBIN 是每次产生的余数连成的字符串 Dec = Dec \ 2 'dec为下次要进行除法的被除数。 Loop cd = Len(DECtoBINa) If cd < 8 Then DECtoBINa = String(8 - cd, "0") & DECtoBINa End If End Function
Sub ydwbb(aa, xx, yy) ab = "TextBox " & aa With ActiveSheet.Shapes(ab) .Select .Left = xx .Top = yy End With End Sub Sub yanselan(aa) ab = "TextBox " & aa Set p3 = ActiveSheet.Shapes(ab) p3.Fill.ForeColor.RGB = RGB(0, 112, 192) p3.TextFrame2.TextRange.Text = "1" End Sub Sub yansehong(aa) ab = "TextBox " & aa Set p3 = ActiveSheet.Shapes(ab) p3.Fill.ForeColor.RGB = RGB(255, 0, 0) p3.TextFrame2.TextRange.Text = "0" End Sub