|
-
Jul 25th, 2001, 10:01 PM
#1
Thread Starter
New Member
Pls Help The Poor Me!!!!!!!!!!!!!!
Below is a following code for my previous question. on how to count like from 0000 when we add it will be to 0001 then 0010 then 0011 so on and so forth i would like to know if i had four led
naming it Led1, Led2, Led3, Led4.. and when i add this time round from 0000 all would be turned off. then when i add Led1, Led2, Led3 will be off but Led4 will be turned on. can someone teach me how to add on to my code below thanks for those who helped me previously. and the code below has a bug when i subtract till all values is 0000 and i sybtract again it will turn to 0001 then i press subtract again it will turn into 0000 it keeps on changing from 0000 to 0001 and then 0000 again ...... but the main aim is about the led anyone can help.
Option Explicit
Dim iValue As Integer
Private Sub CmdAdd_Click()
If iValue = 15 Then iValue = 0 Else iValue = iValue + 1
Text1.Text = Format(dec2bin(iValue), "0000")
End Sub
Private Sub CmdQuit_Click()
End
End Sub
Private Sub CmdSub_Click()
If iValue = 15 Then iValue = 0 Else iValue = iValue - 1
Text1.Text = Format(dec2bin(iValue), "0000")
End Sub
Private Sub Form_Load()
Text1.Text = "0000"
End Sub
Public Function dec2bin(mynum As Variant) As String
Dim loopcounter As Integer
If mynum >= 2 ^ 31 Then
dec2bin = "Too big"
Exit Function
End If
Do
If (mynum And 2 ^ loopcounter) = 2 ^ loopcounter Then
dec2bin = "1" & dec2bin
Else
dec2bin = "0" & dec2bin
End If
loopcounter = loopcounter + 1
Loop Until 2 ^ loopcounter > mynum
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|