Avatar billede janvogt Praktikant
16. december 2003 - 10:59 Der er 37 kommentarer og
1 løsning

VBA: Generering af bankoplader

Som fortsættelse på det udmærkede eksempel i http://www.eksperten.dk/spm/440099 kunne det være sjovt at udbygge eksemplet til også at kunne generere tilfældige bankoplader.

Der er mange milliarder kombinationsmuligheder, så man kommer ikke sådan lige til at generere to ens.

Reglerne for en bankoplade er følgende:

1) Der benyttes tal fra og med 1 til og med 90.

2) En spilleplade er regtangulær med 3 (vandrette) rækker og 9 (lodrette) kolonner, og hver spilleplade rummer 15 forskellige numre. Hver spilleplade har derfor udover numrene 12 blanke felter. 2 plader kan i princippet godt indeholde de samme 15 tal, men alligevel være forskellige fordi placeringen af de blanke felter er forskellig.

3) Numrene er sådan fordelt på pladen, at der er mindst 1 tal og højst 3 tal i hver kolonne og netop 5 tal i hver række.

4) I hver kolonne placeres tallene i stigende orden.

5) Kolonne 1 indeholder tallene 1-9, kolonne 2 indeholder tallene 10-19 osv. Dog indeholder kolonne 9 tallene 80-90.

Lad os tage bare sige, at arket skal laves i området A1:I3.

Er der nogen, som kan lave VBA-koden til ovenstående?
Avatar billede kabbak Professor
16. december 2003 - 17:00 #1
Her er et bud, men mangler sortering, så mindste tal står først.

Public Sub BingoPlader()
Dim C(3) As Variant, UU(3) As Integer, X As Variant, U As Integer, I As Integer, Lille As Variant, Stor As Variant
  Lille = Array(1, 10, 20, 30, 40, 50, 60, 70, 80) ' mindste værdier
    Stor = Array(9, 19, 29, 39, 49, 59, 69, 79, 90) ' største værdier
   
   
    R = 0
    T = 0
     
    '****************************** Tilpasser pladen på arket ****************
    Range("A1:I3").Font.Size = 18
    Rows("1:3").RowHeight = 39.75
    Selection.RowHeight = 39.75
    Range("A1:I3").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
      End With
    Range("A1").Select
  '*********************************** Tilpasser pladen slut ****************

  A = Int(Rnd * 9) + 1 ' Randum fordeling
'****************************** Tilpasser Antal på pladen ****************
Select Case A
  Case 1
    R1 = Array(2, 1, 2, 1, 3, 2, 2, 1, 1)
  Case 2
    R1 = Array(1, 1, 3, 2, 1, 1, 2, 3, 1)
  Case 3
    R1 = Array(1, 2, 1, 3, 1, 2, 1, 2, 2)
  Case 4
    R1 = Array(2, 2, 1, 1, 1, 1, 3, 2, 2)
    Case 5
    R1 = Array(1, 2, 2, 1, 3, 2, 2, 1, 1)
    Case 6
    R1 = Array(3, 2, 1, 2, 2, 2, 1, 1, 1)
    Case 7
    R1 = Array(1, 2, 2, 2, 1, 3, 1, 1, 2)
    Case 8
    R1 = Array(3, 1, 2, 2, 1, 1, 2, 1, 2)
    Case 9
    R1 = Array(1, 2, 1, 1, 2, 1, 1, 3, 3)
  End Select
    '****************************** Tilpasser Antal slut ****************
   
   
For T = 0 To 8 ' 9 kolonner
  R = R + 1
    For I = 1 To 3 ' antal rækker
   
Start1:
      U = Int(Rnd * 3) + 1 'tilfældig placering på række
  UU(I) = U
    For Y = 1 To I - 1
      If UU(Y) = U Then GoTo Start1
    Next Y
Start2:
        X = Int((Rnd() * (Stor(T) - Lille(T)) + Lille(T)))
          If U > R1(T) Then
            Cells(I, R).Font.Size = 10 ' ændre tekststørrelsen på bart felt
          Cells(I, R) = "kabbak" ' bart felt
          GoTo BarFelt
        End If
 
  For Y = 1 To I - 1
      If C(Y) = X Then GoTo Start2
    Next Y
  C(Y) = X
  Cells(I, R) = X
 
BarFelt:
  Next I
Next T
End Sub
Avatar billede kabbak Professor
16. december 2003 - 18:26 #2
så skulle den være færdig

Public Sub BingoPlader()
Dim C(3) As Variant, UU(3) As Integer, X As Variant, U As Integer, I As Integer, Lille As Variant, Stor As Variant
Dim NyPlade As Integer
Columns("A:K").Clear
Q = InputBox(" indtast antal plader", "Antal plader", 1)
Application.ScreenUpdating = False
  Lille = Array(1, 10, 20, 30, 40, 50, 60, 70, 80) ' mindste værdier
    Stor = Array(9, 19, 29, 39, 49, 59, 69, 79, 90) ' største værdier
      NyPlade = 2
    R = 1
    T = 0

    '****************************** Tilpasser pladen på arket ****************
   
      Columns("B:J").ColumnWidth = 8
      Range("K:K,A:A").Select
      Range("A1").ColumnWidth = 2
      Selection.ColumnWidth = 2
      Rows("1:1").RowHeight = 12
      Range(Cells(1, 1), Cells(1, 11)).Interior.ColorIndex = 40
      Sideskift = 0
            For I = 1 To Q
            Sideskift = Sideskift + 1
          Range(Cells(NyPlade, 2), Cells(NyPlade + 2, 10)).Font.Size = 24
          Rows(NyPlade & ":" & NyPlade + 2).RowHeight = 39.75
        Range(Cells(NyPlade, 2), Cells(NyPlade + 2, 10)).Select
            Selection.Borders(xlEdgeLeft).LineStyle = xlContinuous
            Selection.Borders(xlEdgeTop).LineStyle = xlContinuous
            Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
            Selection.Borders(xlEdgeRight).LineStyle = xlContinuous
            Selection.Borders(xlInsideVertical).LineStyle = xlContinuous
            Selection.Borders(xlInsideHorizontal).LineStyle = xlContinuous
          With Selection
          .HorizontalAlignment = xlCenter
          .VerticalAlignment = xlCenter
        End With
          Rows(NyPlade + 3).RowHeight = 20
          Range(Cells(NyPlade + 3, 1), Cells(NyPlade + 3, 11)).Interior.ColorIndex = 40
       
        If Sideskift = 5 Then
        Sideskift = 0
          Rows(NyPlade + 4).RowHeight = 20
          Range(Cells(NyPlade + 4, 1), Cells(NyPlade + 4, 11)).Interior.ColorIndex = 40
        NyPlade = NyPlade + 5
        Else
        NyPlade = NyPlade + 4
        End If
        Next
        Range(Cells(1, 1), Cells(NyPlade - 1, 1)).Interior.ColorIndex = 40
        Range(Cells(1, 11), Cells(NyPlade - 1, 11)).Interior.ColorIndex = 40
    Range("A1").Select
  '*********************************** Tilpasser pladen slut ****************
  NyPlade = 2
  Sideskift = 0
  For ny = 1 To Q
  Sideskift = Sideskift + 1
  A = Int(Rnd * 9) + 1 ' Randum fordeling
'****************************** Tilpasser Antal på pladen ****************
Select Case A
  Case 1
    R1 = Array(2, 1, 2, 1, 3, 2, 2, 1, 1)
  Case 2
    R1 = Array(1, 1, 3, 2, 1, 1, 2, 3, 1)
  Case 3
    R1 = Array(1, 2, 1, 3, 1, 2, 1, 2, 2)
  Case 4
    R1 = Array(2, 2, 1, 1, 1, 1, 3, 2, 2)
    Case 5
    R1 = Array(1, 2, 2, 1, 3, 2, 2, 1, 1)
    Case 6
    R1 = Array(3, 2, 1, 2, 2, 2, 1, 1, 1)
    Case 7
    R1 = Array(1, 2, 2, 2, 1, 3, 1, 1, 2)
    Case 8
    R1 = Array(3, 1, 2, 2, 1, 1, 2, 1, 2)
    Case 9
    R1 = Array(1, 2, 1, 1, 2, 1, 1, 3, 3)
  End Select
    '****************************** Tilpasser Antal slut ****************
   
   
For T = 0 To 8 ' 9 kolonner
  R = R + 1
    For I = 1 To 3 ' antal rækker
   
Start1:
      U = Int(Rnd * 3) + 1 'tilfældig placering på række
  UU(I) = U
    For Y = 1 To I - 1
      If UU(Y) = U Then GoTo Start1
    Next Y
