1樓:手機使用者
這幾天好多人問這道題啊.我已經幫其中一個人編好了.
下面的程式已經是一個比較完整的猜數字遊戲.你看看吧
將下面所有的文字,複製到 記事本 裡,
把檔案儲存為 csz.txt,再把副檔名改為 .frm
即最終檔案全名為: csz.frm
然後,在裝有vb6.0的機器上雙擊就可以了.
version 5.00
begin vb.form form1
borderstyle = 1 'fixed single
caption = "猜數字"
clientheight = 3480
clientleft = 45
clienttop = 330
clientwidth = 5970
linktopic = "form1"
maxbutton = 0 'false
minbutton = 0 'false
scaleheight = 3480
scalewidth = 5970
startupposition = 2 '螢幕中心
begin vb.commandbutton command1
caption = "幫 助"
height = 375
left = 4140
tabindex = 12
top = 2700
width = 795
endbegin vb.optionbutton opbdh
caption = "顯示代號"
height = 255
left = 4200
tabindex = 6
top = 2280
width = 1455
endbegin vb.optionbutton opbwz
caption = "顯示文字"
height = 255
left = 4200
tabindex = 5
top = 1980
value = -1 'true
width = 1455
endbegin vb.commandbutton cmdtc
caption = "退 出"
height = 375
left = 4980
tabindex = 8
top = 2700
width = 795
endbegin vb.textbox txtgc
height = 2955
left = 120
multiline = -1 'true
scrollbars = 2 'vertical
tabindex = 7
top = 120
width = 3735
endbegin vb.commandbutton cmdcs
caption = "猜數"
height = 375
left = 5040
tabindex = 4
top = 1440
width = 675
endbegin vb.commandbutton cmdnew
caption = "新 題 目"
height = 375
left = 4080
tabindex = 1
top = 120
width = 1635
endbegin vb.textbox txtcs
alignment = 2 'center
beginproperty font
name = "宋體"
size = 18
charset = 134
weight = 400
underline = 0 'false
italic = 0 'false
strikethrough = 0 'false
endproperty
height = 435
left = 4080
maxlength = 4
tabindex = 0
top = 1380
width = 855
endbegin vb.commandbutton cmdck
caption = "檢視"
height = 375
left = 5040
tabindex = 3
top = 780
width = 675
endbegin vb.label lblcs
alignment = 2 'center
caption = "0"
height = 195
left = 1200
tabindex = 10
top = 3180
width = 495
endbegin vb.label label2
caption = "[email protected]"
height = 195
left = 4200
tabindex = 9
top = 3180
width = 1515
endbegin vb.label lblsws
alignment = 2 'center
borderstyle = 1 'fixed single
beginproperty font
name = "宋體"
size = 18
charset = 134
weight = 400
underline = 0 'false
italic = 0 'false
strikethrough = 0 'false
endproperty
height = 435
left = 4080
tabindex = 2
top = 720
width = 855
endbegin vb.label label1
caption = "猜數次數:"
height = 195
left = 180
tabindex = 11
top = 3180
width = 915
endend
attribute vb_name = "form1"
attribute vb_globalnamespace = false
attribute vb_creatable = false
attribute vb_predeclaredid = true
attribute vb_exposed = false
option explicit
dim sws as string '儲存 四位數 的字串
dim cs as long '猜數的 次數
private sub cmdck_click()
lblsws.caption = sws
end sub
private sub cmdcs_click()
dim ts as string, txt as string, txtw(4) as integer
dim n as integer, zqs as integer, zqsw as integer
ts = "請輸入四位不重複的數字"
txt = txtcs.text
'判斷是否是四個字元
if len(txt) <> 4 then msgbox ts: exit sub
for n = 1 to 4
txtw(n) = mid(txt, n, 1)
next n
'判斷是否是四個數字
if asc(txtw(1)) < 48 or asc(txtw(1)) > 57 or asc(txtw(2)) < 48 or asc(txtw(2)) > 57 or asc(txtw(3)) < 48 or asc(txtw(3)) > 57 or asc(txtw(4)) < 48 or asc(txtw(4)) > 57 then msgbox ts: exit sub
'判斷是否有重複數字
if txtw(1) = txtw(2) or txtw(1) = txtw(3) or txtw(1) = txtw(4) or txtw(2) = txtw(3) or txtw(2) = txtw(4) or txtw(3) = txtw(4) then msgbox ts: exit sub
for n = 1 to 4
if instr(sws, txtw(n)) <> 0 then zqs = zqs + 1
if mid(sws, n, 1) = txtw(n) then zqsw = zqsw + 1
next n
if cs = 0 then txtgc.text = ""
cs = cs + 1
lblcs.caption = cstr(cs)
if opbwz.value then
txtgc.text = txtgc.text + txt + vbtab + cstr(zqs) + "個數字正確,其中" + cstr(zqsw) + "個位置也正確" + vbcrlf
else
txtgc.text = txtgc.text + txt + vbtab + cstr(zqs) + "a" + cstr(zqsw) + "b" + vbcrlf
end if
if zqsw = 4 then lblsws.caption = sws: msgbox "恭喜你!
你部猜中!" + vbcrlf + "猜測次數:" + cstr(cs) + vbcrlf + vbcrlf + "開始新題目!
": cmdnew_click
end sub
private sub cmdnew_click()
'生成新的四位數,並設定各控制元件的顯示值
dim sz as string
dim n as integer, sjs as integer
sz = "1234567890"
randomize timer
sws = ""
for n = 1 to 4
sjs = int(rnd * len(sz)) + 1
sws = sws + mid(sz, sjs, 1)
sz = left(sz, sjs - 1) + right(sz, len(sz) - sjs)
next n
cs = 0
lblsws.caption = "????"
txtgc.text = ""
lblcs.caption = cstr(cs)
end sub
private sub cmdtc_click()
unload me
end sub
private sub form_load()
cmdnew_click
txtgc.text = "檢視 按鈕,可以先檢視數字" + vbcrlf + "用於在遊戲過程中 做弊" + vbcrlf + "如果不需要這個功能,可以將按鈕的" + vbcrlf + "visible 屬性設定為 false"
end sub
private sub txtcs_keypress(keyascii as integer)
if keyascii = 13 then
cmdcs_click
txtcs.selstart = 0
txtcs.sellength = 4
end if
end sub
求高人解夢!萬分感激
夢境與凶吉禍福無關,常常是白天人的記憶造成的,就是日有所思夜有所夢。夢,是大腦無意識中將腦內資訊,無序的連結而成,有些是你早已忘記,在記憶邊緣的資訊都會被呼叫的,很神奇。但實際上,絕大多數夢是無法預見現實的。如果說夢能夠預見現實,而且這種預見可以被解讀,而且這種能人確實存在,我可以說,這種能人99....
乙肝難題 請專業醫生幫忙解答,萬分感激
你好 據你的情況你不需要 1 肝功能長期正常.2 乙肝兩對半為小三陽.3 hbv dna為陰性 4 b超正常 你以上指標全部正常是不需要 的 你的肝區應該是經常隱痛 所以乙肝小三陽患者都有這樣的症狀 這不是病變的症狀 放心 你只要吃好 喝好 休息好 就不會痛了!你日常生活要注意 不抽菸 不喝酒 不吃...
幫忙翻譯下病歷,最好是全文,萬分感激
發現行為異常 走路不穩2天。患者自訴於2天前自服 鼠藥王 一包及蟑螂藥一小塊。出現行為異常 走路不穩 疲乏。現來急診。藥物過敏史不詳。有抑鬱症。查體 神清應答切題,精神疲乏。雙肺呼吸音清,心率70次每分。律整齊。步態不穩 碎步。行走時動作不協調。右下肢巴氏症陽性。心電圖 竇緩1.精神異常。鼠藥王 中...