Jump to content
Sign in to follow this  
playjacob

Help with bingo card makeing program

Recommended Posts

playjacob

For the past days i've been working on a program to make bingo cards, but now i've have a problem.

The problem is that i only want 5 numbers on each row and they sould be spred randomly.

To see the final result just open up Index.html after you've run the code.

Look at the comments in the code for more info.

Global $DBFile = @ScriptDir&"\Cards.txt"
Global $NumToGenerate = 250
Global $Rnd[3]
Global $NumPrVRow = ""
Global $FillSpace[27]
Global $Row[3]
Global $Output
Global $Mats[$NumToGenerate]
Global $NumbersOnRow[3]
;Create Database File With Mats
For $i = 1 To $NumToGenerate
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $i = ' & $i & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
$a = ""
For $i2 = 0 To 26
  $FillSpace[$i2] = 0
Next
$i2 = ""
$i3 = ""
$i4 = ""
$NumPrVRow = ""
For $i2 = 0 To 2
  While 1
   $Rnd[$i2] = Random(1,9,1)
   $Continue = True
   For $i3 = 0 To $i2
    If ($Rnd[$i2] = $Rnd[$i3]) And ($i2 <> $i3) Then $Continue = False
   Next
   If $Continue = True Then ExitLoop
  WEnd
Next
For $i2=1 To 9
  $a = 2
  For $i3 = 0 To 2
   If $Rnd[$i3] = $i2 Then $a = 1
  Next
  $NumPrVRow &= $a
Next
For $i2 = 0 To 2
  $NumbersOnRow[$i2] = 0
Next
For $i2 = 1 To 9
  $OldRnd2 = ""
  For $i3 = 1 To StringMid($NumPrVRow, $i2,1)
   While 1
    $Rnd2 = Random(1,3,1)
    ;I tryed to add this line.
    $NumbersOnRow[$Rnd2-1] += 1
    $Continue = True
    For $i4 = 0 To $i2
     ;And change This
     ;If $Rnd2 = $OldRnd2  Then $Continue = False
     ;To
     If ($Rnd2 = $OldRnd2) Or ($NumbersOnRow[$Rnd2-1] > 5) Then $Continue = False
    Next
    $OldRnd2 = $Rnd2
    If $Continue = True Then ExitLoop
    ;And Then Also Add This Line:
    $NumbersOnRow[$Rnd2-1] -= 1
    ;But i still could'nt get it to work.
   WEnd
   $FillSpace[$Rnd2*9-9+$i2-1] = 1
  Next
Next
$Full = ""
For $i2 = 0 To 2
  $Row[$i2] = ""
  For $i3 = 1 To 9
   If $FillSpace[($i2+1)*9-9+$i3-1] = 1 Then
    If $i3 = 1 Then
     $Row[$i2] &= Random(1,9,1)&";"
    Else
     $Rnd3 = Random($i3&0,$i3&9,1)
     $Row[$i2] &= $Rnd3-10&";"
    EndIf
   Else
    $Row[$i2] &= ";"
   EndIf
  Next
  IniWrite($DBFile, $i, $i2+1, StringTrimRight($Row[$i2],1))
  $Full &= $Row[$i2]
Next
IniWrite($DBFile, $i, "f", $Full)
Next
$Start = '<html>'&@CRLF&'<head>'&@CRLF&'<style type=text/css>'&@CRLF&'    body { font-family: Verdana, Arial, Helvetica;}'&@CRLF&'    tr { text-align: center; }'&@CRLF&'    .c { padding-top: 35px; padding-bottom: 5px;'&@CRLF&'      border-bottom: 2px dashed black; }'&@CRLF&'    .s { padding-top: 5px; padding-bottom: 35px; }'&@CRLF&'    .c, .s { font-size: 8px;}'&@CRLF&'    .pb { page-break-before: always; }'&@CRLF&'    .rn { font-family: Verdana, Arial, Helvetica; font-size: 13px; border: 2px solid black;}'&@CRLF&'    .pn { font-family: Verdana, Arial, Helvetica; font-size: 18px; text-align: center;}'&@CRLF&'</style>'&@CRLF&'</head>'&@CRLF&'<body onLoad="print();">'&@CRLF&@CRLF&@CRLF
$End = @CRLF&'</body></html>'&@CRLF
$PageBreak = 1
For $i = 0 To $NumToGenerate-1
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $i = ' & $i & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
$Mats[$i] = '<div class=pn>Pladenummer: '&$i+1&'F</div>'&@CRLF&'<table width=90% border=1 cols=10 align=center cellspacing=0'&@CRLF&'style="border-collapse: collapse" cellpadding=10> <tr>'
For $i2 = 1 To 3 ;Change To ABC
  $Mats[$i] &= '<tr>'&@CRLF
  $Split = StringSplit(IniRead($DBFile, $i+1, $i2, ""),";")
  For $i3 = 1 To 9
   $Mats[$i] &= '<td>'&$Split[$i3]&'</td>'&@CRLF
  Next
  $Mats[$i] &= '<td class=rn>'&ConvertToABCAndAddDots($i+1&$i2)&'</td>'&@CRLF
  $Mats[$i] &= '</tr>'&@CRLF