Start2:
        X = Int((Rnd() * (Stor(T) - Lille(T)) + Lille(T)))
          If U > R1(T) Then
            Cells(I + (NyPlade - 1), R).Font.Size = 10 ' ændre tekststørrelsen på bart felt
          Cells(I + (NyPlade - 1), R) = "kabbak" ' bart felt
          GoTo BarFelt
        End If
 
  For Y = 1 To I - 1
      If C(Y) = X Then GoTo Start2
    Next Y
  C(Y) = X
  Cells(I + (NyPlade - 1), R) = X
 
BarFelt:
  Next I
  '**************************** sortering **************
  For I = 1 To 3
  If Cells(I + (NyPlade - 1), R).Font.Size = 10 Then GoTo Tekst1
 
  For IV = 1 To 2
  If Cells(IV + (NyPlade - 1), R).Font.Size = 10 Then GoTo Tekst2
 
      If Cells(I + (NyPlade - 1), R) < Cells(IV + (NyPlade - 1), R) Then
        temp = Cells(I + (NyPlade - 1), R)
        Cells(I + (NyPlade - 1), R) = Cells(IV + (NyPlade - 1), R)
        Cells(IV + (NyPlade - 1), R) = temp
  End If
Tekst2:
  Next IV
Tekst1:
  Next I
 
    '**************************** sortering slut **************
Next T
    If Sideskift = 5 Then
        Sideskift = 0
        NyPlade = NyPlade + 5
        Else
        NyPlade = NyPlade + 4
        End If

  R = 1
Next ny
  Application.ScreenUpdating = True
End Sub
Avatar billede kabbak Professor
16. december 2003 - 18:32 #3
en lille ændring

Public Sub BingoPlader()
Dim C(3) As Variant, UU(3) As Integer, X As Variant, U As Integer, I As Integer, Lille As Variant, Stor As Variant
Dim NyPlade As Integer
Columns("A:K").Clear
Q = InputBox(" indtast antal plader", "Antal plader", 1)
Application.ScreenUpdating = False
  Lille = Array(1, 10, 20, 30, 40, 50, 60, 70, 80) ' mindste værdier
    Stor = Array(9, 19, 29, 39, 49, 59, 69, 79, 90) ' største værdier
      NyPlade = 2
    R = 1
    T = 0

    '****************************** Tilpasser pladen på arket ****************
   
      Columns("B:J").ColumnWidth = 8
      Range("K:K,A:A").Select
      Range("A1").ColumnWidth = 2
      Selection.ColumnWidth = 2
      Rows("1:1").RowHeight = 12
      Range(Cells(1, 1), Cells(1, 11)).Interior.ColorIndex = 40
      Sideskift = 0
            For I = 1 To Q
            Sideskift = Sideskift + 1
          Range(Cells(NyPlade, 2), Cells(NyPlade + 2, 10)).Font.Size = 24
          Rows(NyPlade & ":" & NyPlade + 2).RowHeight = 39.75
        Range(Cells(NyPlade, 2), Cells(NyPlade + 2, 10)).Select
            Selection.Borders(xlEdgeLeft).LineStyle = xlContinuous
            Selection.Borders(xlEdgeTop).LineStyle = xlContinuous
            Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
            Selection.Borders(xlEdgeRight).LineStyle = xlContinuous
            Selection.Borders(xlInsideVertical).LineStyle = xlContinuous
            Selection.Borders(xlInsideHorizontal).LineStyle = xlContinuous
          With Selection
          .HorizontalAlignment = xlCenter
          .VerticalAlignment = xlCenter
        End With
          Rows(NyPlade + 3).RowHeight = 20
          Range(Cells(NyPlade + 3, 1), Cells(NyPlade + 3, 11)).Interior.ColorIndex = 40
       
        If Sideskift = 5 Then
          If I = Q Then
              NyPlade = NyPlade + 4
            Else
              Sideskift = 0
              Rows(NyPlade + 4).RowHeight = 20
              Range(Cells(NyPlade + 4, 1), Cells(NyPlade + 4, 11)).Interior.ColorIndex = 40
              NyPlade = NyPlade + 5
        End If
        Else
        NyPlade = NyPlade + 4
        End If
        Next
        Range(Cells(1, 1), Cells(NyPlade - 1, 1)).Interior.ColorIndex = 40
        Range(Cells(1, 11), Cells(NyPlade - 1, 11)).Interior.ColorIndex = 40
    Range("A1").Select
  '*********************************** Tilpasser pladen slut ****************
  NyPlade = 2
  Sideskift = 0
  For ny = 1 To Q
  Sideskift = Sideskift + 1
  A = Int(Rnd * 9) + 1 ' Randum fordeling
'****************************** Tilpasser Antal på pladen ****************
Select Case A
  Case 1
    R1 = Array(2, 1, 2, 1, 3, 2, 2, 1, 1)
  Case 2
    R1 = Array(1, 1, 3, 2, 1, 1, 2, 3, 1)
  Case 3
    R1 = Array(1, 2, 1, 3, 1, 2, 1, 2, 2)
  Case 4
    R1 = Array(2, 2, 1, 1, 1, 1, 3, 2, 2)
    Case 5
    R1 = Array(1, 2, 2, 1, 3, 2, 2, 1, 1)
    Case 6
    R1 = Array(3, 2, 1, 2, 2, 2, 1, 1, 1)
    Case 7
    R1 = Array(1, 2, 2, 2, 1, 3, 1, 1, 2)
    Case 8
    R1 = Array(3, 1, 2, 2, 1, 1, 2, 1, 2)
    Case 9
    R1 = Array(1, 2, 1, 1, 2, 1, 1, 3, 3)
  End Select
    '****************************** Tilpasser Antal slut ****************
   
   
For T = 0 To 8 ' 9 kolonner
  R = R + 1
    For I = 1 To 3 ' antal rækker
   
Start1:
      U = Int(Rnd * 3) + 1 'tilfældig placering på række
  UU(I) = U
    For Y = 1 To I - 1
      If UU(Y) = U Then GoTo Start1
    Next Y
Start2:
        X = Int((Rnd() * (Stor(T) - Lille(T)) + Lille(T)))
          If U > R1(T) Then
            Cells(I + (NyPlade - 1), R).Font.Size = 10 ' ændre tekststørrelsen på bart felt
          Cells(I + (NyPlade - 1), R) = "kabbak" ' bart felt
          GoTo BarFelt
        End If
 
  For Y = 1 To I - 1
      If C(Y) = X Then GoTo Start2
    Next Y
  C(Y) = X
  Cells(I + (NyPlade - 1), R) = X
 
BarFelt:
  Next I
  '**************************** sortering **************
  For I = 1 To 3
  If Cells(I + (NyPlade - 1), R).Font.Size = 10 Then GoTo Tekst1
 
  For IV = 1 To 2
  If Cells(IV + (NyPlade - 1), R).Font.Size = 10 Then GoTo Tekst2
 
      If Cells(I + (NyPlade - 1), R) < Cells(IV + (NyPlade - 1), R) Then
        temp = Cells(I + (NyPlade - 1), R)
        Cells(I + (NyPlade - 1), R) = Cells(IV + (NyPlade - 1), R)
        Cells(IV + (NyPlade - 1), R) = temp
  End If
Tekst2:
  Next IV
Tekst1:
  Next I
 
    '**************************** sortering slut **************
Next T
    If Sideskift = 5 Then
        Sideskift = 0
        NyPlade = NyPlade + 5
        Else
        NyPlade = NyPlade + 4
        End If

  R = 1
Next ny
  Application.ScreenUpdating = True
End Sub
Avatar billede kabbak Professor
16. december 2003 - 19:10 #4
udskift
X = Int((Rnd() * (Stor(T) - Lille(T)) + Lille(T)))
med denne
X = Int((Rnd() * (Stor(T) - Lille(T) + 1) + Lille(T)))
Avatar billede kabbak Professor
16. december 2003 - 23:35 #5
Den var ikke færdig alligevel, jeg glemte det med 5 på hver række.

Så det er den nu.


Public Sub BingoPlader()
Dim C(3) As Variant, UU(3) As Integer, X As Variant, U As Integer, I As Integer, Lille As Variant, Stor As Variant
Dim NyPlade As Integer, Rcount(2) As Integer

LilleTekst = 10          ' ret Font Size her for lille skrift
StorTekst = 24            ' ret Font Size her for stor skrift
BlankFeltTekst = "kabbak" ' ret blank felt tekst her
Kantfarve = 40            'Ret kantfarver her

