April 28, 2008

《程式設計》樂透彩

 ☆~★~☆~★~☆
 《樂透彩 § 開盤囉》
 ☆~★~☆~★~☆
    
       有下載來玩的,回應一下吧!別當小偷唷!



《程式畫面》

 

《程式碼》

Private Sub Command1_Click()
Dim A(0 To 7) As Integer


Do Until A(1) <> A(2) And A(1) <> A(3)
 And A(1) <> A(4) And A(1) <> A(5) 
And A(1) <> A(6) And
 A(1) <> A(7) And A(2) <> A(3) And
 A(2) <> A(4) And A(2) <> A(5) And 
A(2) <> A(6) And A(2) <> A(7) And
 A(3) <> A(4) And A(3) <> A(5) And
 A(3) <> A(6) And A(3) <> A(7) And
 A(4) <> A(5) And A(4) <> A(6) And
 A(4) <> A(7) And A(5) <> A(6) And
 A(5) <> A(7) And A(6) <> A(7)

Randomize Time

For i = 1 To 7
A(i) = Int(Rnd * 42 + 1)
Next i

For j = 2 To 7
key = A(j)
    i = j - 1

   Do While i > 0 And A(i) > key
         A(i + 1) = A(i)
         i = i - 1
   Loop
  
A(i + 1) = key
Next j


Label1(0).Caption = A(1)
Label1(1).Caption = A(2)
Label1(2).Caption = A(3)
Label1(3).Caption = A(4)
Label1(4).Caption = A(5)
Label1(5).Caption = A(6)
Label1(6).Caption = A(7)


Loop


End Sub

Private Sub Command2_Click()
Dim A(0 To 7) As Integer


Do Until A(1) <> A(2) And A(1) <> A(3)
 And A(1) <> A(4) And A(1) <> A(5) 
And A(1) <> A(6) And
 A(1) <> A(7) And A(2) <> A(3) And
 A(2) <> A(4) And A(2) <> A(5) And 
A(2) <> A(6) And A(2) <> A(7) And
 A(3) <> A(4) And A(3) <> A(5) And
 A(3) <> A(6) And A(3) <> A(7) And
 A(4) <> A(5) And A(4) <> A(6) And
 A(4) <> A(7) And A(5) <> A(6) And
 A(5) <> A(7) And A(6) <> A(7)

Randomize Time

For i = 1 To 7
A(i) = Int(Rnd * 42 + 1)
Next i

For j = 2 To 7
key = A(j)
    i = j - 1

   Do While i > 0 And A(i) > key
         A(i + 1) = A(i)
         i = i - 1
   Loop
  
A(i + 1) = key
Next j


Text1(0).Text = A(1)
Text1(1).Text = A(2)
Text1(2).Text = A(3)
Text1(3).Text = A(4)
Text1(4).Text = A(5)
Text1(5).Text = A(6)
Text1(6).Text = A(7)


Loop

End Sub


Private Sub Command3_Click()
Dim T(0 To 6), L(0 To 6) As Integer
x = 0

For j = 0 To 6
T(j) = Text1(j).Text
  For i = 0 To 6
  L(i) = Label1(i).Caption
     If T(j) = L(i) Then
        x = x + 1
       
     Else
        x = x + 0
     End If
 
  Next i
Next j

Select Case x
Case Is = 0
Label2.Caption = "完全摃龜"
Case Is = 1
Label2.Caption = "只中一號"
Case Is = 2
Label2.Caption = "只差一號就有200元了"
Case Is = 3
Label2.Caption = "恭喜中了200元"
Case Is = 4
Label2.Caption = "恭喜中四獎"
Case Is = 5
Label2.Caption = "恭喜中三獎"
Case Is = 6
Label2.Caption = "恭喜中二獎"
Case Is = 7
Label2.Caption = "看到鬼了,你中頭彩"
End Select

End Sub


Private Sub Command4_Click()
End
End Sub


《作法》
紅色部份是利用亂數和Do迴圈
讓它開出七個不同的數字
放在Label1(0~6)中
而且用插入排序法排序過
在上篇中提到
資二的老師忽略的錯誤
(說明:出現了兩次同樣的數) 
在此篇中已修正成功
也就是使用Do until ....(很長那段)
有試圖修改為短一點
但還是不行
不過能運作不會當機就好 

綠色那段
也是利用亂數和Do迴圈
產生七個不同的電腦選號
放在Text1(0~6)中
而且也已用插入排序法排過
在此程式中
為求擬真
並不一定要用【電腦選號】
也可以自己選擇所須之號碼
來試試手氣

最後橙色的部份
則是利用循序搜尋法
先拿第一個數找看看
有沒有在Label1(0~6)中出現過
如果有,則X加1→代表中一個數
直到最後一個數
再用Select Case X 判斷
中了幾個數
再依各個不同的狀況
寫入不同的序述
之後便可完成

  ※補充:                   
