Basic Programming Name -
Bit-String Flicking Calculator Worksheet #1
Deskcheck the program below and answer the questions that appear on lined paper.
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
txtBitString1.Text = "10110"
txtBitString2.Text = "11011"
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
'Question #1 - How many loop iterations occur with the For loop above?
'Question #2 - What is the current value of the loop variable J
' (at this point in the program)?
'Question #3 - What is the value of Mid$(txtBitString1, 5, 1)?
'Question #4 - What is the value of Val(Mid$(txtBitString2, 1, 1)?
'Question #5 - What is the value of
' (Val(Mid$(txtBitString1, 2, 1)) And Val(Mid$(txtBitString2, 2, 1)))?
' Realize that the And operator in Visual Basic is the same as the And
' logical operation. (True or False)
'Question #6 - If lblAnswer = "101", then what is the value of
' lblAnswer & Str$(Val("1") And Val("0"))?
'Question #7 - Rewrite the If statement above to perform the logical OR operation
' instead of the AND operation. Be sure to use proper indentation
' and spacing.
txtAmount.Text = 2
txtBitString1.Text = "10110"
txtBitString2.Text = "11011"
If cboOperation = "RSHIFT" Then
For J = 1 To Val(txtAmount) ' building a string of zeros of the
ZeroString = ZeroString & "0" ' necessary length for concatenation
Next J
lblAnswer = ZeroString & Left$(txtBitString1, Len(txtBitString1) - _
Val(txtAmount))
End If
'Question #8 - What is the final value of ZeroString?
'Question #9 - What is the value of Left$(txtBitString1, 2)?
'Question #10 - What is the value of Len(txtBitString1) - Val(txtAmount) ?
'Question #11 - What is the value of ZeroString & "101" ?
'Question #12 - What is the value of "101" & ZeroString?
'Question #13 - What is the final value of lblAnswer?
'Question #14 - Rewrite the complete If statement above to perform an LSHIFT
' instead of an RSHIFT. Be sure to use good indentation and spacing.