Columns("A:K").Clear
Q = InputBox("indtast antal plader", "Antal plader", 1) ' antal plader, 5 på hvert A4 ark
Application.ScreenUpdating = False                ' slår skærm opdateringen fra
    Lille = Array(1, 10, 20, 30, 40, 50, 60, 70, 80) ' mindste værdier
    Stor = Array(9, 19, 29, 39, 49, 59, 69, 79, 90)  ' største værdier
      NyPlade = 2
    R = 1
    T = 0

    '****************************** Tilpasser pladen på arket ****************
   
      Columns("B:J").ColumnWidth = 8
      Range("K:K,A:A").Select
      Range("A1").ColumnWidth = 2
      Selection.ColumnWidth = 2
      Rows("1:1").RowHeight = 12
      Range(Cells(1, 1), Cells(1, 11)).Interior.ColorIndex = Kantfarve
      Sideskift = 0
            For I = 1 To Q
            Sideskift = Sideskift + 1
          Range(Cells(NyPlade, 2), Cells(NyPlade + 2, 10)).Font.Size = StorTekst
          Rows(NyPlade & ":" & NyPlade + 2).RowHeight = 39.75
        Range(Cells(NyPlade, 2), Cells(NyPlade + 2, 10)).Select
            Selection.Borders(xlEdgeLeft).LineStyle = xlContinuous
            Selection.Borders(xlEdgeTop).LineStyle = xlContinuous
            Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
            Selection.Borders(xlEdgeRight).LineStyle = xlContinuous
            Selection.Borders(xlInsideVertical).LineStyle = xlContinuous
            Selection.Borders(xlInsideHorizontal).LineStyle = xlContinuous
          With Selection
          .HorizontalAlignment = xlCenter
          .VerticalAlignment = xlCenter
        End With
          Rows(NyPlade + 3).RowHeight = 20
          Range(Cells(NyPlade + 3, 1), Cells(NyPlade + 3, 11)).Interior.ColorIndex = Kantfarve
       
        If Sideskift = 5 Then
          If I = Q Then
              NyPlade = NyPlade + 4
            Else
              Sideskift = 0
              Rows(NyPlade + 4).RowHeight = 20
              Range(Cells(NyPlade + 4, 1), Cells(NyPlade + 4, 11)).Interior.ColorIndex = Kantfarve
              NyPlade = NyPlade + 5
        End If
        Else
        NyPlade = NyPlade + 4
        End If
        Next
        Range(Cells(1, 1), Cells(NyPlade - 1, 1)).Interior.ColorIndex = Kantfarve
        Range(Cells(1, 11), Cells(NyPlade - 1, 11)).Interior.ColorIndex = Kantfarve
    Range("A1").Select
  '*********************************** Tilpasser pladen slut ****************
  NyPlade = 2
  Sideskift = 0
  For ny = 1 To Q
  Sideskift = Sideskift + 1
  A = Int(Rnd * 9) + 1 ' Randum fordeling
'****************************** Tilpasser Antal på pladen ****************
Select Case A
  Case 1
    R1 = Array(2, 1, 2, 1, 3, 2, 2, 1, 1)
  Case 2
    R1 = Array(1, 1, 3, 2, 1, 1, 2, 3, 1)
  Case 3
    R1 = Array(1, 2, 1, 3, 1, 2, 1, 2, 2)
  Case 4
    R1 = Array(2, 2, 1, 1, 1, 1, 3, 2, 2)
    Case 5
    R1 = Array(1, 2, 2, 1, 3, 2, 2, 1, 1)
    Case 6
    R1 = Array(3, 2, 1, 2, 2, 2, 1, 1, 1)
    Case 7
    R1 = Array(1, 2, 2, 2, 1, 3, 1, 1, 2)
    Case 8
    R1 = Array(3, 1, 2, 2, 1, 1, 2, 1, 2)
    Case 9
    R1 = Array(1, 2, 1, 1, 2, 1, 1, 3, 3)
  End Select
    '****************************** Tilpasser Antal slut ****************
   
   
For T = 0 To 8 ' 9 kolonner
  R = R + 1
    For I = 1 To 3 ' antal rækker
   
Start1:
      U = Int(Rnd * 3) + 1 'tilfældig placering på række
  UU(I) = U
    For Y = 1 To I - 1
      If UU(Y) = U Then GoTo Start1
    Next Y
Start2:
        X = Int((Rnd() * (Stor(T) - Lille(T) + 1) + Lille(T)))
          If U > R1(T) Then
            Cells(I + (NyPlade - 1), R).Font.Size = LilleTekst ' ændre tekststørrelsen på bart felt
          Cells(I + (NyPlade - 1), R) = BlankFeltTekst ' bart felt
          GoTo BarFelt
        End If
 
  For Y = 1 To I - 1
      If C(Y) = X Then GoTo Start2
    Next Y
  C(Y) = X
  Cells(I + (NyPlade - 1), R) = X
 
BarFelt:
  Next I
  '**************************** sortering lodret stigende **************
  For I = 1 To 3
  If Cells(I + (NyPlade - 1), R).Font.Size = LilleTekst Then GoTo Tekst1
 
    For Iv = 1 To 2
    If Cells(Iv + (NyPlade - 1), R).Font.Size = LilleTekst Then GoTo Tekst2
      If Cells(I + (NyPlade - 1), R) < Cells(Iv + (NyPlade - 1), R) Then
        temp = Cells(I + (NyPlade - 1), R)
        Cells(I + (NyPlade - 1), R) = Cells(Iv + (NyPlade - 1), R)
        Cells(Iv + (NyPlade - 1), R) = temp
    End If
Tekst2:
    Next Iv
Tekst1:
  Next I
  Next T
    '**************************** sortering 5 i hver række **************

TjekIgen:

For I = 0 To 2
Rcount(I) = 0
For Each NR In Range(Cells(NyPlade + I, 2), Cells(NyPlade + I, 10))
If IsNumeric(NR) Then
  Rcount(I) = Rcount(I) + 1
End If
Next
Next
    If Rcount(0) < 5 And Rcount(1) > 5 Then fra = 1: Til = 0: GoTo FlytPlads
    If Rcount(0) < 5 And Rcount(2) > 5 Then fra = 2: Til = 0: GoTo FlytPlads
    If Rcount(1) < 5 And Rcount(0) > 5 Then fra = 0: Til = 1: GoTo FlytPlads
    If Rcount(1) < 5 And Rcount(2) > 5 Then fra = 2: Til = 1: GoTo FlytPlads
    If Rcount(2) < 5 And Rcount(0) > 5 Then fra = 0: Til = 2: GoTo FlytPlads
    If Rcount(2) < 5 And Rcount(1) > 5 Then fra = 1: Til = 2: GoTo FlytPlads
  GoTo AltOk
FlytPlads:
  For Iv = 1 To 9
    If IsNumeric(Cells(NyPlade + fra, Iv + 1)) Then ' rækken med mere end 5
    If Cells(NyPlade + Til, Iv + 1) = BlankFeltTekst Then 'rækken med mindre end 5 og skal være blank
      Cells(NyPlade + Til, Iv + 1) = Cells(NyPlade + fra, Iv + 1) ' flytter række
      Cells(NyPlade + Til, Iv + 1).Font.Size = StorTekst  ' ændrer skriftstørrelse
      Cells(NyPlade + fra, Iv + 1) = BlankFeltTekst    ' skriver blank tekst
      Cells(NyPlade + fra, Iv + 1).Font.Size = LilleTekst  ' ændrer skriftstørrelse på blank
    GoTo TjekIgen
    End If
  End If
  Next
GoTo TjekIgen
'**************************** sortering slut **************
AltOk:
    If Sideskift = 5 Then
        Sideskift = 0
        NyPlade = NyPlade + 5
        Else
        NyPlade = NyPlade + 4
        End If
    R = 1
Next ny
  Application.ScreenUpdating = True
End Sub
Avatar billede kabbak Professor
17. december 2003 - 01:04 #6
Den sorterede ikke ordentlig, så det er sidste bud fra mig.

Men hvis nogen kunne opdater sorteringen så den blev hurtigere, vil jeg da gerne høre nærmere.

Public Sub BingoPlader()
Dim C(3) As Variant, UU(3) As Integer, X As Variant, U As Integer, I As Integer, Lille As Variant, Stor As Variant
Dim NyPlade As Integer, Rcount(2) As Integer

LilleTekst = 10          ' ret Font Size her for lille skrift
StorTekst = 24            ' ret Font Size her for stor skrift
BlankFeltTekst = "kabbak" ' ret blank felt tekst her
Kantfarve = 40            'Ret kantfarver her