Next
$Mats[$i] &= '</table><div class=c>Made using The Bingo Program by Jacob Bom Andersen</div></br>'&@CRLF
If $PageBreak = 4 Then $Mats[$i] &= '<div class=pb></div>'
$PageBreak += 1
Next
$Output = $Start
For $i = 0 To $NumToGenerate-1
$Output &= $Mats[$i]
Next
$Output &= $End
FileDelete("Index.html")
FileWrite("Index.html", $Output)
Func ConvertToABCAndAddDots($ToConvert)
$Split2 = StringSplit($ToConvert, "")
$Out = ""
For $b = 1 To $Split2[0]
  If $b = $Split2[0] Then
   $Out &= Chr($Split2[$b]+64)
  Else
   $Out &= $Split2[$b]&Chr(183)
  EndIf
Next
Return $Out
EndFunc

Ps. The Database File that it is also makeing is for an other program that i've made to play bingo, witch is then also able to check is someone has bingo.

Sorry for my bad english.

Share this post


Link to post
Share on other sites
JohnOne

To be honest, I would have to study that code for an hour to begin to see what is going on.

Only advice I can offer at this time is to make use of functions to make your code more modular, readable

and easier to debug.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
JohnQSmith

Just glancing over your code, I don't see you following the "rules" for bingo.

Here's what you need to make sure you implement.

There are 5 columns and 5 rows on each card. The columns are labeled B, I, N, G, and O. Each column can only contain a specific set of numbers.

B (1-15), I (16-30), N (31-45), G (46-60), O (61-75)

Also, the numbers in each column must be unique (you cannot have two or more of the same number on any card), but can appear in any order in their respective column.


Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Share this post


Link to post
Share on other sites
BrewManNH

@JohnQSmith

That only applies to BINGO in the US and parts of Canada, he's making cards for European BINGO games which are different. I had to look that one up myself yesterday. ;)


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
JohnQSmith

he's making cards for European BINGO games which are different

Holy crap, will ya look at that! I didn't know there were different kinds. Thanks for the info. Learned something new ;) which means it's a good day.

Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Share this post


