' Bit-String Calculator Demo Program
' Mr. Minich
' Purpose - to illustrate the code for a couple of bit-string flicking operations.
'               Only the AND and RSHIFT operations work in this program. Notice that
'               a combo box named cboOperation is used in this program. Always use the
'               prefix 'cbo' when naming combo boxes. To enter the user's options for
'               a combo box, type them into its List property.

Option Explicit Private Sub cmdCalculate_Click() Dim J As Integer ' loop variable Dim ZeroString As String ' a string of zeros to be used when shifting a bit string If cboOperation = "AND" Then For J = 1 To Len(txtBitString1) lblAnswer = lblAnswer & (Val(Mid$(txtBitString1, J, 1)) And _ Val(Mid$(txtBitString2, J, 1))) Next J End If ' the And operator performs the same bit-wise logical ' operation as AND in bit-string flicking. ' Visual Basic also uses the bit-wise operators, NOT, OR, ' and XOR. You can easily combine NOT and XOR to ' perform the XNOR operation since XNOR is not defined ' as an operator in Visual Basic. Or, you can use VB's Eqv
' operator which is equivalent to the XNOR operation but refer ' to this demo program for help.
' ****************** ' Add If/Then statements for the other required logical operators here. ' ****************** If cboOperation = "RSHIFT" Then For J = 1 To Val(txtAmount) ' building a string of zeros of the ZeroString = ZeroString & "0" ' necessary length for later concatenation Next J lblAnswer = ZeroString & Left$(txtBitString1, Len(txtBitString1) - Val(txtAmount)) End If ' ****************** ' Add If/Then statements for the other required shift and circulate operators here. ' ****************** End Sub Private Sub cmdClear_Click() lblAnswer = "" ' clearing the text boxes and labels txtBitString1 = "" txtBitString2 = "" txtAmount = 0 End Sub Private Sub CmdExit_Click() End ' exiting the program End Sub