Columns("A:K").Clear
Q = InputBox("indtast antal plader", "Antal plader", 1) ' antal plader, 5 på hvert A4 ark
Application.ScreenUpdating = False                ' slår skærm opdateringen fra
    Lille = Array(1, 10, 20, 30, 40, 50, 60, 70, 80) ' mindste værdier
    Stor = Array(9, 19, 29, 39, 49, 59, 69, 79, 90)  ' største værdier
      NyPlade = 2
    R = 1
    T = 0

    '****************************** Tilpasser pladen på arket ****************
   
      Columns("B:J").ColumnWidth = 8
      Range("K:K,A:A").Select
      Range("A1").ColumnWidth = 2
      Selection.ColumnWidth = 2
      Rows("1:1").RowHeight = 12
      Range(Cells(1, 1), Cells(1, 11)).Interior.ColorIndex = Kantfarve
      Sideskift = 0
            For I = 1 To Q
            Sideskift = Sideskift + 1
          Range(Cells(NyPlade, 2), Cells(NyPlade + 2, 10)).Font.Size = StorTekst
          Rows(NyPlade & ":" & NyPlade + 2).RowHeight = 39.75
        Range(Cells(NyPlade, 2), Cells(NyPlade + 2, 10)).Select
            Selection.Borders(xlEdgeLeft).LineStyle = xlContinuous
            Selection.Borders(xlEdgeTop).LineStyle = xlContinuous
            Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
            Selection.Borders(xlEdgeRight).LineStyle = xlContinuous
            Selection.Borders(xlInsideVertical).LineStyle = xlContinuous
            Selection.Borders(xlInsideHorizontal).LineStyle = xlContinuous
          With Selection
          .HorizontalAlignment = xlCenter
          .VerticalAlignment = xlCenter
        End With
          Rows(NyPlade + 3).RowHeight = 20
          Range(Cells(NyPlade + 3, 1), Cells(NyPlade + 3, 11)).Interior.ColorIndex = Kantfarve
       
        If Sideskift = 5 Then
          If I = Q Then
              NyPlade = NyPlade + 4
            Else
              Sideskift = 0
              Rows(NyPlade + 4).RowHeight = 20
              Range(Cells(NyPlade + 4, 1), Cells(NyPlade + 4, 11)).Interior.ColorIndex = Kantfarve
              NyPlade = NyPlade + 5
        End If
        Else
        NyPlade = NyPlade + 4
        End If
        Next
        Range(Cells(1, 1), Cells(NyPlade - 1, 1)).Interior.ColorIndex = Kantfarve
        Range(Cells(1, 11), Cells(NyPlade - 1, 11)).Interior.ColorIndex = Kantfarve
    Range("A1").Select
  '*********************************** Tilpasser pladen slut ****************
  NyPlade = 2
  Sideskift = 0
  For ny = 1 To Q
  Sideskift = Sideskift + 1
  A = Int(Rnd * 9) + 1 ' Randum fordeling
'****************************** Tilpasser Antal på pladen ****************
Select Case A
  Case 1
    R1 = Array(2, 1, 2, 1, 3, 2, 2, 1, 1)
  Case 2
    R1 = Array(1, 1, 3, 2, 1, 1, 2, 3, 1)
  Case 3
    R1 = Array(1, 2, 1, 3, 1, 2, 1, 2, 2)
  Case 4
    R1 = Array(2, 2, 1, 1, 1, 1, 3, 2, 2)
    Case 5
    R1 = Array(1, 2, 2, 1, 3, 2, 2, 1, 1)
    Case 6
    R1 = Array(3, 2, 1, 2, 2, 2, 1, 1, 1)
    Case 7
    R1 = Array(1, 2, 2, 2, 1, 3, 1, 1, 2)
    Case 8
    R1 = Array(3, 1, 2, 2, 1, 1, 2, 1, 2)
    Case 9
    R1 = Array(1, 2, 1, 1, 2, 1, 1, 3, 3)
  End Select
    '****************************** Tilpasser Antal slut ****************
   
   
For T = 0 To 8 ' 9 kolonner
  R = R + 1
    For I = 1 To 3 ' antal rækker
   
Start1:
      U = Int(Rnd * 3) + 1 'tilfældig placering på række
  UU(I) = U
    For Y = 1 To I - 1
      If UU(Y) = U Then GoTo Start1
    Next Y
Start2:
        X = Int((Rnd() * (Stor(T) - Lille(T) + 1) + Lille(T)))
          If U > R1(T) Then
            Cells(I + (NyPlade - 1), R).Font.Size = LilleTekst ' ændre tekststørrelsen på bart felt
          Cells(I + (NyPlade - 1), R) = BlankFeltTekst ' bart felt
          GoTo BarFelt
        End If
 
  For Y = 1 To I - 1
      If C(Y) = X Then GoTo Start2
    Next Y
  C(Y) = X
  Cells(I + (NyPlade - 1), R) = X
 
BarFelt:
  Next I
Next T
    '**************************** sortering 5 i hver række **************
TjekIgen:

For I = 0 To 2
Rcount(I) = 0
For Each NR In Range(Cells(NyPlade + I, 2), Cells(NyPlade + I, 10))
If IsNumeric(NR) Then
  Rcount(I) = Rcount(I) + 1
End If
Next
Next
    If Rcount(0) < 5 And Rcount(1) > 5 Then Fra = 1: Til = 0: GoTo FlytPlads
    If Rcount(0) < 5 And Rcount(2) > 5 Then Fra = 2: Til = 0: GoTo FlytPlads
    If Rcount(1) < 5 And Rcount(0) > 5 Then Fra = 0: Til = 1: GoTo FlytPlads
    If Rcount(1) < 5 And Rcount(2) > 5 Then Fra = 2: Til = 1: GoTo FlytPlads
    If Rcount(2) < 5 And Rcount(0) > 5 Then Fra = 0: Til = 2: GoTo FlytPlads
    If Rcount(2) < 5 And Rcount(1) > 5 Then Fra = 1: Til = 2: GoTo FlytPlads
  GoTo AltOk
 
FlytPlads:
  For Iv = 2 To 10
    If IsNumeric(Cells(NyPlade + Fra, Iv)) Then  ' rækken med mere end 5
    If Cells(NyPlade + Til, Iv) = BlankFeltTekst Then  'rækken med mindre end 5 og skal være blank
     
      Cells(NyPlade + Til, Iv) = Cells(NyPlade + Fra, Iv)  ' flytter række
      Cells(NyPlade + Fra, Iv) = BlankFeltTekst    ' skriver blank tekst
       
      Cells(NyPlade + Til, Iv).Font.Size = StorTekst  ' ændrer skriftstørrelse
      Cells(NyPlade + Fra, Iv).Font.Size = LilleTekst  ' ændrer skriftstørrelse på blank
    GoTo TjekIgen
 
    End If
  End If
  Next
GoTo TjekIgen
'**************************** sortering lodret stigende **************
AltOk:
For v = 2 To 10
  For I = 1 To 3
  If Cells(I + (NyPlade - 1), v).Font.Size = LilleTekst Then GoTo Tekst1
 
    For Iv = 1 To 2
    If Cells(Iv + (NyPlade - 1), v).Font.Size = LilleTekst Then GoTo Tekst2
      If Cells(I + (NyPlade - 1), v) < Cells(Iv + (NyPlade - 1), v) Then
        temp = Cells(I + (NyPlade - 1), v)
        Cells(I + (NyPlade - 1), v) = Cells(Iv + (NyPlade - 1), v)
        Cells(Iv + (NyPlade - 1), v) = temp
    End If
Tekst2:
    Next Iv
Tekst1:
  Next I
  Next
 
'**************************** sortering slut **************

    If Sideskift = 5 Then
        Sideskift = 0
        NyPlade = NyPlade + 5
        Else
        NyPlade = NyPlade + 4
        End If
    R = 1
Next ny
  Application.ScreenUpdating = True
End Sub
Avatar billede bak Seniormester
17. december 2003 - 08:59 #7
Hurtigere ?? Jeg når dårlig nok at se når den laver 50 :-)
Flot, kabbak...

lige en ting, der ikke påvirker hastigen synderligt
Disse linier kan alle erstattes af een:

Selection.Borders(xlEdgeLeft).LineStyle = xlContinuous
Selection.Borders(xlEdgeTop).LineStyle = xlContinuous
Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
Selection.Borders(xlEdgeRight).LineStyle = xlContinuous
Selection.Borders(xlInsideVertical).LineStyle = xlContinuous
Selection.Borders(xlInsideHorizontal).LineStyle = xlContinuous

Nemlig:
Selection.Borders.LineStyle = xlContinuous
Avatar billede janvogt Praktikant
17. december 2003 - 09:58 #8
Jeg kan kun give bak ret - flot arbejde!
Selvom reglerne for en bankoplade er forholdsvis simple, kan man hurtigt regne ud, at det hurtigt bliver kompliceret.
Jeg har faktisk set programmer, som laver et A4-ark med 6 plader, hvor samtlige 90 tal forekommer én gang.

Har jeg ret i, at jeg kan udvide området

  A = Int(Rnd * 9) + 1 ' Randum fordeling
'****************************** Tilpasser Antal på pladen ****************
Select Case A
  Case 1
    R1 = Array(2, 1, 2, 1, 3, 2, 2, 1, 1)

med flere arrays, så det f.eks. også er muligt, at der kan forekomme 3 tal på en plade mellem 20 og 29?
Avatar billede kabbak Professor
17. december 2003 - 10:10 #9
Ja i øjeblikket, men den kan jo udbygges med en random kolonne placering.

