vb问题··请高手指教···急急急急··

2024-12-22 12:53:50
推荐回答(1个)
回答1:

1/////////////////////////////
如方程ax^2+bx+c=0
private sub command1_click()
dim a,b,c,t
a=inputbox("请输入a")
b=inputbox("请输入b")
c=inputbox("请输入c")
t=b^2-4*a*c
if t<0 then
msgbox "次方程无实根"
elseif t>0 then
print "x1=";(-1*b+sqr(t))/(2*a)
print "x2=";(-1*b-sqr(t))/(2*a)
elseif t=0 then
print "x1=x2";(-1*b)/(2*a)
end if

2.///////////////////////////////
把txtdisplay 的multiline 设置为true
Private Sub Form_Click()
txtDisplay.Text = ""
For i = 1 To 9
For j = 1 To 9
If j >= i Then
txtDisplay.Text = txtDisplay.Text & j & "*" & i & "=" & i * j & vbNewLine
Exit For
Else
txtDisplay.Text = txtDisplay.Text & j & "*" & i & "=" & i * j & " "
End If
Next
Next
End Sub

3\/////////////////////////////
Dim tt(100), s(10), temp1, temp2, temp3, i
Randomize
For i = 1 To 100
tt(i) = i
Next i
For i = 1 To 10
1 s(i) = tt(Int(Rnd() * 100 + 1))
If s(i) <> "" Then
temp3 = temp3 + s(i)
tt(s(i)) = ""
Else
GoTo 1
End If
Next i
temp3 = temp3 / 10
MsgBox s(1) & Chr(13) & s(2) & Chr(13) & s(3) & Chr(13) & s(4) _
& Chr(13) & s(5) & Chr(13) & s(6) & Chr(13) _
& s(7) & Chr(13) & s(8) & Chr(13) & s(9) & Chr(13) & s(10)
temp2 = 100
For i = 1 To 10
If s(i) >= temp1 Then temp1 = s(i)
If s(i) <= temp2 Then temp2 = s(i)
Next i
MsgBox "最大值:" & temp1 & Chr(13) & "最小值:" & temp2 & Chr(13) & "平均值:" & temp3
4\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Private Sub Command1_Click()
Dim i As Integer, aver As Double
For i = 1 To 100
sdt(i) = InputBox("input sdt(i) grade")
Next i
For i = 1 To 100
aver = aver + sdt(i)
Next i
aver = aver / 100
msg = "100个学生的平均成绩为" & aver
MsgBox msg
j = 0
For i = 1 To 100
If sdt(i) > aver Then
j = j + 1
End If
Next i
msg = "高于平均分的人数为" & j
MsgBox msg
End Sub