会VB的大神们,求改正确

会VB的大神们,求改正确,第1张

有几处错误,S = c + 1, 变量c没有定义,也没有值,所以s的值会一直是1.下面的inputbox()右侧有两个括号,括号不匹配.改一下吧

Private Sub Command1_Click()

Dim t As Single

Dim S As Integer

S = 0

t = CSng(InputBox("请输入数据:", "竞猜手机价格", 0))

Do While t >0 And t <998 Or t >998

S = S + 1

MsgBox "猜错了,竞猜次数:"携消 &S

t = CSng(InputBox("卜斗请输入数据:", "竞猜手辩弊知机价格", 0))

Loop

If t = 998 Then

MsgBox "猜对了,竞猜次数" &Str(s)

End If

End Sub

“在随机数文本框出现跑动的两位随机整数”…… 这是个愰子,你只要开个定时器,设个间隔,里面用个随机数生成两位整数,显示到某个标签上去就行了。

真正的数字是在窗体加载的事件时,就用随机数产生了的,这个可中迟以存成全局的变量。以后经常要用到。

接下来,就是一个输入框和一个按扭。在按扭单击事件中,取文本框的值,首先判断是搭李不是数字,这个只要用转成数值型那个函数就够了,夹杂着字母什么的转不出数来。最后,比一下你随机产生的数字,跟输入进来的这个数字。

如果相同(猜中了),把定时器停下,把这个数显示在那个定时器控制着跑数的标签上。如果没猜中……就清了输入框就可以了。(你也可以在知培迟此d出一个MessageBox进行提示,比如猜大了还是猜小了。有心计的人使用折半查找法,猜个6-7次就能猜中。)

至于退出的那个按扭,单击事件里其实就一两句代码,没什么可说的。

结构分析完了,代码自己去写。这种初级的东西就是给新人练手用的,我不能跟小号抢怪……

把下面的代码复制到记事本中缺绝,改名为form1.frm,再用vb6打开编译即可使用。希望你能喜欢,不足之处可以提出来。

VERSION 5.00

Begin VB.Form Form1

BorderStyle = 5 'Sizable ToolWindow

Caption = "彩票选号程序"

ClientHeight= 3855

ClientLeft = 60

ClientTop = 330

ClientWidth = 6600

LinkTopic = "Form1"

MaxButton = 0 'False

MinButton = 0 '腔纤False

ScaleHeight = 3855

ScaleWidth = 6600

ShowInTaskbar = 0 'False

StartUpPosition = 3 '窗口缺省

Begin VB.Frame Frame4

Caption = "号码框"

Height = 2415

Left= 3600

TabIndex= 11

Top = 1320

Width = 2895

Begin VB.CommandButton Command6

Caption = "输入号码"

Height = 255

Left= 1560

TabIndex= 19

Top = 720

Width = 1095

End

Begin VB.CommandButton Command5

Caption = "试试运气"

Height = 495

Left= 120

TabIndex= 16

Top = 1440

Width = 2535

End

Begin VB.TextBox xx

Height = 270

Left= 1560

TabIndex= 14

Top = 1080

Width = 1095

End

Begin VB.TextBox sx

Height = 270

Left= 120

TabIndex= 13

Top = 1080

Width = 1095

End

Begin VB.Label Label5

Caption = "伍扮仿范围:"

Height = 255

Left= 120

TabIndex= 18

Top = 720

Width = 615

End

Begin VB.Label Label4

Caption = "机选号码:"

Height = 255

Left= 120

TabIndex= 17

Top = 2040

Width = 2535

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 = 135

Left= 1320

TabIndex= 15

Top = 1200

Width = 255

End

Begin VB.Label Label2

Caption = "我的号码:"

Height = 255

Left= 120

TabIndex= 12

Top = 360

Width = 2655

End

End

Begin VB.Frame Frame3

Caption = "统计框"

Height = 975

Left= 3600

TabIndex= 8

Top = 240

Width = 2895

Begin VB.CommandButton Command3

Caption = "点我统计!"

Height = 615

Left= 120

TabIndex= 9

Top = 240

Width = 2655

End

End

Begin VB.Frame Frame2

Caption = "查找框"

Height = 2415

Left= 120

TabIndex= 3

Top = 1320

Width = 3375

Begin VB.CommandButton Command4

Caption = "清除"

Height = 255

Left= 2400

TabIndex= 10

Top = 2040

Width = 855

End

Begin VB.CommandButton Command2

Caption = "查找"

Height = 255

Left= 2520

TabIndex= 7

Top = 240

Width = 735

End

Begin VB.ListBox List1

Height = 1320

ItemData= "Form1.frx":0000

Left= 120

List= "Form1.frx":0002

TabIndex= 5

Top = 600

Width = 3135

End

Begin VB.TextBox Text1

Height = 270

Left= 120

TabIndex= 4

Top = 240

Width = 2295

End

Begin VB.Label Label1

Caption = "总共:0项"

Height = 255

Left= 120

TabIndex= 6

Top = 2040

Width = 2175

End

End

Begin VB.Frame Frame1

Caption = "输入框"

Height = 1095

Left= 120

TabIndex= 0

Top = 120

Width = 3375

Begin VB.TextBox Text2

Height = 270

Left= 120

TabIndex= 2

Top = 240

Width = 3135

End

Begin VB.CommandButton Command1

Caption = "输入并确定"

Height = 375

Left= 120

TabIndex= 1

Top = 600

Width = 3135

End

End

End

Attribute VB_Name = "Form1"

Attribute VB_GlobalNameSpace = False

Attribute VB_Creatable = False

Attribute VB_PredeclaredId = True

Attribute VB_Exposed = False

Dim N As Long

Dim NR As String

Dim ZS As Long

Dim CS As Long

Dim mynum As Long

Private Sub Command1_Click()

Open "C:\1.TXT" For Append As #1

Print #1, Val(Text2.Text)

Close #1

Label2.Caption = "我的号码:" &Val(Text2.Text)

mynum = Val(Text2.Text)

Text2.Text = ""

End Sub

Private Sub Command2_Click()

CS = CS + 1

Open "C:\1.TXT" For Input As #1

Do While Not EOF(1)

Line Input #1, NR

NR = Trim(NR)

If NR = Text1.Text Then List1.AddItem NR: N = N + 1

Loop

Close #1

List1.AddItem "------------第" &CS &"次------------"

Label1.Caption = "总共:" &N &"项"

N = 0

NR = ""

End Sub

Private Sub Command3_Click()

Open "C:\1.TXT" For Input As #1

Do While Not EOF(1)

Line Input #1, NR

NR = Trim(NR)

If NR = NR Then ZS = ZS + 1

Loop

Close #1

MsgBox "共有" &ZS &"项"

ZS = 0

End Sub

Private Sub Command4_Click()

List1.Clear

End Sub

Private Sub Command5_Click()

Label4.Caption = "机选号码:" &Int(Rnd * Val(sx.Text)) + Val(xx.Text)

End Sub

Private Sub Command6_Click()

mynum = InputBox("输入号码:")

Label2.Caption = "我的号码:" &mynum

End Sub

Private Sub Form_Load()

N = 0

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12247672.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-22
下一篇 2023-05-22

发表评论

登录后才能评论

评论列表(0条)

保存