ligesom  rækkeplaceringen her

For I = 1 To 3 ' antal rækker
   
Start1:
      U = Int(Rnd * 3) + 1 'tilfældig placering på række
  UU(I) = U
    For Y = 1 To I - 1
      If UU(Y) = U Then GoTo Start1
    Next Y

Bare med kolnner, så ved man ikke hvilken kolonne sen skriver i
Avatar billede janvogt Praktikant
17. december 2003 - 10:23 #10
Hvordan vil koden så se ud?
Tanken om, at det er totalt tilfældigt tiltaler mig :-)
Jeg har set en beregning som siger, at der skulle være 3.669688.706217.187500 (3 trilliareder) kombinationsmuligheder, eller nok til, at alle mennesker på jorden kan få ca. 500 millioner forskellige plader hver.
Avatar billede kabbak Professor
17. december 2003 - 11:58 #11
jeg ser på det i aften.
Avatar billede kabbak Professor
17. december 2003 - 12:21 #12
er lavet

Public Sub BingoPlader()
Dim C(3) As Variant, UU(3) As Integer, X As Variant, U As Integer, I As Integer, Lille As Variant, Stor As Variant
Dim NyPlade As Integer, Rcount(2) As Integer, Kol(9) As Integer
Randomize
LilleTekst = 10          ' ret Font Size her for lille skrift
StorTekst = 24            ' ret Font Size her for stor skrift
BlankFeltTekst = "kabbak" ' ret blank felt tekst her
Kantfarve = 40            'Ret kantfarver her

Columns("A:K").Clear
Q = InputBox("indtast antal plader", "Antal plader", 1) ' antal plader, 5 på hvert A4 ark
Application.ScreenUpdating = False                ' slår skærm opdateringen fra
    Lille = Array(1, 10, 20, 30, 40, 50, 60, 70, 80) ' mindste værdier
    Stor = Array(9, 19, 29, 39, 49, 59, 69, 79, 90)  ' største værdier
      NyPlade = 2
    R = 1
    t = 0

    '****************************** Tilpasser pladen på arket ****************
   
      Columns("B:J").ColumnWidth = 8
      Range("K:K,A:A").Select
      Range("A1").ColumnWidth = 2
      Selection.ColumnWidth = 2
      Rows("1:1").RowHeight = 12
      Range(Cells(1, 1), Cells(1, 11)).Interior.ColorIndex = Kantfarve
      Sideskift = 0
            For I = 1 To Q
            Sideskift = Sideskift + 1
          Range(Cells(NyPlade, 2), Cells(NyPlade + 2, 10)).Font.Size = StorTekst
          Rows(NyPlade & ":" & NyPlade + 2).RowHeight = 39.75
        Range(Cells(NyPlade, 2), Cells(NyPlade + 2, 10)).Select
          Selection.Borders.LineStyle = xlContinuous
          With Selection
          .HorizontalAlignment = xlCenter
          .VerticalAlignment = xlCenter
        End With
          Rows(NyPlade + 3).RowHeight = 20
          Range(Cells(NyPlade + 3, 1), Cells(NyPlade + 3, 11)).Interior.ColorIndex = Kantfarve
       
        If Sideskift = 5 Then
          If I = Q Then
              NyPlade = NyPlade + 4
            Else
              Sideskift = 0
              Rows(NyPlade + 4).RowHeight = 20
              Range(Cells(NyPlade + 4, 1), Cells(NyPlade + 4, 11)).Interior.ColorIndex = Kantfarve
              NyPlade = NyPlade + 5
        End If
        Else
        NyPlade = NyPlade + 4
        End If
        Next
        Range(Cells(1, 1), Cells(NyPlade - 1, 1)).Interior.ColorIndex = Kantfarve
        Range(Cells(1, 11), Cells(NyPlade - 1, 11)).Interior.ColorIndex = Kantfarve
    Range("A1").Select
  '*********************************** Tilpasser pladen slut ****************
  NyPlade = 2
  Sideskift = 0
  For ny = 1 To Q
  Sideskift = Sideskift + 1
  A = Int(Rnd * 9) + 1 ' Randum fordeling
'****************************** Tilpasser Antal på pladen ****************
Select Case A
  Case 1
    R1 = Array(2, 1, 2, 1, 3, 2, 2, 1, 1)
  Case 2
    R1 = Array(1, 1, 3, 2, 1, 1, 2, 3, 1)
  Case 3
    R1 = Array(1, 2, 1, 3, 1, 2, 1, 2, 2)
  Case 4
    R1 = Array(2, 2, 1, 1, 1, 1, 3, 2, 2)
    Case 5
    R1 = Array(1, 2, 2, 1, 3, 2, 2, 1, 1)
    Case 6
    R1 = Array(3, 2, 1, 2, 2, 2, 1, 1, 1)
    Case 7
    R1 = Array(1, 2, 2, 2, 1, 3, 1, 1, 2)
    Case 8
    R1 = Array(3, 1, 2, 2, 1, 1, 2, 1, 2)
    Case 9
    R1 = Array(1, 2, 1, 1, 2, 1, 1, 3, 3)
  End Select
    '****************************** Tilpasser Antal slut ****************
   
   
For t = 1 To 9 ' 9 kolonner
KOL1:
      UK = Int(Rnd * 9) + 1 'tilfældig placering på Kolonner
  Kol(t) = UK
    For Y = 1 To t - 1
      If Kol(Y) = UK Then GoTo KOL1
    Next Y
  R = UK + 1
 
    For I = 1 To 3 ' antal rækker
   
Start1:
      U = Int(Rnd * 3) + 1 'tilfældig placering på række
  UU(I) = U
    For Y = 1 To I - 1
      If UU(Y) = U Then GoTo Start1
    Next Y
Start2:
        X = Int((Rnd() * (Stor(UK - 1) - Lille(UK - 1) + 1) + Lille(UK - 1)))
          If U > R1(UK - 1) Then
            Cells(I + (NyPlade - 1), R).Font.Size = LilleTekst ' ændre tekststørrelsen på bart felt
          Cells(I + (NyPlade - 1), R) = BlankFeltTekst ' bart felt
          GoTo BarFelt
        End If
 
  For Y = 1 To I - 1
      If C(Y) = X Then GoTo Start2
    Next Y
  C(Y) = X
  Cells(I + (NyPlade - 1), R) = X
 
BarFelt:
  Next I
Next t
    '**************************** sortering 5 i hver række **************
TjekIgen:

For I = 0 To 2
Rcount(I) = 0
For Each NR In Range(Cells(NyPlade + I, 2), Cells(NyPlade + I, 10))
If IsNumeric(NR) Then
  Rcount(I) = Rcount(I) + 1
End If
Next
Next
    If Rcount(0) < 5 And Rcount(1) > 5 Then Fra = 1: Til = 0: GoTo FlytPlads
    If Rcount(0) < 5 And Rcount(2) > 5 Then Fra = 2: Til = 0: GoTo FlytPlads
    If Rcount(1) < 5 And Rcount(0) > 5 Then Fra = 0: Til = 1: GoTo FlytPlads
    If Rcount(1) < 5 And Rcount(2) > 5 Then Fra = 2: Til = 1: GoTo FlytPlads
    If Rcount(2) < 5 And Rcount(0) > 5 Then Fra = 0: Til = 2: GoTo FlytPlads
    If Rcount(2) < 5 And Rcount(1) > 5 Then Fra = 1: Til = 2: GoTo FlytPlads
  GoTo AltOk
 
FlytPlads:
  For Iv = 2 To 10
    If IsNumeric(Cells(NyPlade + Fra, Iv)) Then  ' rækken med mere end 5
    If Cells(NyPlade + Til, Iv) = BlankFeltTekst Then  'rækken med mindre end 5 og skal være blank
     
      Cells(NyPlade + Til, Iv) = Cells(NyPlade + Fra, Iv)  ' flytter række
      Cells(NyPlade + Fra, Iv) = BlankFeltTekst    ' skriver blank tekst
       
      Cells(NyPlade + Til, Iv).Font.Size = StorTekst  ' ændrer skriftstørrelse
      Cells(NyPlade + Fra, Iv).Font.Size = LilleTekst  ' ændrer skriftstørrelse på blank
    GoTo TjekIgen
 
    End If
  End If
  Next
GoTo TjekIgen
'**************************** sortering lodret stigende **************
AltOk:
For v = 2 To 10
  For I = 1 To 3
  If Cells(I + (NyPlade - 1), v).Font.Size = LilleTekst Then GoTo Tekst1
 
    For Iv = 1 To 2
    If Cells(Iv + (NyPlade - 1), v).Font.Size = LilleTekst Then GoTo Tekst2
      If Cells(I + (NyPlade - 1), v) < Cells(Iv + (NyPlade - 1), v) Then
        temp = Cells(I + (NyPlade - 1), v)
        Cells(I + (NyPlade - 1), v) = Cells(Iv + (NyPlade - 1), v)
        Cells(Iv + (NyPlade - 1), v) = temp
    End If
