一道超低级的vb题

来源:百度知道 编辑:UC知道 时间:2024/04/29 02:07:42
设计命令按钮command1上鼠标点击事件处理过程:其处理如下:(1)从文本路框text1中取得用户输入的整数值存入变量n(2)在文本框text2中显示n值(3)若n等于整数的平方,则置text2的背景位红色,否则置text2的背景为黄色

Dim n As Long
n = TextBox1.Text
TextBox2.Text = n
Dim m As Long
m = n ^ (1 / 2)
Dim i As Long = 0
For i = 0 To n + 1
If m = i Then
TextBox2.ForeColor = Color.Red
Else
TextBox2.ForeColor = Color.Yellow
End If
next
i = i + 1
textbox2.color

VB6.0代码:

Option Explicit

Private Sub Command1_Click()
On Error GoTo err_handle
Dim n As Single
n = Text1.Text
Text2.Text = n
If Int(Sqr(Val(n))) ^ 2 = n Then Text2.BackColor = vbRed Else Text2.BackColor = vbYellow
Exit Sub
err_handle:
Exit Sub
End Sub