本文主要是介绍使用vb6.0编写的随机生成双色球中奖预测号码(STEP-BY-STEP版本),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
使用vb6.0编写的随机生成双色球中奖预测号码(STEP-BY-STEP版本)
2019/10/2 11:13
最近研究双色球,在网络上搜索到这里:
http://blog.sina.com.cn/s/blog_4cd4ffc401018xbx.html
vb编写双色球号码生成小程序源码
需要3个label,用来显示相应信息;两个文本框,一个显示生成的号码,一个用来设置号码数量;两个按钮,一个用来开始生成,一个用来复制生成的号码。完整代码如下:
源码:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 10350
ClientLeft = 120
ClientTop = 450
ClientWidth = 12510
LinkTopic = "Form1"
ScaleHeight = 10350
ScaleWidth = 12510
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "生成双色球"
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 1695
Left = 8760
TabIndex = 6
Top = 8400
Width = 2055
End
Begin VB.CommandButton Command1
Caption = "复制到剪贴板"
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 1575
Left = 4320
TabIndex = 5
Top = 8520
Width = 2535
End
Begin VB.TextBox Text2
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 6255
Left = 4080
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 4
Text = "000shuangseqiu5random.frx":0000
Top = 1920
Width = 7935
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 975
Left = 4080
TabIndex = 3
Text = "Text1"
Top = 720
Width = 1455
End
Begin VB.Label Label3
Caption = "所花时间"
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 1215
Left = 600
TabIndex = 2
Top = 8760
Width = 2415
End
Begin VB.Label Label2
Caption = "号码"
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 975
Left = 840
TabIndex = 1
Top = 2520
Width = 2055
End
Begin VB.Label Label1
Caption = "注数"
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Left = 960
TabIndex = 0
Top = 840
Width = 1935
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'首先声明一个生成号码的函数用于调用
'Sub 生成() 'vb的函数名称可以用汉字的,呵呵
Sub Generate5Random() 'vb的函数名称可以用汉字的,呵呵
Dim n(1 To 33), i, j, q, p '定义变量
For i = 1 To 33
n(i) = 0
Next
j = 0
Randomize Timer '防止随机数重复
While j < 6 '生成6个红球号码
q = Int(Rnd(1) * 33 + 1) '红球号码为01到33
If q < 10 Then '判断是否是小于10
q = 0 & q '小于10则在前面加0
End If
'如果生成的是重复的号码就重新生成一个!
If n(q) = 0 Then
Text2.Text = Text2.Text & q & " " '生成后写入文本框,各球中间用1个空格隔开
n(q) = 1
j = j + 1
End If
Wend
'红球已经生成完毕了,下面是蓝球,同红球
Randomize Timer
p = Int(Rnd(1) * 16 + 1)
If p < 10 Then '判断是否是小于10
p = 0 & p '小于10则在前面加0
End If
Text2.Text = Text2.Text & " " & p & vbCrLf '红球和蓝球联合起来,用两个空格隔开,末尾加上换行符,以便于生成多个号码
End Sub
Private Sub Command1_Click()
'使用Clipboard来实现复制到剪贴板功能
Clipboard.Clear
Clipboard.SetText Text2.Text
End Sub
Private Sub Command2_Click()
'我们在界面加上一个显示生成时间的小东西
Dim s, t, k
s = Timer '开始生成
Text2.Text = "" '先清空文本框
k = 0
While k < Val(Text1.Text) '按照需要来生成所需数量的号码
'Call 生成
Call Generate5Random
k = k + 1
Wend
t = Timer '生成结束
'默认显示耗时会出现.555秒的情况。加0之后会出现00秒的情况
'Label3.Caption = "用时" & t - s & "秒" '显示生成时间
Label3.Caption = "用时0" & t - s & "秒" '显示生成时间
End Sub
'如果没有预设,TEXT2里面就不会有内容!!!!
Private Sub Form_Load()
'在load里面设置一下文本框内容
Text2.Text = ""
Text1.Text = 5
End Sub
步骤:
增加代码,并修改label标签、TEXT文本框、Command命令按钮的名称为(有意义的)中文名。
修改窗体文字的字体:宋体、四号
修正TEXT2文本框的显示模式:可以换行
测试生成50注双色球:(下面的看不见了!)
保存窗体和工程并编译生成生成EXE文件:
源码:
https://download.csdn.net/download/wb4916/11831436
000shuangseqiu5random随机生成5注双色球20191002_1052.7z
这篇关于使用vb6.0编写的随机生成双色球中奖预测号码(STEP-BY-STEP版本)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!