问答题
【正确答案】[解析] 程序中用到了RGB函数,该函数通过红、绿、蓝三基色产生某种颜色,语法为RGB(红,绿,蓝)函数,其中括号中的红、绿、蓝三基色的范围为0~255之间的整数。解题步骤:
第一步:编写程序代码。
程序提供的代码:
Option Explicit
Private Sub Command1_Click()
End
End Sub
Private Sub Form_Load()
'Label4.BackColor = RGB( ?, HScroll2.Value, HScroll3.Value)
End Sub
Private Sub HScroll1_Change()
'Label4.? = RGB(HScrolll.Value, HScroll2.Value, HScroll3.Value)
End Sub
Private Sub HScroll2_Change()
'Label4.BackColor = ?(HScroll1.Value, HScroll2.Value, HScroll3.Value)
End Sub
Private Sub HScroll3_Change()
'? = RGB(HScrolll.Value, HScroll2.Value, HScroll3.Value)
End Sub
参考代码:
Option Explicit
Private Sub Command1_Click()
End
End Sub
Private Sub Form_Load()
Label4.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
End Sub
Private Sub HScroll1_Change()
Label4.BackColor = RGB(HScrolll.Value, HScroll2.Value, HScroll3.Value)
End Sub
Private Sub HScroll2_Change()
Label4.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
End Sub
Private Sub HScroll3_Change()
Label4.BackColor = RGB(HScrolll.Value, HScroll2.Value, HScroll3.Value)
End Sub
第二步:调试并运行程序。
第三步:按题目要求存盘。
(2)[解析] 该题用到两个函数和一个公式,Val()是将其内容转变为数字类型,Sqr()是求数值的平方根,而求解三角形的面积的时候用到海伦公式即S=Sqr(p*(p-a)*(p-b)*(p-c)),其中a、b、c是三角形的三个边,p=(a+b+c)/2。
解题步骤:
第一步:编写程序代码。
程序提供的代码:
Option Explicit
Dim a As Single
Dim b As Single
Dim c As Single
Dim S As Double
Dim L As Single
Private Sub Command1_Click()
a = Val (Text5.Text)
b = Val (Text6.Text)
c = Val (Text7.Text)
'If ? Then
Textl.Text = "是三角形"
'If ? Then
Text2.Text = "是直角三角形"
Else
'If ? Then
Text2.Text = "是锐角三角形"
Else: Text2.Text = "是钝角三角形"
End If
End If
Text3.Text = a + b + c '计算三角形的周长
L = (a + b + c) / 2
Text4.Text = Sqr(L * (n - a) * (L - b)(L - c) ) '计算三角形的面积
Else: Text1.Text = "非三角形"
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End If
Command2.Enabled = True
End Sub
Private Sub Command2_Click ()
'此处需要设置,以实现清空所有文本框及使“清除再来”失效的功能
'?
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub Form_Load ()
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Command2.Enabled = False
End Sub
参考代码:
Option Explicit
Dim a As Single
Dim b As Single
Dim c As Single
Dim S As Double
Dim L As Single
Private Sub Command1_Click()
a = Val (Text5.Text)
b = Val(Text6.Text)
c = Val (Text7.Text)
If a <> 0 And b <> 0 And c <> 0 And a + b > c And a + c > b And b + c > a Then
Text1.Text = "是三角形"
If a ^ 2 + b ^ 2 = c ^ 2 Or a ^ 2 + c ^ 2 = b ^ 2 Or b ^ 2 + c ^ 2 = a ^ 2 Then
Text2.Text = "是直角三角形"
Else
If a ^ 2 +b ^ 2 > c ^ 2Anda ^ 2 + c ^ 2 > b ^ 2 And b ^ 2 + c ^ 2 > a ^ 2 Then
Text2.Text = "是锐角三角形"
Else: Text2.Text = "是钝角三角形"
End If
End If
Text3.Text = a + b + c
L = (a + b + c) / 2
Text4.Text = Sqr(L * (L - a) * (L - b) * (L - c) )
Else
Text1.Text = "非三角形"
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End If
Command2.Enabled = True
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Command2.Enabled = False
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub Form_Load()
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Command2.Enabled = False
End Sub
第二步:调试并运行程序。
第三步:按题目要求存盘。
【答案解析】