vb.net抽奖程序,vb抽奖程序代码
vb.net产生随机数
方法名称:next();功能描述:返回一个0~2147483647之间的整数
成都创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都做网站、成都网站制作、宁远网络推广、重庆小程序开发、宁远网络营销、宁远企业策划、宁远品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;成都创新互联为所有大学生创业者提供宁远建站搭建服务,24小时服务热线:18980820575,官方网址:www.cdcxhl.com
方法名称:next(i);功能描述:返回一个0~i之间的整数
方法名称:next(i,j);功能描述:返回一个i~j之间的整数
方法名称:Nextdouble();功能描述:返回一个0~1之间的随机小数
================
使用方法:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim rand = New System.Random()
MsgBox(rand.next().ToString())
End Sub
==========================
产生N个不同数的话,我给你个我写的VB的代码,你稍微改下:
产生0-10的数:
Private Sub Command1_Click()
Randomize
Dim a(10) As Long
n = 10
For i = 0 To n
a(i) = Int(Rnd() * (n + 1))
For j = 0 To i - 1
If a(i) = a(j) Then
i = i - 1
Exit For
End If
Next
Next
For i = 0 To n
Print a(i)
Next
End Sub
VBNET编写抽奖软件程序
先把所有电话名单放在一个List泛型集合中,取出一个就Remove掉一个,这样就不会重复了。
几等奖几个按照你的需求来循环即可。
给文本框添加内容:TextBox1.Text = 字符串
换行用vbCrLf常量表示。
详细的可以私信
VB.net做一个小程序 求教
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim oleDbConnection1 As OleDb.OleDbConnection
Dim oledbDataAdapter As OleDb.OleDbDataAdapter
Dim oledbData As DataSet = New DataSet
Dim strConnect As String = "Provider= OraOLEDB.Oracle;Data Source=888;User ID=888;Password=888;"
oleDbConnection1 = New System.Data.OleDb.OleDbConnection(strConnect)
Dim strSql As String
strSql = "select *" " from xx"
Dim oledbCommand As OleDb.OleDbCommand
oledbCommand.CommandText = strSql
oledbCommand.CommandType = CommandType.Text
oledbCommand.Connection = oleDbConnection1
oledbDataAdapter.SelectCommand = oledbCommand
oleDbConnection1.Open()
oledbDataAdapter.Fill(oledbData, "gy_bingrenxx")
oleDbConnection1.Close()
'在窗体上添加一个DataGridView控件,在这个位置加一句代码
DataGridView1.DataSource = oledbDataAdapter.Tables("gy_bingrenxx")
End Sub
请教vb源代码,抽奖程序,从100个人中抽取三等奖3个,二等奖2个,一等奖1个,每次抽奖不重复。
Public Sub Main()
Dim allLeft As New List(Of Integer)()
For i As Integer = 0 To 99
allLeft.Add(i + 1)
Next
Dim r As New Random()
Dim [next] As Integer
Dim level As String
For i As Integer = 0 To 5
[next] = r.[Next]() Mod allLeft.Count
If i 3 Then
level = "Third"
ElseIf i 5 Then
level = "Second"
Else
level = "First"
End If
Console.WriteLine(level " level prize is: " allLeft([next]).ToString())
allLeft.RemoveAt([next])
Next
End Sub
怎么用VB做一个随机抽取器?
只要在代码中使用随机函数即可实现随机抽取功能
一、vb随机数生成的方法
vb随机数生成函数是 Rnd[(number)],number 参数为可选项。在调用 Rnd 生成随机数之前,先使用 Randomize 初始化随机数生成器来产生种子,该生成器是根据系统计时器来产生种子的。
1、生成100以内的随机数
Randomize
Int(Rnd() * 100)//生成 0 - 99 之间的随机数
Int(Rnd() * 101)//生成 0 - 100 之间的随机数
2、生成指定范围随机数
由于 vb 没有提供直接生成指定范围随机数的函数,所以要把 Rnd 变通一下,方法如下:
Int((上限 - 下限 + 1) * Rnd + 下限);
把它封装成可直接调用的函数如下:
Function GetRandom(under, over As Integer) As Integer
If under over Then
temp = under;
under = over;
over = temp;
End If
Randomize
GetRandom = Int((under - over + 1) * Rnd + over);
End Function
调用方法:
GetRandom(10, 100);//生成10到100的随机数
二、vb.net生成随机数的方法
1、方法:Random.Next(int minValue, int maxValue);
2、说明:
若 minValue 和 maxValue 都没有提供,则生成一个 0 - 2147483647 之间的随机数;
若 minValue 和 maxValue 只提供一个,则生成一个 0 - maxValue 之间的随机数;
若 minValue 和 maxValue 两个都提供,则生成一个 minValue - maxValue 之间的随机数;
3、举例
Dim ran = New System.Random()
ran.Next()//生成 0 - 2147483647 之间的随机数
ran.Next(100)//生成 0 - 100 之间的随机数
ran.Next(10, 100)//生成 10 - 100 之间的随机数
Dim ran = New Random(DateTime.Now.Millisecond)//通过日期的微秒生成随机数
什么是多线程技术?在VB 中如何使用?
vb6可以实现多线程,不过比较麻烦,vb.net完全支持多线程,请参见msdn.
至于vb6实现多线程请看CreateThread这个API函数.以下有详细方案:
用VB写多线程程序用到的第一个API函数是CreateThread,这个函数的声明如下:
Private Declare Function CreateThread Lib "kernel32" (ByVal lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadId As Long)As Long
这个函数的返回值是线程的句柄,它的参数含义如下:
1.lpThreadAttributes:这个参数表明函数的返回句柄是否可被子进程继承,如果可被继承,则指向一个SECURITY_ATTRIBUTES的结构,否则设为vbnull。
2.dwStackSize:这个参数设置线程的堆栈大小。
3.lpStartAddress:这个参数指明这个线程函数的起始地址。
4.lpParameter:这个参数是传给线程函数的参数。
5.dwCreationFlags:这个参数设置当线程创建时的初始状态,挂起,运行等等。
6.lpThreadId:这个参数是待创建线程的ID号。
假设创建一个管理线程的类clsThreads,用类的一个公用函数Initialize来初始化线程,用ResumeThread和SuspendThread函数来激活线程,实现代码如下:
Private Type udtThread
Handle As Long
Enabled As Boolean
End Type
Private uThread As udtThread
Private Const CREATE_SUSPENDED As Long = H4
Private Declare Function CreateThread Lib "kernel32" (ByVal lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long
Private Declare Function ResumeThread Lib "kernel32" (ByVal hThread As Long) As Long
Private Declare Function SuspendThread Lib "kernel32" (ByVal hThread As Long) As Long
Private Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long
Public Sub Initialize(ByVal lpfnBasFunc As Long) '初始化线程
Dim lStackSize As Long, lCreationFlags As Long, lpThreadId As Long, lNull As Long
On Error Resume Next
lNull = 0 '创建一个空指针
lStackSize = 0 '0表示用exe的stack size
lCreationFlags = CREATE_SUSPENDED '表示初始化后先不激活,让别人来激活
uThread.Handle = CreateThread(lNull, lStackSize, lpfnBasFunc, lNull, lCreationFlags, lpThreadId)
If uThread.Handle = lNull Then MsgBox "Create thread failed!"
End Sub
Public Property Get Enabled() As Boolean
On Error Resume Next
Enabled = uThread.Enabled
End Property
Public Property Let Enabled(ByVal vNewValue As Boolean)
On Error Resume Next
If vNewValue And (Not uThread.Enabled) Then
ResumeThread uThread.Handle '激活线程
uThread.Enabled = True
ElseIf uThread.Enabled Then
SuspendThread uThread.Handle
uThread.Enabled = False
End If
End Property
Private Sub Class_Terminate() '终止线程
On Error Resume Next
Call TerminateThread(uThread.Handle, 0)
End Sub
以上内容在类模块clsThreads中,有了它就可以在窗体中实现多线程了。下面以一个简单的例子来说明如何创建多线程(以2个线程为例)。
在form1中添加picture1和picture2两个图片框,以及一个command1按钮,在工程中添加一个bas模块,该模块的代码如下:
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Public Sub FlickerTop()
Static BgColor As Long
Dim lTick As Long, lCounter As Long
On Error Resume Next
For lCounter = 0 To 60000
BgColor = lCounter Mod 256
Form1.Picture1.BackColor = RGB(BgColor, 0, 0) '变化图片框的颜色
lTick = GetTickCount
While GetTickCount - lTick 10 '延迟10个毫秒时间
Wend
Next
End Sub
Public Sub FlickerBottom()
Static BgColor As Long
Dim lTick As Long, lCounter As Long
On Error Resume Next
For lCounter = 0 To 60000
BgColor = lCounter Mod 256
Form1.Picture2.BackColor = RGB(0, BgColor, 0)
lTick = GetTickCount
While GetTickCount - lTick 10
Wend
Next
End Sub
最后在form1中用下面的代码来创建两个线程,
Option Explicit
Public myThreadTop As New clsThreads, myThreadBottom As New clsThreads
Private Sub Command1_Click()
On Error Resume Next
With myThreadTop
.Initialize AddressOf FlickerTop
.Enabled = True
End With
With myThreadBottom
.Initialize AddressOf FlickerBottom
.Enabled = True
End With
MsgBox "看看会有什么..."
Set myThreadTop = Nothing
Set myThreadBottom = Nothing
End Sub
新闻名称:vb.net抽奖程序,vb抽奖程序代码
网站链接:http://hbruida.cn/article/heipep.html