Tekst2:
    Next Iv
Tekst1:
  Next I
  Next
 
'**************************** sortering slut **************

    If Sideskift = 5 Then
        Sideskift = 0
        NyPlade = NyPlade + 5
        Else
        NyPlade = NyPlade + 4
        End If
    R = 1
Next ny
  Application.ScreenUpdating = True
End Sub
Avatar billede janvogt Praktikant
17. december 2003 - 12:52 #13
Mange tak. Nu er vi vist ved at være der.

Man burde vel så kunne fjerne Case A - afsnittet?
Avatar billede janvogt Praktikant
17. december 2003 - 13:54 #14
Ser ud til, at den stadig bruger array-afsnittet.
Avatar billede kabbak Professor
17. december 2003 - 14:39 #15
Det gør den, men den vælger tilfældig inde i array

eks:
R1 = Array(2, 1, 2, 1, 3, 2, 2, 1, 1)
Kolonne 3,5,1,9,7,2,6,8,4
og ved næste plade måske
Kolonne 4,8,6,2,7,9,1,5,3
Avatar billede janvogt Praktikant
17. december 2003 - 14:47 #16
Jeg synes nu jeg stadig kun får en af de 9 opstillinger.
Så det kan stadig ikke lade sig gøre at få 3 tal mellem 10 og 19 på en plade.
Avatar billede janvogt Praktikant
17. december 2003 - 15:09 #17
Hvis den fordeler dem tilfældigt på kolonnerne, er der så vidt jeg kan se kun behov for 4 kombinationsmuligheder:
3    3    3    1    1    1    1    1    1
3    3    2    2    1    1    1    1    1
3    2    2    2    2    1    1    1    1
2    2    2    2    2    2    1    1    1
Avatar billede kabbak Professor
17. december 2003 - 16:30 #18
nu har jeg haft 3 tal i alle kolonner, mon ikke så det dur.

Public Sub BingoPlader()
Dim C(3) As Variant, UU(3) As Integer, X As Variant, U As Integer, I As Integer, Lille As Variant, Stor As Variant
Dim NyPlade As Integer, Rcount(2) As Integer, Kol(8) As Integer
Randomize
LilleTekst = 10          ' ret Font Size her for lille skrift
StorTekst = 24            ' ret Font Size her for stor skrift
BlankFeltTekst = "kabbak" ' ret blank felt tekst her
Kantfarve = 40            'Ret kantfarver her

Columns("A:K").Clear
Q = InputBox("indtast antal plader", "Antal plader", 1) ' antal plader, 5 på hvert A4 ark
Application.ScreenUpdating = False                ' slår skærm opdateringen fra
    Lille = Array(1, 10, 20, 30, 40, 50, 60, 70, 80) ' mindste værdier
    Stor = Array(9, 19, 29, 39, 49, 59, 69, 79, 90)  ' største værdier
      NyPlade = 2
    R = 1
    T = 0

    '****************************** Tilpasser pladen på arket ****************
   
      Columns("B:J").ColumnWidth = 8
      Range("K:K,A:A").Select
      Range("A1").ColumnWidth = 2
      Selection.ColumnWidth = 2
      Rows("1:1").RowHeight = 12
      Range(Cells(1, 1), Cells(1, 11)).Interior.ColorIndex = Kantfarve
      Sideskift = 0
            For I = 1 To Q
            Sideskift = Sideskift + 1
          Range(Cells(NyPlade, 2), Cells(NyPlade + 2, 10)).Font.Size = StorTekst
          Rows(NyPlade & ":" & NyPlade + 2).RowHeight = 39.75
        Range(Cells(NyPlade, 2), Cells(NyPlade + 2, 10)).Select
          Selection.Borders.LineStyle = xlContinuous
          With Selection
          .HorizontalAlignment = xlCenter
          .VerticalAlignment = xlCenter
        End With
          Rows(NyPlade + 3).RowHeight = 20
          Range(Cells(NyPlade + 3, 1), Cells(NyPlade + 3, 11)).Interior.ColorIndex = Kantfarve
       
        If Sideskift = 5 Then
          If I = Q Then
              NyPlade = NyPlade + 4
            Else
              Sideskift = 0
              Rows(NyPlade + 4).RowHeight = 20
              Range(Cells(NyPlade + 4, 1), Cells(NyPlade + 4, 11)).Interior.ColorIndex = Kantfarve
              NyPlade = NyPlade + 5
        End If
        Else
        NyPlade = NyPlade + 4
        End If
        Next
        Range(Cells(1, 1), Cells(NyPlade - 1, 1)).Interior.ColorIndex = Kantfarve
        Range(Cells(1, 11), Cells(NyPlade - 1, 11)).Interior.ColorIndex = Kantfarve
    Range("A1").Select
  '*********************************** Tilpasser pladen slut ****************
  NyPlade = 2
  Sideskift = 0
  For ny = 1 To Q
  Sideskift = Sideskift + 1
  A = Int(Rnd * 9) + 1 ' Randum fordeling
'****************************** Tilpasser Antal på pladen ****************
Select Case A
  Case 1
    R1 = Array(2, 1, 2, 1, 3, 2, 2, 1, 1)
  Case 2
    R1 = Array(1, 1, 3, 2, 1, 1, 2, 3, 1)
  Case 3
    R1 = Array(1, 2, 1, 3, 1, 2, 1, 2, 2)
  Case 4
    R1 = Array(2, 2, 1, 1, 1, 1, 3, 2, 2)
    Case 5
    R1 = Array(1, 2, 2, 1, 3, 2, 2, 1, 1)
    Case 6
    R1 = Array(3, 2, 1, 2, 2, 2, 1, 1, 1)
    Case 7
    R1 = Array(1, 2, 2, 2, 1, 3, 1, 1, 2)
    Case 8
    R1 = Array(3, 1, 2, 2, 1, 1, 2, 1, 2)
    Case 9
    R1 = Array(1, 2, 1, 1, 2, 1, 1, 3, 3)
  End Select
    '****************************** Tilpasser Antal slut ****************
    '****************************** Blanding  start ****************
    For T = 0 To 8 ' 9 kolonner
KOL1:
      UK = Int(Rnd * 9) + 1 'tilfældig placering på Kolonner
  Kol(T) = UK - 1
    For Y = 0 To T - 1
      If Kol(Y) = UK - 1 Then GoTo KOL1
    Next Y
Next T
        '****************************** Blanding ****************
   
For T = 0 To 8 ' 9 kolonner
  R = R + 1
    For I = 1 To 3 ' antal rækker
   
Start1:
      U = Int(Rnd * 3) + 1 'tilfældig placering på række
  UU(I) = U
    For Y = 1 To I - 1
      If UU(Y) = U Then GoTo Start1
    Next Y
Start2:
        X = Int((Rnd() * (Stor(T) - Lille(T) + 1) + Lille(T)))
          If U > R1(Kol(T)) Then
            Cells(I + (NyPlade - 1), R).Font.Size = LilleTekst ' ændre tekststørrelsen på bart felt
          Cells(I + (NyPlade - 1), R) = BlankFeltTekst ' bart felt
          GoTo BarFelt
        End If
 
  For Y = 1 To I - 1
      If C(Y) = X Then GoTo Start2
    Next Y
  C(Y) = X
  Cells(I + (NyPlade - 1), R) = X
 
BarFelt:
  Next I
Next T
    '**************************** sortering 5 i hver række **************
TjekIgen:

For I = 0 To 2
Rcount(I) = 0
For Each NR In Range(Cells(NyPlade + I, 2), Cells(NyPlade + I, 10))
If IsNumeric(NR) Then
  Rcount(I) = Rcount(I) + 1
End If
Next
Next
    If Rcount(0) < 5 And Rcount(1) > 5 Then Fra = 1: Til = 0: GoTo FlytPlads
    If Rcount(0) < 5 And Rcount(2) > 5 Then Fra = 2: Til = 0: GoTo FlytPlads
    If Rcount(1) < 5 And Rcount(0) > 5 Then Fra = 0: Til = 1: GoTo FlytPlads
    If Rcount(1) < 5 And Rcount(2) > 5 Then Fra = 2: Til = 1: GoTo FlytPlads
    If Rcount(2) < 5 And Rcount(0) > 5 Then Fra = 0: Til = 2: GoTo FlytPlads
    If Rcount(2) < 5 And Rcount(1) > 5 Then Fra = 1: Til = 2: GoTo FlytPlads
  GoTo AltOk
 
