VB中产生随机数
各位大神,真的不会,麻烦说详细点,编程越简单越好,本人第一次学VB,别踩我。题目:使得单击一次按钮可以产生一个[60,90]之间的随机数并显示在标签1上,再求出该数的正弦...
各位大神,真的不会,麻烦说详细点,编程越简单越好,本人第一次学VB,别踩我。
题目:使得单击一次按钮可以产生一个[60,90]之间的随机数并显示在标签1上,再求出该数的正弦值,将结果写在标签2上。
提示
(1)使用Rnd函数产生随机数,注意,为了防止两次运行程序的随机数序列相同,调用Rnd之前先用Randomize语句进行初始化。
(2)产生某闭区间内的随机数的公式为:(上限-下限+1)*rnd+下限。
(3)求正弦值函数为:sin()。
图片 展开
题目:使得单击一次按钮可以产生一个[60,90]之间的随机数并显示在标签1上,再求出该数的正弦值,将结果写在标签2上。
提示
(1)使用Rnd函数产生随机数,注意,为了防止两次运行程序的随机数序列相同,调用Rnd之前先用Randomize语句进行初始化。
(2)产生某闭区间内的随机数的公式为:(上限-下限+1)*rnd+下限。
(3)求正弦值函数为:sin()。
图片 展开
展开全部
Private Sub cmdRanAngle_Click()
Dim dblAngle As double
Dim dblSin As double
'Randomize
dblAngle = dbl((90*ran)+60)
dblSin = sin(dblAngle)
lblScream.Caption = dblAngle
lblAnswer.caption = dblSin
End sub
最简单的方法,楼上都有错。。。。。
希望楼主采纳,有VB问题希望可以探讨,QQ827170254
Dim dblAngle As double
Dim dblSin As double
'Randomize
dblAngle = dbl((90*ran)+60)
dblSin = sin(dblAngle)
lblScream.Caption = dblAngle
lblAnswer.caption = dblSin
End sub
最简单的方法,楼上都有错。。。。。
希望楼主采纳,有VB问题希望可以探讨,QQ827170254
展开全部
将下面的代码粘贴到文本文件,另存*.frm 文件
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4470
ClientLeft = 60
ClientTop = 420
ClientWidth = 6165
LinkTopic = "Form1"
ScaleHeight = 4470
ScaleWidth = 6165
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "下一个随机数"
Height = 615
Left = 2040
TabIndex = 2
Top = 1440
Width = 1695
End
Begin VB.Label Label4
Caption = "正弦值:"
Height = 495
Left = 1320
TabIndex = 4
Top = 3600
Width = 855
End
Begin VB.Label Label3
Caption = "随机数(60-90):"
Height = 375
Left = 1320
TabIndex = 3
Top = 2880
Width = 1335
End
Begin VB.Label Label2
Height = 495
Left = 3360
TabIndex = 1
Top = 3600
Width = 1575
End
Begin VB.Label Label1
Height = 375
Left = 3240
TabIndex = 0
Top = 2880
Width = 2175
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Randomize
Label1.Caption = Rnd() * 30 + 60
Label2.Caption = Sin(Label1.Caption)
MsgBox Sin(56)
End Sub
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4470
ClientLeft = 60
ClientTop = 420
ClientWidth = 6165
LinkTopic = "Form1"
ScaleHeight = 4470
ScaleWidth = 6165
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "下一个随机数"
Height = 615
Left = 2040
TabIndex = 2
Top = 1440
Width = 1695
End
Begin VB.Label Label4
Caption = "正弦值:"
Height = 495
Left = 1320
TabIndex = 4
Top = 3600
Width = 855
End
Begin VB.Label Label3
Caption = "随机数(60-90):"
Height = 375
Left = 1320
TabIndex = 3
Top = 2880
Width = 1335
End
Begin VB.Label Label2
Height = 495
Left = 3360
TabIndex = 1
Top = 3600
Width = 1575
End
Begin VB.Label Label1
Height = 375
Left = 3240
TabIndex = 0
Top = 2880
Width = 2175
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Randomize
Label1.Caption = Rnd() * 30 + 60
Label2.Caption = Sin(Label1.Caption)
MsgBox Sin(56)
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
randomize
dim x,y as long (我忘了实型是不是single了)
x=rnd*31+60 (rnd有个值域,是取不到0还是1来着,你自己改改)
y=sin(x)
label1.caption=x
label2.caption=y
end sub
dim x,y as long (我忘了实型是不是single了)
x=rnd*31+60 (rnd有个值域,是取不到0还是1来着,你自己改改)
y=sin(x)
label1.caption=x
label2.caption=y
end sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-10-21
展开全部
Private Sub Command1_Click()
Randomize
Label1.Caption = (90 - 60 + 1) * Rnd + 60
Label2.Caption = Sin(Val(Label1.Caption))
End Sub
Randomize
Label1.Caption = (90 - 60 + 1) * Rnd + 60
Label2.Caption = Sin(Val(Label1.Caption))
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
dim x as double,y as double
randomize
x=rnd*31+60
y=sin(x)
label1.caption=x
label2.caption=y
end sub
dim x as double,y as double
randomize
x=rnd*31+60
y=sin(x)
label1.caption=x
label2.caption=y
end sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询