首先谢谢各位大神,
抽奖系统是用VB编写的,奖品在C:\program Files\Microsoft Visual Studio\WFJ.TXT (wfj.txt里) 现在状况是按空格或者确定键会随机从wfj.txt里抽取奖品,我想修改代码设置一个特定键,按了之后会指定显示wfj.txt的第一行!代码如下
FORM1代码Option Explicit
Dim gradeshu, filenum, num, filenum1, exit1 As Integer
Dim nextline, abcd, abcde, abcdef As StringPrivate Sub loadlist1(nextline As String)
Dim num1, i As Integer
num1 = Int(Mid(nextline, InStr(nextline, "/") + 1, InStr(nextline, " ") - InStr(nextline, "/") - 1)) - Int(Mid(nextline, InStr(nextline, ":") + 1, InStr(nextline, "/") - InStr(nextline, ":") - 1))
For i = 1 To num1
List1.AddItem (Trim(Mid(nextline, InStr(nextline, " "))))
Next
End SubPrivate Sub b_Click()
Dim str2 As String
Dim ab
str2 = ""
filenum1 = FreeFile
Open "c:\program Files\Microsoft Visual Studio\wfj.txt" For Input As filenum1
Do While Not EOF(filenum1)
Line Input #filenum1, nextline
If Trim(nextline) <> "" Then str2 = str2 + " " + Trim(Mid(nextline, InStr(nextline, ":") + 1)) + " " + vbCr
Loop
Close filenum1
ab = MsgBox(str2, vbOKOnly, "中奖人数")
End SubPrivate Sub c_Click()
End
End SubPrivate Sub d_Click()
Form2.Show
End SubPrivate Sub Form_Activate()
gradeshu = 0
List1.Clear
List2.Clear
filenum = FreeFile
Open "c:\program Files\Microsoft Visual Studio\wfj.txt" For Input As filenum
Do While Not EOF(filenum)
Line Input #filenum, nextline
nextline = Trim(nextline)
If nextline <> "" Then
gradeshu = gradeshu + 1
loadlist1 (nextline)
List2.AddItem (Trim(Mid(nextline, InStr(nextline, " "))))
End If
Loop
Close filenum
If List1.ListCount < 49 Then
If exit1 = 1 Then End
MsgBox (" 中奖名额少于50,抽奖结束,增加名额方可继续进行! ")
Form2.Show
exit1 = exit1 + 1
End If
start.Enabled = False
End SubPrivate Sub Form_Load()
exit1 = 0
End SubPrivate Sub abc()
start.Enabled = True: start.SetFocus: Call start_Click
End SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then Form1.PopupMenu a
If Button = 1 Then Call abc
End SubPrivate Sub Label2_Click()
Call abc
End SubPrivate Sub Label4_Click()
Call abc
End SubPrivate Sub Label5_Click()
Call abc
End SubPrivate Sub pause_Click()
Dim i As Integer
Dim str1(0 To 30) As String
Dim a, str2, num1 As String
pause.Enabled = False
Timer1.Enabled = False
Randomize
i = Int(List1.ListCount * Rnd(1))
a = Trim(List1.List(i))
Label4.Caption = vbCr + a
List1.RemoveItem (i)
i = 0
filenum = FreeFile
Open "c:\program Files\Microsoft Visual Studio\wfj.txt" For Input As filenum
Do While Not EOF(filenum)
Line Input #filenum, nextline
If Trim(nextline) <> "" Then str1(i) = Trim(nextline): i = i + 1
Loop
Close filenum
filenum = FreeFile
Open "c:\program Files\Microsoft Visual Studio\wfj.txt" For Output As filenum
For i = 0 To gradeshu - 1
If a = Trim(Mid(str1(i), InStr(str1(i), " "))) Then
Label5.Caption = Mid(str1(i), 1, 3)
num1 = Int(Mid(str1(i), InStr(str1(i), ":") + 1, InStr(str1(i), "/") - InStr(str1(i), ":") - 1)) + 1
str1(i) = Mid(str1(i), 1, InStr(str1(i), ":")) + num1 + Mid(str1(i), InStr(str1(i), "/"))
End If
Print #filenum, str1(i)
Next
Close filenum
num = 0
End SubPrivate Sub start_Click()
If List1.ListCount = 99 Then MsgBox (" 中奖名额少于100,通知营销策划部增加名额! ")
If List1.ListCount = 79 Then MsgBox (" 中奖名额少于80,通知营销策划部增加名额! ")
If List1.ListCount = 49 Then MsgBox (" 中奖名额少于50,抽奖结束,增加名额方可继续进行! "): Exit Sub
start.Enabled = False
pause.Enabled = True
pause.SetFocus
Timer1.Enabled = True
End SubPrivate Sub Timer1_Timer()
Randomize
Label4.Caption = vbCr + List2.List(Int(gradeshu * Rnd(2)))
End SubFORM2代码Option Explicit
Dim filenum As Integer
Dim nextline As StringPrivate Sub Command1_Click()
Dim str As String
If Trim(Text1.Text) = "24680" Then
str = Trim(RichTextBox1.Text) + vbCrLf
filenum = FreeFile
Open "c:\program Files\Microsoft Visual Studio\wfj.txt" For Output As filenum
Do While Len(str) > 8
Print #filenum, Mid(str, 1, InStr(str, vbCrLf) - 1)
str = Mid(str, InStr(str, vbCrLf) + 2)
Loop
Close #filenum
MsgBox (" 奖项设置保存成功! ")
Text1.Text = ""
Command2.SetFocus
Else
MsgBox " 密码不正确 ! ", , "提示": Text1.Text = "": Text1.SetFocus
End If
End SubPrivate Sub Command2_Click()
Unload Me
End SubPrivate Sub Form_Load()
RichTextBox1.Text = " "
filenum = FreeFile
Open "c:\program Files\Microsoft Visual Studio\wfj.txt" For Input As filenum
Do While Not EOF(filenum)
Line Input #filenum, nextline
nextline = Trim(nextline)
If nextline <> "" Then
RichTextBox1.Text = RichTextBox1.Text + nextline + vbCrLf + " "
End If
Loop
Close #filenum
End SubPrivate Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
If Trim(Text1.Text) = "24680" Then
Command1.Enabled = True
RichTextBox1.Visible = True
Command1.SetFocus
Else
MsgBox " 密码不正确 ! ", , "提示"
Text1.Text = ""
End If
End If
End Sub
抽奖系统是用VB编写的,奖品在C:\program Files\Microsoft Visual Studio\WFJ.TXT (wfj.txt里) 现在状况是按空格或者确定键会随机从wfj.txt里抽取奖品,我想修改代码设置一个特定键,按了之后会指定显示wfj.txt的第一行!代码如下
FORM1代码Option Explicit
Dim gradeshu, filenum, num, filenum1, exit1 As Integer
Dim nextline, abcd, abcde, abcdef As StringPrivate Sub loadlist1(nextline As String)
Dim num1, i As Integer
num1 = Int(Mid(nextline, InStr(nextline, "/") + 1, InStr(nextline, " ") - InStr(nextline, "/") - 1)) - Int(Mid(nextline, InStr(nextline, ":") + 1, InStr(nextline, "/") - InStr(nextline, ":") - 1))
For i = 1 To num1
List1.AddItem (Trim(Mid(nextline, InStr(nextline, " "))))
Next
End SubPrivate Sub b_Click()
Dim str2 As String
Dim ab
str2 = ""
filenum1 = FreeFile
Open "c:\program Files\Microsoft Visual Studio\wfj.txt" For Input As filenum1
Do While Not EOF(filenum1)
Line Input #filenum1, nextline
If Trim(nextline) <> "" Then str2 = str2 + " " + Trim(Mid(nextline, InStr(nextline, ":") + 1)) + " " + vbCr
Loop
Close filenum1
ab = MsgBox(str2, vbOKOnly, "中奖人数")
End SubPrivate Sub c_Click()
End
End SubPrivate Sub d_Click()
Form2.Show
End SubPrivate Sub Form_Activate()
gradeshu = 0
List1.Clear
List2.Clear
filenum = FreeFile
Open "c:\program Files\Microsoft Visual Studio\wfj.txt" For Input As filenum
Do While Not EOF(filenum)
Line Input #filenum, nextline
nextline = Trim(nextline)
If nextline <> "" Then
gradeshu = gradeshu + 1
loadlist1 (nextline)
List2.AddItem (Trim(Mid(nextline, InStr(nextline, " "))))
End If
Loop
Close filenum
If List1.ListCount < 49 Then
If exit1 = 1 Then End
MsgBox (" 中奖名额少于50,抽奖结束,增加名额方可继续进行! ")
Form2.Show
exit1 = exit1 + 1
End If
start.Enabled = False
End SubPrivate Sub Form_Load()
exit1 = 0
End SubPrivate Sub abc()
start.Enabled = True: start.SetFocus: Call start_Click
End SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then Form1.PopupMenu a
If Button = 1 Then Call abc
End SubPrivate Sub Label2_Click()
Call abc
End SubPrivate Sub Label4_Click()
Call abc
End SubPrivate Sub Label5_Click()
Call abc
End SubPrivate Sub pause_Click()
Dim i As Integer
Dim str1(0 To 30) As String
Dim a, str2, num1 As String
pause.Enabled = False
Timer1.Enabled = False
Randomize
i = Int(List1.ListCount * Rnd(1))
a = Trim(List1.List(i))
Label4.Caption = vbCr + a
List1.RemoveItem (i)
i = 0
filenum = FreeFile
Open "c:\program Files\Microsoft Visual Studio\wfj.txt" For Input As filenum
Do While Not EOF(filenum)
Line Input #filenum, nextline
If Trim(nextline) <> "" Then str1(i) = Trim(nextline): i = i + 1
Loop
Close filenum
filenum = FreeFile
Open "c:\program Files\Microsoft Visual Studio\wfj.txt" For Output As filenum
For i = 0 To gradeshu - 1
If a = Trim(Mid(str1(i), InStr(str1(i), " "))) Then
Label5.Caption = Mid(str1(i), 1, 3)
num1 = Int(Mid(str1(i), InStr(str1(i), ":") + 1, InStr(str1(i), "/") - InStr(str1(i), ":") - 1)) + 1
str1(i) = Mid(str1(i), 1, InStr(str1(i), ":")) + num1 + Mid(str1(i), InStr(str1(i), "/"))
End If
Print #filenum, str1(i)
Next
Close filenum
num = 0
End SubPrivate Sub start_Click()
If List1.ListCount = 99 Then MsgBox (" 中奖名额少于100,通知营销策划部增加名额! ")
If List1.ListCount = 79 Then MsgBox (" 中奖名额少于80,通知营销策划部增加名额! ")
If List1.ListCount = 49 Then MsgBox (" 中奖名额少于50,抽奖结束,增加名额方可继续进行! "): Exit Sub
start.Enabled = False
pause.Enabled = True
pause.SetFocus
Timer1.Enabled = True
End SubPrivate Sub Timer1_Timer()
Randomize
Label4.Caption = vbCr + List2.List(Int(gradeshu * Rnd(2)))
End SubFORM2代码Option Explicit
Dim filenum As Integer
Dim nextline As StringPrivate Sub Command1_Click()
Dim str As String
If Trim(Text1.Text) = "24680" Then
str = Trim(RichTextBox1.Text) + vbCrLf
filenum = FreeFile
Open "c:\program Files\Microsoft Visual Studio\wfj.txt" For Output As filenum
Do While Len(str) > 8
Print #filenum, Mid(str, 1, InStr(str, vbCrLf) - 1)
str = Mid(str, InStr(str, vbCrLf) + 2)
Loop
Close #filenum
MsgBox (" 奖项设置保存成功! ")
Text1.Text = ""
Command2.SetFocus
Else
MsgBox " 密码不正确 ! ", , "提示": Text1.Text = "": Text1.SetFocus
End If
End SubPrivate Sub Command2_Click()
Unload Me
End SubPrivate Sub Form_Load()
RichTextBox1.Text = " "
filenum = FreeFile
Open "c:\program Files\Microsoft Visual Studio\wfj.txt" For Input As filenum
Do While Not EOF(filenum)
Line Input #filenum, nextline
nextline = Trim(nextline)
If nextline <> "" Then
RichTextBox1.Text = RichTextBox1.Text + nextline + vbCrLf + " "
End If
Loop
Close #filenum
End SubPrivate Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
If Trim(Text1.Text) = "24680" Then
Command1.Enabled = True
RichTextBox1.Visible = True
Command1.SetFocus
Else
MsgBox " 密码不正确 ! ", , "提示"
Text1.Text = ""
End If
End If
End Sub
从txt到数组,2行代码就搞定(一个定义语句,一个读取和分解语句)
请参考:
Option Explicit
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 32 ''space
Label1.Caption = ReturnJP
Case 49 ''0
Case 65 ''a
Select Case Shift
Case 1 ''shift+a
Case 2 ''ctrl+a
Case 4 ''alt+a
End Select
End Select
End Sub
Function ReturnJP() As String
''要引用microsoft scripting runtime
On Error Resume Next
Dim FSO As New FileSystemObject, i As Integer, ww
ww = Split(FSO.GetFile("d:\idx.txt").OpenAsTextStream.ReadAll, vbCrLf)
If UBound(ww) > -1 Then
Randomize
i = Int(Rnd * (UBound(ww) + 1))
ReturnJP = ww(i)
Else
ReturnJP = "没有内容!"
End If
End Function...
Function ReturnJP() As String
''要引用microsoft scripting runtime
On Error Resume Next
Dim FSO As New FileSystemObject, i As Integer, ww
ww = Split(FSO.GetFile("d:\idx.txt").OpenAsTextStream.ReadAll, vbCrLf)
ReturnJP = "没有内容!"''默认值
If UBound(ww) > -1 Then
Randomize
i = Int(Rnd * (UBound(ww) + 1))
ReturnJP = ww(i)
End If
End Function
form里面添加keydown的代码就好
你的代码我懒得看
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
把你要作弊的那个文字显示到桌面上
end ifEnd Sub
这里的KeyAscii = 13 就是你作弊的时候按的键的ascii码值,13是回车,表示回车就开始作弊了