FlytPlads:
  For Iv = 2 To 10
    If IsNumeric(Cells(NyPlade + Fra, Iv)) Then  ' rækken med mere end 5
    If Cells(NyPlade + Til, Iv) = BlankFeltTekst Then  'rækken med mindre end 5 og skal være blank
     
      Cells(NyPlade + Til, Iv) = Cells(NyPlade + Fra, Iv)  ' flytter række
      Cells(NyPlade + Fra, Iv) = BlankFeltTekst    ' skriver blank tekst
       
      Cells(NyPlade + Til, Iv).Font.Size = StorTekst  ' ændrer skriftstørrelse
      Cells(NyPlade + Fra, Iv).Font.Size = LilleTekst  ' ændrer skriftstørrelse på blank
    GoTo TjekIgen
 
    End If
  End If
  Next
GoTo TjekIgen
'**************************** sortering lodret stigende **************
AltOk:
For v = 2 To 10
  For I = 1 To 3
  If Cells(I + (NyPlade - 1), v).Font.Size = LilleTekst Then GoTo Tekst1
 
    For Iv = 1 To 2
    If Cells(Iv + (NyPlade - 1), v).Font.Size = LilleTekst Then GoTo Tekst2
      If Cells(I + (NyPlade - 1), v) < Cells(Iv + (NyPlade - 1), v) Then
        temp = Cells(I + (NyPlade - 1), v)
        Cells(I + (NyPlade - 1), v) = Cells(Iv + (NyPlade - 1), v)
        Cells(Iv + (NyPlade - 1), v) = temp
    End If
Tekst2:
    Next Iv
Tekst1:
  Next I
  Next
 
'**************************** sortering slut **************

    If Sideskift = 5 Then
        Sideskift = 0
        NyPlade = NyPlade + 5
        Else
        NyPlade = NyPlade + 4
        End If
    R = 1
Next ny
  Application.ScreenUpdating = True
End Sub
Avatar billede Slettet bruger
18. december 2003 - 02:33 #19
Hvis du vil have "ægte" random tal kan du lave en web-query med:
http://www.random.org/cgi-bin/randnum?num=10&min=1&max=3&col=1

til at returnere 10 tilfældige tal mellem 1 og 3.

www.random.org genererer tilfældige tal på baggrund af radiostøj.
Avatar billede kabbak Professor
18. december 2003 - 08:10 #20
ja det ville jo være dejligt, men jeg kan ikke lige overskue hvordan jeg styrer antallet af tal, der må jo kun være 15, det er derfor jeg bruger Case sætningen.
Avatar billede Slettet bruger
18. december 2003 - 08:59 #21
Der er en vejledning her:
http://www.random.org/http.html

under "Randnum" CGI scriptet.
Avatar billede janvogt Praktikant
18. december 2003 - 09:27 #22
Det er stadig ikke helt tilfældigt. Jeg beklager min stædighed, men hvis det kan lade sig gøre, at lave det helt tilfældigt, kan vi lige så godt lave det.

Der er stadig tilladte kombinationer, som koden aldrig vil generere.
F.eks. vil der aldrig være 3 kolonner med 3 tal eller en plade uden en kolonne med 3 tal.

Jeg har prøvet at erstatte de 9 "Cases" med de 4 teoretisk mulige, altså:
A = Int(Rnd * 4) + 1 ' Randum fordeling
Select Case A
  Case 1
    R1 = Array(3, 3, 3, 1, 1, 1, 1, 1, 1)
  Case 2
    R1 = Array(3, 3, 2, 2, 1, 1, 1, 1, 1)
  Case 3
    R1 = Array(3, 2, 2, 2, 2, 1, 1, 1, 1)
  Case 4
    R1 = Array(2, 2, 2, 2, 2, 2, 1, 1, 1)
  End Select

På denne måde vil alle kombinationer kunne forekomme, men der vil være et forkert forhold mellem dem, f.eks. vil der forekomme 25% af plader med 3 kolonner med 3 tal, hvilket er alt for meget.

Jeg har regnet ud, at der er 1554 kombinationsmuligheder af de 4 cases.
Sandsynlighed for Case 1 udgør 84 / 1554 = 5,41%
Sandsynlighed for Case 2 udgør 756 / 1554 = 48,65%
Sandsynlighed for Case 3 udgør 630 / 1554 = 40,54%
Sandsynlighed for Case 4 udgør 84 / 1554 = 5,41%

Hvordan får jeg disse forhold indarbejdet i koden?
Avatar billede kabbak Professor
18. december 2003 - 09:35 #23
Janvogt >> Du sætter dem bare ind i stedet for mine 9 case.

Husk at lave
A = Int(Rnd * 9) + 1 ' Randum fordeling
om til
A = Int(Rnd * 4) + 1 ' Randum fordeling

Med det sidste jeg lavede i går, skulle den køre som du vil
Avatar billede janvogt Praktikant
18. december 2003 - 10:10 #24
Ja, det har jeg også gjort, som du ser af ovenstående, men de 4 procentfordelinger skulle gerne lægges på hver case.
Avatar billede kabbak Professor
18. december 2003 - 10:19 #25
Lav en

