vb.net编写随机抽奖 vb设计随机抽奖程序 点击抽奖按钮 随机抽取

VB编写一个抽奖小程序,要求每次抽奖的数字不重复Dim n As Integer
Dim a()
Private Sub Command1_Click()
If n = 0 Then'第一次点击时执行
m = Val(Text1)
ReDim a(1 To m)
For i = 1 To m'生成数组a,元素为1至m这m个数
a(i) = i
Next
For i = 1 To m - 1'随机打乱数组a中元素
r = Int(Rnd * m + 1)
tmp = a(i)
a(i) = a(r)
a(r) = tmp
Next
End If
n = n + 1'计数点击次数
If nVal(Text1) Then'次数超过指定次数,抽奖结束
MsgBox "抽奖结束!"
Exit Sub
End If
Text2 = a(n)'从数组中抽出第n个数,由于数组中是随机排列,所以相当于生成一个随机数,并且不会重复
End Sub
vb.net 多次滚动抽奖的程序代码我用多线程写的,你可以参考下 。
系统界面图如下:(注:重置功能为清除已经中奖号码,回归1-100都可以中奖状态 。)
代码:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
System.Threading.Thread g_Thread = null;
Listint g_list = new Listint();
int g_Num = 0;
delegate void g_delegate();
/// summary
/// 开始
/// /summary
/// param name="sender"/param
/// param name="e"/param
private void button2_Click(object sender, EventArgs e)
{
if(g_list.Count==100)
{
MessageBox.Show("所有数字已使用,请重置!");
return;
}
button3.Enabled = true;
Random r = new Random();
g_delegate dele= ChangeTxt;
g_Thread = new System.Threading.Thread(() =
{
while(this.IsDisposed==false)
{
g_Num = r.Next(1, 100);
if(g_list.Contains(g_Num))
{
g_Num =1;
}
while(g_list.Contains(g_Num))
{
g_Num++;
}
this.Invoke(dele);
System.Threading.Thread.Sleep(50);
}
});
g_Thread.Start();
}
void ChangeTxt()
{
label2.Text = g_Num.ToString();
}
/// summary
/// 停止
/// /summary
/// param name="sender"/param
/// param name="e"/param
private void button3_Click(object sender, EventArgs e)
{
//if(g_Thread.ThreadState==System.Threading.ThreadState.Running)
{
g_Thread.Abort();
g_list.Add(Convert.ToInt32(label2.Text));
}
button3.Enabled = false;
}
/// summary
/// 重置
/// /summary
/// param name="sender"/param
/// param name="e"/param
private void button1_Click(object sender, EventArgs e)
{
g_list.Clear();
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
System.Environment.Exit(0);
}
}
VB设计一个随机抽奖程序,当单击开始按钮时,在两个文本框产生【1 , 20】之间的随机整数?假定开始按钮是 Command1vb.net编写随机抽奖 , 两个文本框分别是 Text1、Text2
Private Sub Command1_Click()
Randomize
Text1.Text = Int(Rnd * 20) + 1
Text2.Text = Int(Rnd * 20) + 1
End Sub
vb 编写一个抽奖程序command1用来随机抽取vb.net编写随机抽奖,text2显示
text1用来自己输入
command2用来判断
基本思想vb.net编写随机抽奖:假设连续有a位相同vb.net编写随机抽奖,经过验证如果为真则得出结果vb.net编写随机抽奖,如果为假vb.net编写随机抽奖,则假设a=a-1位相同……直到a=0
也可以自己输入text2数据来检验程序
这段程序不局限于7位数
Private Sub Command2_Click()
Dim a$, b$, i%, j%, k%
a = CStr(Text1)
b = CStr(Text2)
For i = Len(a) To 1 Step -1
For j = 1 To Len(a) - i + 1
If Mid(a, j, i) = Mid(b, j, i) Then
k = i
Exit For

推荐阅读