计算机编程问题-----VB程序设计

来源:百度知道 编辑:UC知道 时间:2024/05/24 19:02:03
窗体上有两个名称分别为C1, C2的命令按扭,一个文本框Text1。命令按钮的标题及文本框上显示的字符自定。编程实现当按下C1时,将C2的标题与Text1中的内容交换的代码怎样编写

dim a as string,b as string , c as string
a=text1.text
b=command2.caption
c=a
a=b
b=c
text1.text=a
command2.caption=b

鉴定过了。楼上的答案正确

Private Sub Command1_Click()
Dim a As String, b As String, c As String
a = Text1.Text

b = Command2.Caption

c = a 'a的值赋给临时变量c

a = b 'b赋给a实现转换

b = c '这里把c=a的值即a赋给a,即完成a、b的转换过程

Text1.Text = a

Command2.Caption = b
End Sub
Private Sub Form_Load()
Frame1.Caption = "简单交换程序"
Command1.Caption = "C1"
Command2.Caption = "C2"
Text1.Text = ""
Text1.ToolTipText = "最大不超过5个字符"
End Sub