( sæt 1,2,3 og 4 taller ind 'Fordeling =Array(' efter fordelings%, min fordeling er bare for at vise det

A = Int(Rnd * Antal i Array) + 1 ' Randum fordeling
  Fordeling = Array(1, 1,2, 2, 2,2, 3,3, 3, 3, 4,4)

Select Case Fordeling(A)
Case 1
    R1 = Array(3, 3, 3, 1, 1, 1, 1, 1, 1)
  Case 2
    R1 = Array(3, 3, 2, 2, 1, 1, 1, 1, 1)
  Case 3
    R1 = Array(3, 2, 2, 2, 2, 1, 1, 1, 1)
  Case 4
    R1 = Array(2, 2, 2, 2, 2, 2, 1, 1, 1)
  End Select
Avatar billede kabbak Professor
18. december 2003 - 10:23 #26
nå der smuttede noget.

A = Int(Rnd * Antal i Array) + 1 ' Randum fordeling

Antal i Array, skal være det antal tal du sætter ind i arrayet
Avatar billede janvogt Praktikant
18. december 2003 - 10:46 #27
Ikke forstået.
Avatar billede janvogt Praktikant
18. december 2003 - 10:55 #28
Som det er med koden:
A = Int(Rnd * 4) + 1 ' Randum fordeling
Select Case A
  Case 1
    R1 = Array(3, 3, 3, 1, 1, 1, 1, 1, 1)
  Case 2
    R1 = Array(3, 3, 2, 2, 1, 1, 1, 1, 1)
  Case 3
    R1 = Array(3, 2, 2, 2, 2, 1, 1, 1, 1)
  Case 4
    R1 = Array(2, 2, 2, 2, 2, 2, 1, 1, 1)
  End Select

vil der være 25% chance for hver enkelt case. Det skal der ikke være.

Case 1 skal komme i 84 ud af 1554 = 5,41%
Case 2 skal komme i 756 ud af 1554 = 48,65%
Case 3 skal komme i 630 ud af 1554 = 40,54%
Case 4 skal komme i 84 ud af 1554 = 5,41%
Avatar billede janvogt Praktikant
18. december 2003 - 11:38 #29
Denne skulle vist klare den:

  Ford = Int(Rnd * 1554) + 1 ' Random fordeling
  If Ford < 84 + 756 + 630 + 84 Then a = 4
  If Ford < 84 + 756 + 630 Then a = 3
  If Ford < 84 + 756 Then a = 2
  If Ford < 84 Then a = 1
   
  Select Case a
    Case 1
    R1 = Array(3, 3, 3, 1, 1, 1, 1, 1, 1)
    Case 2
    R1 = Array(3, 3, 2, 2, 1, 1, 1, 1, 1)
    Case 3
    R1 = Array(3, 2, 2, 2, 2, 1, 1, 1, 1)
    Case 4
    R1 = Array(2, 2, 2, 2, 2, 2, 1, 1, 1)
  End Select
Avatar billede laurbjerg Nybegynder
18. december 2003 - 12:37 #30
Er det muligt at få den endelig kode at se, når alle de udmærkede rettelser er blevet tastet ind ?
Avatar billede janvogt Praktikant
18. december 2003 - 12:53 #31
Jo da:

Public Sub BingoPlader()
Dim C(3) As Variant, UU(3) As Integer, X As Variant, U As Integer, I As Integer, Lille As Variant, Stor As Variant
Dim NyPlade As Integer, Rcount(2) As Integer, Kol(8) As Integer
Randomize
LilleTekst = 6            ' ret Font Size her for lille skrift
StorTekst = 24            ' ret Font Size her for stor skrift
BlankFeltTekst = "IM"    ' ret blank felt tekst her
Kantfarve = 40            ' ret kantfarver her

Columns("A:K").Clear
Q = InputBox("indtast antal plader", "Antal plader", 1) ' antal plader, 5 på hvert A4 ark
Application.ScreenUpdating = False                ' slår skærm opdateringen fra
    Lille = Array(1, 10, 20, 30, 40, 50, 60, 70, 80) ' mindste værdier
    Stor = Array(9, 19, 29, 39, 49, 59, 69, 79, 90)  ' største værdier
      NyPlade = 2
    R = 1
    T = 0

    '****************************** Tilpasser pladen på arket ****************
   
      Columns("B:J").ColumnWidth = 8
      Range("K:K,A:A").Select
      Range("A1").ColumnWidth = 2
      Selection.ColumnWidth = 2
      Rows("1:1").RowHeight = 12
      Range(Cells(1, 1), Cells(1, 11)).Interior.ColorIndex = Kantfarve
      Sideskift = 0
            For I = 1 To Q
            Sideskift = Sideskift + 1
          Range(Cells(NyPlade, 2), Cells(NyPlade + 2, 10)).Font.Size = StorTekst
          Rows(NyPlade & ":" & NyPlade + 2).RowHeight = 39.75
        Range(Cells(NyPlade, 2), Cells(NyPlade + 2, 10)).Select
          Selection.Borders.LineStyle = xlContinuous
          With Selection
          .HorizontalAlignment = xlCenter
          .VerticalAlignment = xlCenter
        End With
          Rows(NyPlade + 3).RowHeight = 20
          Range(Cells(NyPlade + 3, 1), Cells(NyPlade + 3, 11)).Interior.ColorIndex = Kantfarve
       
        If Sideskift = 5 Then
          If I = Q Then
              NyPlade = NyPlade + 4
            Else
              Sideskift = 0
              Rows(NyPlade + 4).RowHeight = 20
              Range(Cells(NyPlade + 4, 1), Cells(NyPlade + 4, 11)).Interior.ColorIndex = Kantfarve
              NyPlade = NyPlade + 5
        End If
        Else
        NyPlade = NyPlade + 4
        End If
        Next
        Range(Cells(1, 1), Cells(NyPlade - 1, 1)).Interior.ColorIndex = Kantfarve
        Range(Cells(1, 11), Cells(NyPlade - 1, 11)).Interior.ColorIndex = Kantfarve
    Range("A1").Select
  '*********************************** Tilpasser pladen slut ****************
  NyPlade = 2
  Sideskift = 0
  For ny = 1 To Q
  Sideskift = Sideskift + 1
 
    '****************************** Tilpasser Antal på pladen ****************
    ' De 4 fordelingsmuligheder har forskellige sandsynligheder
    ' De kan placeres på 1554 forskellige måder
   
  Ford = Int(Rnd * 1554) + 1 ' Random fordeling
  If Ford < 84 + 756 + 630 + 84 Then a = 4
  If Ford < 84 + 756 + 630 Then a = 3
  If Ford < 84 + 756 Then a = 2
  If Ford < 84 Then a = 1
   
  Select Case a
    Case 1
    R1 = Array(3, 3, 3, 1, 1, 1, 1, 1, 1)
    Case 2
    R1 = Array(3, 3, 2, 2, 1, 1, 1, 1, 1)
    Case 3
    R1 = Array(3, 2, 2, 2, 2, 1, 1, 1, 1)
    Case 4
    R1 = Array(2, 2, 2, 2, 2, 2, 1, 1, 1)
  End Select
    '****************************** Blanding  start ****************
    For T = 0 To 8 ' 9 kolonner
KOL1:
      UK = Int(Rnd * 9) + 1 'tilfældig placering på Kolonner
  Kol(T) = UK - 1
    For Y = 0 To T - 1
      If Kol(Y) = UK - 1 Then GoTo KOL1
    Next Y
Next T
    '****************************** Blanding ****************
   
For T = 0 To 8 ' 9 kolonner
  R = R + 1
    For I = 1 To 3 ' antal rækker
   
Start1:
      U = Int(Rnd * 3) + 1 'tilfældig placering på række
  UU(I) = U
    For Y = 1 To I - 1
      If UU(Y) = U Then GoTo Start1
    Next Y
Start2:
        X = Int((Rnd() * (Stor(T) - Lille(T) + 1) + Lille(T)))
          If U > R1(Kol(T)) Then
            Cells(I + (NyPlade - 1), R).Font.Size = LilleTekst ' ændre tekststørrelsen på bart felt
          Cells(I + (NyPlade - 1), R) = BlankFeltTekst ' bart felt
          GoTo BarFelt
        End If
 
  For Y = 1 To I - 1
      If C(Y) = X Then GoTo Start2
    Next Y
  C(Y) = X
  Cells(I + (NyPlade - 1), R) = X
 
BarFelt:
  Next I
Next T
    '**************************** sortering 5 i hver række **************
TjekIgen:

For I = 0 To 2
Rcount(I) = 0
For Each NR In Range(Cells(NyPlade + I, 2), Cells(NyPlade + I, 10))
If IsNumeric(NR) Then
  Rcount(I) = Rcount(I) + 1
End If
Next
Next
    If Rcount(0) < 5 And Rcount(1) > 5 Then Fra = 1: Til = 0: GoTo FlytPlads
    If Rcount(0) < 5 And Rcount(2) > 5 Then Fra = 2: Til = 0: GoTo FlytPlads
    If Rcount(1) < 5 And Rcount(0) > 5 Then Fra = 0: Til = 1: GoTo FlytPlads
    If Rcount(1) < 5 And Rcount(2) > 5 Then Fra = 2: Til = 1: GoTo FlytPlads
    If Rcount(2) < 5 And Rcount(0) > 5 Then Fra = 0: Til = 2: GoTo FlytPlads
    If Rcount(2) < 5 And Rcount(1) > 5 Then Fra = 1: Til = 2: GoTo FlytPlads
  GoTo AltOk
 
FlytPlads:
  For Iv = 2 To 10
    If IsNumeric(Cells(NyPlade + Fra, Iv)) Then  ' rækken med mere end 5
    If Cells(NyPlade + Til, Iv) = BlankFeltTekst Then  'rækken med mindre end 5 og skal være blank
     
      Cells(NyPlade + Til, Iv) = Cells(NyPlade + Fra, Iv)  ' flytter række
      Cells(NyPlade + Fra, Iv) = BlankFeltTekst    ' skriver blank tekst
       
      Cells(NyPlade + Til, Iv).Font.Size = StorTekst  ' ændrer skriftstørrelse
      Cells(NyPlade + Fra, Iv).Font.Size = LilleTekst  ' ændrer skriftstørrelse på blank
    GoTo TjekIgen
 
    End If
  End If
  Next
GoTo TjekIgen
'**************************** sortering lodret stigende **************
AltOk:
For v = 2 To 10
  For I = 1 To 3
  If Cells(I + (NyPlade - 1), v).Font.Size = LilleTekst Then GoTo Tekst1
 
    For Iv = 1 To 2
    If Cells(Iv + (NyPlade - 1), v).Font.Size = LilleTekst Then GoTo Tekst2
      If Cells(I + (NyPlade - 1), v) < Cells(Iv + (NyPlade - 1), v) Then
        temp = Cells(I + (NyPlade - 1), v)
        Cells(I + (NyPlade - 1), v) = Cells(Iv + (NyPlade - 1), v)
        Cells(Iv + (NyPlade - 1), v) = temp
    End If
Tekst2:
    Next Iv
Tekst1:
  Next I
  Next
 
'**************************** sortering slut **************

    If Sideskift = 5 Then
        Sideskift = 0
        NyPlade = NyPlade + 5
        Else
        NyPlade = NyPlade + 4
        End If
    R = 1
Next ny
  Application.ScreenUpdating = True
End Sub
Avatar billede laurbjerg Nybegynder
18. december 2003 - 13:04 #32
Jeg takker og er meget imponeret !
Avatar billede janvogt Praktikant
18. december 2003 - 13:27 #33
Også her. Flot arbejde af kabbak.
Han har fortjent hvert et point.

Jeg har imidlertid behov for at få pladerne præsenteret på en lidt anden måde.
Se http://www.eksperten.dk/spm/441442
Avatar billede kabbak Professor
18. december 2003 - 13:29 #34
tak for det ;-))
Avatar billede kabbak Professor
18. december 2003 - 23:37 #35
Ps. jeg har fået at vide at en kolonne godt kan være uden tal, så er der jo flere kombinationer.
Avatar billede janvogt Praktikant
18. december 2003 - 23:45 #36
Ser ud til, at vi blive ved :-)
Jeg prøver at finde en løsning, hvis jeg får tid.
Avatar billede janvogt Praktikant
18. december 2003 - 23:46 #37
Ser ud til, at vi kan blive ved :-)
Avatar billede janvogt Praktikant
18. december 2003 - 23:50 #38
Ifølge denne side skal der være mindst ét tal i hver kolonne
http://www.diku.dk/hjemmesider/ansatte/nils/Notes/bankoplader.html
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester