回文字符串是一个对称的字符串,它从左到右读和从右到左读是完全一样的。如“abcba”和“abccba”都是回文字符串,“abc”不是回文字符串。小王编写了一个验证回文字符串的VB程序,功能如下:在文本框Text1里输入一个字符串,单击命令按钮Command1,在文本框Text2中显示验证结果:是回文字符串显示“yes”,否则显示“no”。程序运行界面如图所示。
(1)
在设计程序界面时,要窗体Form1的标题栏上显示“判断回文字符串”,应修改Form1的属性。
(2)
实现上述功能的VB程序如下,请在划线处填入合适代码。
Private Sub Command1_Click() Dim st As String Dim i As Integer, j As Integer Dim flag As Boolean j = Len(st) i = 1 flag = True Do While flag And i <= j If Mid(st, i, 1) = Mid(st, j, 1) Then i = i + 1 Else flag = False End If Loop If Then Text2.Text = "yes" Else Text2.Text = "no" End If End Sub
答案: 【1】Caption
【1】st=Text.Text1【2】j=j-1【3】flag或Flag=True