Link to post
Share on other sites
BigDod


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • PuneetTewani
      By PuneetTewani
      Mouse click (using coordinates) not working on NSE NOW software. Works well everywhere else.
    • TheDcoder
      By TheDcoder
      Hello Guys! I wanted to share all my knowledge on arrays! Hope may enjoy the article , Lets start!
      Declaring arrays!
      Declaring arrays is a little different than other variables: 
      ; Rules to follow while declaring arrays: ; ; Rule #1: You must have a declarative keyword like Dim/Global/Local before the declaration unless the array is assigned a value from a functions return (Ex: StringSplit) ; Rule #2: You must declare the number of dimensions but not necessarily the size of the dimension if you are gonna assign the values at the time of declaration. #include <Array.au3> Local $aEmptyArray[0] ; Creates an Array with 0 elements (aka an Empty Array). Local $aArrayWithData[1] = ["Data"] _ArrayDisplay($aEmptyArray) _ArrayDisplay($aArrayWithData) That's it
      Resizing Arrays
      Its easy! Just like declaring an empty array! ReDim is our friend here:
      #include <Array.au3> Local $aArrayWithData[1] = ["Data1"] ReDim $aArrayWithData[2] ; Change the number of elements in the array, I have added an extra element! $aArrayWithData[1] = "Data2" _ArrayDisplay($aArrayWithData) Just make sure that you don't use ReDim too often (especially don't use it in loops!), it can slow down you program.
      Best practice of using "Enum"
      You might be wondering what they might be... Do you know the Const keyword which you use after Global/Local keyword? Global/Local are declarative keywords which are used to declare variables, of course, you would know that already by now , If you check the documentation for Global/Local there is a optional parameter called Const which willl allow you to "create a constant rather than a variable"... Enum is similar to Const, it declares Integers (ONLY Integers):
      Global Enum $ZERO, $ONE, $TWO, $THREE, $FOUR, $FIVE, $SIX, $SEVEN, $EIGHT, $NINE ; And so on... ; $ZERO will evaluate to 0 ; $ONE will evaluate to 1 ; You get the idea :P ; Enum is very useful to declare Constants each containing a number (starting from 0) This script will demonstrate the usefulness and neatness of Enums :
      ; We will create an array which will contain details of the OS Global Enum $ARCH, $TYPE, $LANG, $VERSION, $BUILD, $SERVICE_PACK Global $aOS[6] = [@OSArch, @OSType, @OSLang, @OSVersion, @OSBuild, @OSServicePack] ; Now, if you want to access anything related to the OS, you would do this: ConsoleWrite(@CRLF) ConsoleWrite('+>' & "Architecture: " & $aOS[$ARCH] & @CRLF) ConsoleWrite('+>' & "Type: " & $aOS[$TYPE] & @CRLF) ConsoleWrite('+>' & "Langauge: " & $aOS[$LANG] & @CRLF) ConsoleWrite('+>' & "Version: " & $aOS[$VERSION] & @CRLF) ConsoleWrite('+>' & "Build: " & $aOS[$BUILD] & @CRLF) ConsoleWrite('+>' & "Service Pack: " & $aOS[$SERVICE_PACK] & @CRLF) ConsoleWrite(@CRLF) ; Isn't it cool? XD You can use this in your UDF(s) or Program(s), it will look very neat!
      Looping through an Array
      Looping through an array is very easy! . There are 2 ways to loop an array in AutoIt!
      Simple Way:
      ; This is a very basic way to loop through an array ; In this way we use a For...In...Next Loop! Global $aArray[2] = ["Foo", "Bar"] ; Create an array ; This loop will loop 2 times because our $aArray contains 2 elements. For $vElement In $aArray ; $vElement will contain the value of the elements in the $aArray... one element at a time. ConsoleWrite($vElement & @CRLF) ; Prints the element out to the console Next ; And that's it! Advanced Way:
      ; This is an advanced way to loop through an array ; In this way we use a For...To...Next Loop! Global $aArray[4] = ["Foo", "Bar", "Baz", "Quack"] ; Create an array ; This loop will loop 2 times because our $aArray contains 2 elements. For $i = 0 To UBound($aArray) - 1 ; $i is automatically created and is set to zero, UBound($aArray) returns the no. of elements in the $aArray. ConsoleWrite($aArray[$i] & @CRLF) ; Prints the element out to the console. Next ; This is the advanced way, we use $i to access the elements! ; With the advanced method you can also use the Step keyword to increase the offset in each "step" of the loop: ; This will only print every 2nd element starting from 0 ConsoleWrite(@CRLF & "Every 2nd element: " & @CRLF) For $i = 0 To UBound($aArray) - 1 Step 2 ConsoleWrite($aArray[$i] & @CRLF) Next ; This will print the elements in reverse order! ConsoleWrite(@CRLF & "In reverse: " & @CRLF) For $i = UBound($aArray) - 1 To 0 Step -1 ConsoleWrite($aArray[$i] & @CRLF) Next ; And that ends this section! For some reason, many people use the advance way more than the simple way . For more examples of loops see this post by @FrancescoDiMuro!
      Interpreting Multi-Dimensional Arrays
      Yeah, its the most brain squeezing problem for newbies, Imagining an 3D Array... I will explain it in a very simple way for ya, so stop straining you brain now! . This way will work for any array regardless of its dimensions...
      Ok, Lets start... You can imagine an array as a (data) mine of information:

      ; Note that: ; Dimension = Level (except the ground level :P) ; Element in a Dimension = Path ; Level 2 ----------\ ; Level 1 -------\ | ; Level 0 ----\ | | ; v v v Local $aArray[2][2][2] ; \-----/ ; | ; v ; Ground Level ; As you can see that $aArray is the Ground Level ; All the elements start after the ground level, i.e from level 0 ; Level 0 Contains 2 different paths ; Level 1 Contains 4 different paths ; Level 2 Contains 8 different paths ; When you want too fill some data in the data mine, ; You can do that like this: $aArray[0][0][0] = 1 $aArray[0][0][1] = 2 $aArray[0][1][0] = 3 $aArray[0][1][1] = 4 $aArray[1][0][0] = 5 $aArray[1][0][1] = 6 $aArray[1][1][0] = 7 $aArray[1][1][1] = 8 ; Don't get confused with the 0s & 1s, Its just tracing the path! ; Try to trace the path of a number with the help of the image! Its super easy! :D I hope you might have understand how an array looks, Mapping your way through is the key in Multi-Dimensional arrays, You take the help of notepad if you want! Don't be shy!
      Frequently Asked Questions (FAQs) & Their answers
      Q #1. What are Arrays?
      A. An Array is an datatype of an variable (AutoIt has many datatypes of variables like "strings", "integers" etc. Array is one of them). An Array can store information in a orderly manner. An Array consist of elements, each element can be considered as a variable (and yes, each element has its own datatype!). AutoIt can handle 16,777,216 elements in an Array, If you have an Array with 16,777,217 elements then AutoIt crashes.
      Q #2. Help! I get an error while declaring an Array!?
      A. You tried to declare an array like this:
      $aArray[1] = ["Data"] That is not the right way, Array is a special datatype, since its elements can be considered as individual variables you must have an declarative keyword like Dim/Global/Local before the declaration, So this would work:
      Local $aArray[1] = ["Data"] Q #3. How can I calculate the no. of elements in an array?
      A. The UBound function is your answer, Its what exactly does! If you have an multi-dimensional Array you can calculate the total no. of elements in that dimension by specifying the dimension in the second parameter of UBound
      Q #4. Why is my For...Next loop throwing an error while processing an Array?
      A.  You might have done something like this:
      #include <MsgBoxConstants.au3> Local $aArray[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Local $iMyNumber = 0 For $i = 0 To UBound($aArray) ; Concentrate here! $iMyNumber += $aArray[$i] Next MsgBox($MB_OK, "Sum of all Numbers!", $iMyNumber) Did you notice the mistake? UBound returns the no. of elements in an array with the index starting from 1! That's right, you need to remove 1 from the total no. of elements in order to process the array because the index of an array starts with 0! So append a simple - 1 to the statment:
      #include <MsgBoxConstants.au3> Local $aArray[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Local $iMyNumber = 0 For $i = 0 To UBound($aArray) - 1 $iMyNumber += $aArray[$i] Next MsgBox($MB_OK, "Sum of all Numbers!", $iMyNumber) Q #5. Can an Array contain an Array? How do I access an Array within an Array?
      A. Yes! It is possible that an Array can contain another Array! Here is an example of an Array within an Array:
      ; An Array can contain another Array in one of its elements ; Let me show you an example of what I mean ;) #include <Array.au3> Global $aArray[2] $aArray[0] = "Foo" Global $aChildArray[1] = ["Bar"] $aArray[1] = $aChildArray _ArrayDisplay($aArray) ; Did you see that!? The 2nd element is an {Array} :O ; But how do we access it??? ; You almost guessed it, like this: ; Just envolope the element which contains the {Array} (as shown in _ArrayDisplay) with brackets (or parentheses)! :D ConsoleWrite(($aArray[1])[0]) ; NOTE the brackets () around $aArray[1]!!! They are required or you would get an syntax error! ; So this: $aArray[1][0] wont work!  
      More FAQs coming soon!
    • Dequality
      By Dequality
      error code >Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "D:\Scripts\Tests\Test.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop +>16:23:40 AutoIt3.exe ended.rc:0 +>16:23:40 AutoIt3Wrapper Finished. >Exit code: 0 Time: 0.6734 HotKeySet("{F4}", _myExit()) Global $aCoordinates1[2] = [499, 582] Global $aCoordinates2[2] = [672, 614] While(1)     $instrument = PixelSearch(602, 439, 601, 438, 0x434343, 1)     if not(@error) Then         $musicscore = PixelSearch(1185, 529, 1184, 528, 0xDDA03B, 1)         If not(@error) Then             MouseMove($musicscore[0], $musicscore[1], 3)             Sleep(500)             MouseClick("RIGHT", $musicscore[0], $musicscore[1], 1, 1)         EndIf     EndIf     MouseClick("LEFT", random($aCoordinates1[0], $aCoordinates1[1]), Random($aCoordinates2[0], $aCoordinates2[1]))    Sleep(Random(304000, 309043)) WEnd Func _myExit()     Exit EndFunc Any help are highly appreciatet... :-) 
       
      Dequality.
    • simonc8
      By simonc8
      I have a script which executes sleep for a couple of hours then carries out instructions. Does the running AutoIt script prevent the computer from entering sleep mode during this time? If not, is there something I can add to the AutoIt script to keep the computer awake?
      Grateful for advice.
×