|
Today I came across a question
about Visual Basic that involves the use of text to control
the appearance and disappearance of graphics. The question
is as follow:
"
Microsoft Visual Basic?
How can i have it so that when i
click a command button, a certain caption entered in a text
box will triger a shape to appear? This is what i have so
far:
Private Sub cmdcalculate_Click()
If txtcharacter = a Then
shpa.Visible = True
End Sub "
It is quite obvious that the
program won't work. Can you figure out why?
Ok, the correct program is
shown on the right hand side.
|
The complete code should be
Private Sub cmdcal_Click()
Dim txtcharacter As String
txtcharacter = txtchar.Text
If txtcharacter = "a" Then
Shpa.Visible = True
Else
Shpa.Visible = False
End If
End Sub
The mistakes in the original code are
(i) does not declare txtcharacter as a string data type
(ii) does not include End If After the If statement
(iii) does not include the opening and closing quotes " "
for the character a
(iv) should add the following statement
Else
Shpa.Visible = False
otherwise it will remains visible after you have entered the
character a. |