ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

½Ð°Ý¦p¦ó¥ÎARRAY°µ¸ê®Æ¤ñ¹ï¡H

½Ð°Ý¦p¦ó¥ÎARRAY°µ¸ê®Æ¤ñ¹ï¡H

¬Ý¤F¤@¨ÇVBAªº±Ð¾Ç¡A¬Ý±o¥bÀ´¤£À´¡CÁÙ¬O¦Û¤v°Ê¤â¼g¤@¨ÇVBAªº¤pµ{¦¡¡A©â¾Ç±o¤ñ¸û§Ö¡C
³Ìªñ¹Á¸Õ¥ÎVBA¼gBINGO¹CÀ¸¡A³y¼Æ¦r¥dªº³¡¥÷©M©â¸¹½Xªº³¡¥÷³£¯à¦¨¥\¡A¥i¬O¥ÎVBA¹ï¸¹½Xªº³¡¥÷§Ú«o¤£¤F¸Ñ¡C
¥Ñ©óBINGO¹CÀ¸¥u­n¬O¡Gª½¡B¾î¡B¹ï¨¤½u¦¨¤@½u«K¥i¥H³Ó¥X¡C¥H5X5ªº¼Æ¦r¥d¬°¨Ò¡A¬O§_§Ú»Ý­n¼g¤U
5¾î¡B5ª½¡B2¹ï¨¤¡A¦@12­Ó²Õ¦XªºIF CONDITION¤~¯à°µ¤ñ¹ï¡H
´¿°Ý¹L¦P¨Æ¡A¥L«Øij§Ú¥i¥H¥ÎARRAYªº¤èªk°µ¡A¥]¬A©â¸¹½X©M³y¼Æ¦r¥d¤]¥i¥H¡C
§Ú¤j·§¤]¸Õ¹LARRAY¡A¥ý§âÀH¾÷¼Æ¦r©ñ¦bARRAY¤¤¡A¦A¶¶§Ç©â¥X¡A¦ý§ÚµLªkÁקK­«½Æ¼Æ¦r¡C

