如何在VB中实现点击按钮后,在文本框中每隔3秒产生1个0-9之间的随机数,共三个随机数?非常感谢!谢谢

如题,求教各位大神。拜谢!

第1个回答  2011-10-10
timer控件的Enabled属性设为false
timer控件的Interval属性改为3000,也就是3s

Private Sub Command1_Click() ’点击按钮开始计时
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer() '每隔3s产生一个1-9的随机数
Text1.Text = Int(Rnd() * 9 - 1 + 1) + 1
End Sub
第2个回答  2011-10-11
界面:三个文本框,一个按钮,一个计时器。
代码如下:
Private Sub Command1_Click()
Timer1.Enabled = Not Timer1.Enabled
If Timer1.Enabled Then
Timer1_Timer
Command1.Caption = "暂停"
Else
初始状态
End If
End Sub

Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 3000
初始状态
End Sub

Private Sub Timer1_Timer()
Randomize
Text1 = Int(Rnd * 9 + 1)
Text2 = Int(Rnd * 9 + 1)
Text3 = Int(Rnd * 9 + 1)
End Sub

Private Sub 初始状态()
Text1 = ""
Text2 = ""
Text3 = ""
Command1.Caption = "出数"
End Sub本回答被提问者采纳
第3个回答  2011-10-10
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.timer1.Enabled = true;
}

private void timer1_Tick(object sender, EventArgs e)
{
int b = GetRandom();
textBox1.Text = b.ToString();
int c = GetRandom();
textBox2.Text = c.ToString();
int d = GetRandom();
textBox3.Text = d.ToString();
}

private static int GetRandom()
{
Random a = new Random((int)DateTime.Now.Ticks);
int b = a.Next(10);
return b;
}

}
}
加个 timer控件就好了!
第4个回答  2011-10-10
三个文本框 每个文本框 出一个,还是 在同一个 文本框里 三秒 变一次?追问

三个文本框,每个文本框出一个。谢谢这位大哥帮忙。谢谢啦

第5个回答  2011-10-10
整数还是小数?

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网