原先可輸入N字元的Text
已用屬性中的選項       
控制為只能輸入2字元   
  


《心得》

再度利用以前學過的各種觀念
寫出了新的程式
發現科主任所說的大海
自己好像已深在其中
進入了不可自拔的地步

做完這個程式才發現
原來樂透是這麼難中
10次內才中一次200元
可見樂透少買為妙唷!

這次花了3天想程式+2天做程式 

備註:台客在【對獎】部份,
   有提供意見唷!

          

          

0推薦此文章
Today's Visitors: 0 Total Visitors: 202
Personal Category: ┬科展專用覽┴★〞 Topic: technology
歷史上的今天:
[Trackback URL]

Reply
  • 1樓

    1樓搶頭香

    去你的38死了!!

  • fangicheng at April 28, 2008 04:28 PM comment | prosecute
  • 2樓

    2樓頸推

    去你的38死了!!

  • fangicheng at April 28, 2008 04:28 PM comment | prosecute
  • 3樓

    3樓坐沙發

    去你的38死了!!

  • fangicheng at April 28, 2008 04:28 PM comment | prosecute
  • 5樓

    專業的5樓

    去你的38死了!!

  • fangicheng at April 28, 2008 04:28 PM comment | prosecute
  • 大芳別再亂了
    等等科主任又要說灌水很嚴重了

  • Blog Owner at April 28, 2008 04:47 PM Reply
  • 6樓

    6樓

    就說。。。。

    主謀是你!!!

  • fangicheng at April 28, 2008 04:54 PM comment | prosecute
  • 最好是我~
    科主任有眼睛的
    不會誤會好人

  • Blog Owner at April 28, 2008 04:59 PM Reply
  • 7樓

    7樓

    = =別人中獎了還說看到鬼了~

    這什麼鳥東西啊!?

    閒人閒人閒人~

    不是我要說.....

    我真的有下載來玩.....XD

    哈!哈!

    = =不過無聊.....

    閒人寫出來的東西....

    就是很無聊.....

  • lollipop0410 at April 28, 2008 06:09 PM comment | prosecute
  • 很好玩嗎
    好像不是這樣吼~
    我可是做了很久耶

  • Blog Owner at April 28, 2008 06:45 PM Reply
  • 8樓

    8樓

    對阿~

    科主任不會誤會好人的!

    因為我是好人,你是壞人呀~


    所以他不會誤會我的~

    so~

    你是主謀!!!!!!

  • fangicheng at April 28, 2008 06:41 PM comment | prosecute
  • = = 我不是

  • Blog Owner at April 28, 2008 06:45 PM Reply
  • 9樓

    9樓

    什麼?!

    你說你不是好人,是壞人呀!!!!

    早說咩~

    雖然我在好幾百年前就知道囉!!

    人要坦承的面對自己~接受現實吧!!!

  • fangicheng at April 28, 2008 06:50 PM comment | prosecute
  • 最好是醬啦~~

  • Blog Owner at April 28, 2008 06:51 PM Reply
  • 10樓

    10樓

    這是天經地義的道理你不懂嗎???

    你不懂竟敢還敢活在這個世上?!

    羞不羞恥呀你XDD!!


    阿對了~






    看看你的腳~~








    別猶豫了!!














    快看!!!!



















    你的鞋帶是不是又掉了呀XDDD?!






    哈哈哈!!

  • fangicheng at April 28, 2008 06:57 PM comment | prosecute
  • 我看了
    發現...我在室內
    我沒穿鞋 = =

  • Blog Owner at April 28, 2008 07:08 PM Reply
  • 11樓

    11樓

    踏踏
    歡迎來我家

  • shumyuet at April 29, 2008 05:22 AM comment | email | prosecute
  • 嗯嗯 ^^

  • Blog Owner at May 1, 2008 07:16 PM Reply
  • 12樓

    12樓

    Sealed

  • Sealed at May 1, 2008 11:21 AM comment
  • Sealed

  • Blog Owner at May 1, 2008 07:18 PM Reply
  • 13樓

    13樓

    Sealed

  • Sealed at May 1, 2008 10:39 PM comment
  • Sealed

  • Blog Owner at May 1, 2008 10:53 PM Reply
  • 14樓

    14樓

    Sealed

  • Sealed at May 1, 2008 11:55 PM comment
  • Sealed

  • Blog Owner at May 2, 2008 07:24 PM Reply
  • 15樓

    15樓

    Sealed

  • Sealed at April 29, 2013 03:53 AM comment
Post A Comment









Yes No





誰來收藏
Loading ...
unlog_NVPO 0