©Ò¥H§Ú·Q½Ð±Ð¤j®a¡A¤p§ÌªºDRAW©MPAPERªºµ{§Ç¥i¥H¥ÎARRAY§ï¼g¶Ü¡H
¥t¥~¡A¦p¦ó¦b©â¤@­Ó·sªº¸¹½X®É¤ñ¹ï¼Æ¦r¥d¡A¬Ý¬Ý¬O§_¤¤¼ú¡AÁÂÁ¤j®a¡C

bango.rar (14.37 KB)

¥»©«³Ì«á¥Ñ GBKEE ©ó 2011-12-16 17:53 ½s¿è

¦^´_ 1# ¤p«L«È
  1. Option Explicit
  2. Public Rng As Range, Rng1 As Range, Rng2 As Range
  3. Sub Restart()
  4.     Sheets(1).Cells.Clear
  5. End Sub
  6. Sub Draw()
  7.     Dim B As Integer, C As Integer, d As Integer
  8.     With Sheet1
  9. L:
  10.         B = Int(100 * Rnd() + 1)
  11.         C = Application.CountIf(.Range("A:A"), B)       '¤ñ¹ï¬O§_­«´_
  12.         If C = 1 Then GoTo L:                           '­«°µ¶Ã¼Æ
  13.         d = Application.CountA(.Range("A:A")) + 5
  14.         .Cells(d, 1) = B
  15.         .Cells(d, 1).Select
  16.         Bingo (B)
  17.     End With
  18. End Sub
  19. Sub Paper()
  20.     Dim E As Range, B As Integer, i As Integer, ii As Integer
  21.     Set Rng = [Sheet1!I1:M5]                  '³]©w¼Æ¦r°Ï°ì
  22.     For Each E In Rng
  23. L:
  24.         B = Int(100 * Rnd() + 1)
  25.         C = Application.CountIf(Rng, B)        '¤ñ¹ï¬O§_­«´_
  26.         If C = 1 Then GoTo L:
  27.             E = B
  28.     Next
  29.     For i = 1 To 5                             '³]©w¹ï¨¤½u¥Ñ¥ª¦Ü¥k°Ï°ì
  30.         If i = 1 Then
  31.             Set Rng1 = Rng.Cells(i, i)
  32.         Else
  33.             Set Rng1 = Union(Rng1, Rng.Cells(i, i))
  34.         End If
  35.     Next
  36.     ii = 5
  37.     For i = 1 To 5                             '³]©w¹ï¨¤½u¥Ñ¥k¦Ü¥ª°Ï°ì
  38.         If i = 1 Then
  39.             Set Rng2 = Rng.Cells(i, ii)
  40.         Else
  41.             Set Rng2 = Union(Rng1, Rng.Cells(i, ii))
  42.         End If
  43.         ii = ii - 1
  44.     Next
  45. End Sub
  46. Sub Bingo(No As Integer)
  47.     Dim f As Range, d As Integer, C As Range, i As Integer, ii As Integer
  48.     Set f = Rng.Find(No, LookIn:=xlValues, LOOKAT:=xlWhole)     '´M§ä¼Æ¦r
  49.     If f Is Nothing Then Exit Sub
  50.     If Not f Is Nothing Then
  51.         f.Font.ColorIndex = 3              '§ä¨ì¼Æ¦rµ¹¦rÅéÃC¦â
  52.         f.Font.FontStyle = "²ÊÅé"           '§ä¨ì¼Æ¦rµ¹¦r«¬¼Ë¦¡
  53.     End If
  54.     For i = 1 To Rng.Columns.Count
  55.         d = 0
  56.         For Each C In Rng.Columns(i).Cells
  57.             If C.Font.ColorIndex = 3 Then d = d + 1
  58.         Next
  59.         If d = 5 Then Rng.Columns(i).Select: GoTo ok
  60.      Next
  61.     For i = 1 To Rng.Rows.Count                               'Àˬd¾î¦C
  62.         d = 0
  63.         For Each C In Rng.Rows(i).Cells
  64.             If C.Font.ColorIndex = 3 Then d = d + 1
  65.         Next
  66.         If d = 5 Then Rng.Rows(i).Select: GoTo ok
  67.     Next
  68.     d = 0
  69.     For Each C In Rng1                                          'Àˬd¹ï¨¤½u
  70.             If C.Font.ColorIndex = 3 Then d = d + 1
  71.     Next
  72.     If d = 5 Then Rng1.Select: GoTo ok
  73.     d = 0
  74.     For Each C In Rng2                                          'Àˬd¹ï¨¤½u
  75.             If C.Font.ColorIndex = 3 Then d = d + 1
  76.     Next
  77.     If d = 5 Then Rng2.Select: GoTo ok
  78. Exit Sub
  79. ok:
  80. MsgBox "Bingo"
  81. End Sub
½Æ»s¥N½X

TOP

¦^´_ 1# ¤p«L«È
  1. Public k%
  2. Sub Draw()
  3. If Application.CountA([A:A]) >= k ^ 2 Then Exit Sub
  4. n = Int((k ^ 2) * Rnd + 1)
  5. Do Until IsError(Application.Match(n, [A:A], 0))
  6. n = Int((k ^ 2) * Rnd + 1)
  7. Loop
  8. r = Application.CountA([A:A]) + 1
  9. [A5].Offset(r) = n
  10. Set a = Range("I1").CurrentRegion.Find(n, lookat:=xlWhole)
  11. a.Interior.ColorIndex = 3
  12. Set b = a.EntireColumn
  13. Set c = a.EntireRow
  14. ar = Array(b, c)
  15. For i = 0 To 1
  16. yn = True
  17. For Each x In Intersect(ar(i), Range("I1").CurrentRegion)
  18.    If x.Interior.ColorIndex <> 3 Then yn = False: Exit For
  19. Next
  20. If yn = True Then MsgBox "Bango!!!": Exit Sub
  21. Next
  22. Set b = [I1]
  23. Set c = [I1].Offset(, k - 1)
  24. ar = Array(b, c)
  25. For i = 0 To 1
  26. yn = True: x = IIf(i = 0, 1, -1)
  27.   For j = 0 To k - 1
  28.   If ar(i).Offset(j, j * x).Interior.ColorIndex <> 3 Then yn = False: Exit For
  29.   Next
  30.    If yn = True Then MsgBox "Bango!!!": Exit Sub
  31. Next
  32. End Sub


  33. Sub Restart()
  34. Sheets(1).Cells.Clear
  35. Sheets(2).Cells.Clear
  36. Sheets(3).Cells.Clear
  37. End Sub

  38. Sub Paper()

  39. k = InputBox("¿é¤J°}¦Cºû¼Æ", , 5)
  40. ReDim ar(k, k)
  41. ReDim ay(k, k)
  42. For i = 0 To k - 1
  43.    For j = 0 To k - 1
  44.    ar(i, j) = Rnd
  45.    Next
  46. Next
  47. [I1].Resize(k, k) = ar
  48. For i = 0 To k - 1
  49.    For j = 0 To k - 1
  50.    ay(i, j) = Application.Rank(ar(i, j), [I1].Resize(k, k))
  51.    Next
  52. Next
  53. [I1].Resize(k, k) = ay

  54. End Sub
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

        ÀR«ä¦Û¦b : Ä@­n¤j¡B§Ó­n°í¡B®ð­n¬X¡B¤ß­n²Ó¡C
ªð¦^¦Cªí ¤W¤@¥DÃD