Throwing two dice and print out the total of each throw

in the days of line numbers  i build a short programme to simulate the 
throwing of two dice with a screen  print out the number of times, a 
particular number randomly came up . My question is can this run using Access 
VB ? Any constructive advise would be most welcome . The old code is as 
follows:
 REM THROWING 2 DICE
CLS
INPUT "How many Throws", N
Dim A(12)
FOR  M = 1 TO 12
A(M) = 0
Next M
FOR T = 1 TO N
X = int(6 * rnd (1)) + 1
Y = int(6 * rnd (1)) + 1
Z = X + Y
A (Z) = A(Z)+1
NEXT T
CLS
PRINT TAB(5); "Total" ; TAB(25); " Frequency"
PRINT
FOR M = 2 TO 12 
PRINT TAB(7) ; M; TAB(28) ;A(M)
NEXT M
END 





-- 
RFortune
0
Utf
12/22/2009 8:56:09 PM
access 16762 articles. 3 followers. Follow

6 Replies
856 Views

Similar Articles

[PageSpeed] 10

Yes, you can...

The only decision here is for your output window.

You can use the debug/development window, or you can use a form With a text
box that will scroll as a window.

Lets first do this with the debug window (no form needed, just code).

Option Compare Database

Sub Test1()

   Rem THROWING 2 DICE
   n = InputBox("How many Throws")

   Dim A(12)
   For M = 1 To 12
      A(M) = 0
   Next M
   For T = 1 To n
      X = Int(6 * Rnd(1)) + 1
      y = Int(6 * Rnd(1)) + 1
      Z = X + y
      A(Z) = A(Z) + 1
   Next T

   Debug.Print Tab(5); "Total"; Tab(25); " Frequency"
   Debug.Print
   For M = 2 To 12
      Debug.Print Tab(7); M; Tab(28); A(M)
   Next M

End Sub

Like when useing te PET, or TRS80, or the Apple II, There is often some 
minor differences in the code syntax. For example, we don't have a CLS 
command. and, we had to change the print command to debug.print.

The output for entering a value of 2 is:

    Total                Frequency

       2                    0
       3                    0
       4                    0
       5                    0
       6                    0
       7                    1
       8                    0
       9                    1
       10                   0
       11                   0
       12                   0


A surprising amount of the old style basic programming syntax actually works 
inside of the MS access, even the code to read and write text files remains 
unchanged as it existined in the old DOS basic system from 22 years ago.

For example:

Sub ReadTextFile

    Dim strFile      As String
    Dim intF         As Integer
    Dim strLineBuf   As String
    Dim lngLines     As Long
    Dim lngBlank     As Long

   strFile = "c:\my data\MyData.txt"

      intF = FreeFile()
      Open strFile For Input As #intF

      Do While EOF(intF) = False
         Line Input #intF, strLineBuf
         If Trim(strLineBuf) = "" Then
            lngBlank = lngBlank + 1
         Else
            lngLines = lngLines + 1
         End If
      Loop
      Close intF

   End If

   MsgBox "Number non blank lines  = " & lngLines & vbCrLf & _
          "Blank lines = " & lngBlank & vbCrLf & _
          "Total = " & lngBlank + lngLines

End Function

If you look at the use of the input# command, it's exactly the same syntax 
that we had twenty years ago. About the only difference in the above is that 
I use a message box command in place of a (debug) print command and 
therefore the user sees the answer displayed in a dialog box in windows on 
the screen, instead of on the output text in the debug window..


-- 
Albert D. Kallal    (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal@msn.com


0
Albert
12/22/2009 9:23:35 PM
Sorry, one more thing....


To the run the code, either put your cursor in the code and hit f5, or from 
the debug window simply type in the name of hte sub.


eg:

Test1

Also, do save the code module. Note that the code module name MUST be 
different then the sub name in side. You can put lots of subs inside of one 
code module....


-- 
Albert D. Kallal    (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal@msn.com


0
Albert
12/22/2009 9:25:46 PM
As a side note, I think I forgot the original instructions or step by step 
how to get into the code editor....

This step(s) might not be clear.

The first thing we have to do is to create a standard code module in which 
you can enter some of your code routines. Keep in mind that each code module 
you create can have quite a few different subroutines, or little sets of 
code that you want to run. Often what happens is if I have some routines to 
read and write files, then I will create a code module for all that code 
that reads and writes files.

Here's a typical screen shot of all the modules I created in a typical 
access application:

http://www.members.shaw.ca/AlbertKallal/test/index2.htm

So in the above screen shot, each module created can have quite a bit of 
code in it. The conceptual idea here is that you create modules to allow you 
to Group like minded code into the same code module.

The above screen shot is access 2003, and you can see I have models for word 
code, testing, etc...

So before you can type in some code, the first thing you do is select the 
modules tab, then create a new code module. You can then type in the code as 
per my other message.

As mentioned each code module you create can have more than one subroutine 
or code "function".

-- 
Albert D. Kallal    (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal@msn.com


0
Albert
12/22/2009 9:35:59 PM
If you do a little research in Statistics, you will be able to calculate the 
probability of any number between 2 and 12 coming up when throwing of two 
dice. This will be more accurate than your simulation.

Steve
santus@penn.com


"Bob" <Bob@discussions.microsoft.com> wrote in message 
news:05286C6A-3F0C-433C-93DB-3693EFC64A6A@microsoft.com...
> in the days of line numbers  i build a short programme to simulate the
> throwing of two dice with a screen  print out the number of times, a
> particular number randomly came up . My question is can this run using 
> Access
> VB ? Any constructive advise would be most welcome . The old code is as
> follows:
> REM THROWING 2 DICE
> CLS
> INPUT "How many Throws", N
> Dim A(12)
> FOR  M = 1 TO 12
> A(M) = 0
> Next M
> FOR T = 1 TO N
> X = int(6 * rnd (1)) + 1
> Y = int(6 * rnd (1)) + 1
> Z = X + Y
> A (Z) = A(Z)+1
> NEXT T
> CLS
> PRINT TAB(5); "Total" ; TAB(25); " Frequency"
> PRINT
> FOR M = 2 TO 12
> PRINT TAB(7) ; M; TAB(28) ;A(M)
> NEXT M
> END
>
>
>
>
>
> -- 
> RFortune 


0
Steve
12/22/2009 10:05:59 PM
On Dec 22, 5:05 pm, "Steve" <notmyem...@address.com> wrote:
> If you do a little research in Statistics, you will be able to calculate the
> probability of any number between 2 and 12 coming up when throwing of two
> dice. This will be more accurate than your simulation.

That's a great point Steve.  BTW, Merry Christmas.  Here's a codeless
version  I tried:

Using two queries:

tblIntegers
ID AutoNumber
theInt Long
ID theInt
1 1
2 2
3 3
....
25 25

qryTheCrosstab:
TRANSFORM Count(qryRolls.Total) AS CountOfTotal
SELECT qryRolls.theInt
FROM (SELECT 20 As NumRolls, theInt, ID, Rnd(ID) * 10^9 AS Seed, SEED
Mod 6 + 1 As Pos, Pos + Pos As Total FROM tblIntegers WHERE
tblIntegers.theInt <= 20) AS qryRolls
GROUP BY qryRolls.theInt
PIVOT qryRolls.Total IN (2,3,4,5,6,7,8,9,10,11,12);

qrySummary:
SELECT Sum(Nz(qryTheCrosstab.[2], 0)) AS 2s, Sum(Nz(qryTheCrosstab.
[3], 0)) AS 3s, Sum(Nz(qryTheCrosstab.[4],  0)) AS 4s, Sum(Nz
(qryTheCrosstab.[5], 0)) AS 5s, Sum(Nz(qryTheCrosstab.[6], 0)) AS 6s,
Sum(Nz(qryTheCrosstab.[7], 0)) AS 7s, Sum(Nz(qryTheCrosstab.[8], 0))
AS 8s, Sum(Nz(qryTheCrosstab.[9], 0)) AS 9s, Sum(Nz(qryTheCrosstab.
[10], 0)) AS 10s, Sum(Nz(qryTheCrosstab.[11], 0)) AS 11s, Sum(Nz
(qryTheCrosstab.[12], 0)) AS 12s
FROM qryTheCrosstab;

!qrySummary
2s 3s 4s 5s 6s 7s 8s 9s 10s 11s 12s
1   0   3   4   2   4   3   1   0   0   2

A97 version of qryTheCrosstab:

TRANSFORM Count(qryRolls.Total) AS CountOfTotal
SELECT qryRolls.theInt
FROM [SELECT 20 As NumRolls, theInt, ID, Rnd(ID) * 10^9 AS Seed, SEED
Mod 6 + 1 As Pos, Pos + Pos As Total FROM tblIntegers WHERE
tblIntegers.theInt <= 20 ]. AS qryRolls
GROUP BY qryRolls.theInt
PIVOT qryRolls.Total IN (2,3,4,5,6,7,8,9,10,11,12);

Note that the number of rolls must be changed near the <=.  The other
20 is for information only.  All of the above can probably be
simplified.

James A. Fortune
MPAPoster@FortuneJames.com
0
James
12/23/2009 1:30:56 PM
Merry Christmas to you and your family too, Jim. I wish you too a Happy, 
Healthy and Prosperpous New Year.

Steve


"James A. Fortune" <MPAPoster@FortuneJames.com> wrote in message 
news:c4e94791-ff34-4d32-a941-f24c25e2cc2b@d21g2000yqn.googlegroups.com...
> On Dec 22, 5:05 pm, "Steve" <notmyem...@address.com> wrote:
>> If you do a little research in Statistics, you will be able to calculate 
>> the
>> probability of any number between 2 and 12 coming up when throwing of two
>> dice. This will be more accurate than your simulation.
>
> That's a great point Steve.  BTW, Merry Christmas.  Here's a codeless
> version  I tried:
>
> Using two queries:
>
> tblIntegers
> ID AutoNumber
> theInt Long
> ID theInt
> 1 1
> 2 2
> 3 3
> ...
> 25 25
>
> qryTheCrosstab:
> TRANSFORM Count(qryRolls.Total) AS CountOfTotal
> SELECT qryRolls.theInt
> FROM (SELECT 20 As NumRolls, theInt, ID, Rnd(ID) * 10^9 AS Seed, SEED
> Mod 6 + 1 As Pos, Pos + Pos As Total FROM tblIntegers WHERE
> tblIntegers.theInt <= 20) AS qryRolls
> GROUP BY qryRolls.theInt
> PIVOT qryRolls.Total IN (2,3,4,5,6,7,8,9,10,11,12);
>
> qrySummary:
> SELECT Sum(Nz(qryTheCrosstab.[2], 0)) AS 2s, Sum(Nz(qryTheCrosstab.
> [3], 0)) AS 3s, Sum(Nz(qryTheCrosstab.[4],  0)) AS 4s, Sum(Nz
> (qryTheCrosstab.[5], 0)) AS 5s, Sum(Nz(qryTheCrosstab.[6], 0)) AS 6s,
> Sum(Nz(qryTheCrosstab.[7], 0)) AS 7s, Sum(Nz(qryTheCrosstab.[8], 0))
> AS 8s, Sum(Nz(qryTheCrosstab.[9], 0)) AS 9s, Sum(Nz(qryTheCrosstab.
> [10], 0)) AS 10s, Sum(Nz(qryTheCrosstab.[11], 0)) AS 11s, Sum(Nz
> (qryTheCrosstab.[12], 0)) AS 12s
> FROM qryTheCrosstab;
>
> !qrySummary
> 2s 3s 4s 5s 6s 7s 8s 9s 10s 11s 12s
> 1   0   3   4   2   4   3   1   0   0   2
>
> A97 version of qryTheCrosstab:
>
> TRANSFORM Count(qryRolls.Total) AS CountOfTotal
> SELECT qryRolls.theInt
> FROM [SELECT 20 As NumRolls, theInt, ID, Rnd(ID) * 10^9 AS Seed, SEED
> Mod 6 + 1 As Pos, Pos + Pos As Total FROM tblIntegers WHERE
> tblIntegers.theInt <= 20 ]. AS qryRolls
> GROUP BY qryRolls.theInt
> PIVOT qryRolls.Total IN (2,3,4,5,6,7,8,9,10,11,12);
>
> Note that the number of rolls must be changed near the <=.  The other
> 20 is for information only.  All of the above can probably be
> simplified.
>
> James A. Fortune
> MPAPoster@FortuneJames.com 


0
Steve
12/23/2009 11:50:43 PM
Reply:

Similar Artilces:

printing issue
Hello, This is a crosspost that i also posted in excel.printing. I am having this weird issue in excel 2007. I would create a relatively long worksheet (one that would end up being 10 - 15pgs) and with in this worksheet there would be text and pasted pictures. Now the picture would be followed by a description underneath. All the picture would be sized about the same and all the cells are default and not adjusted at all. The text is default size also. The margins and everything are set the same. Now the issue is this, on excel normal view or page break view everything loo...

Inbox unread total does not change
I have a problem with one Outlook installation in my office. The number on the right of the Inbox, which should reflect the number of unread messages, is the total of all the messages in the Inbox - both unread and read. How do I fix this? >-----Original Message----- >I have a problem with one Outlook installation in my >office. The number on the right of the Inbox, which should >reflect the number of unread messages, is the total of all >the messages in the Inbox - both unread and read. > >How do I fix this? >. >What version of Outlook are you running? ...

Two CListBoxes alignment
Hi, there, I am using two CListBoxes control to show two sets of files. When I click on one file of control A, I want the file with the same index of control B also highlighted. And when I slide the scroll bar of control A, the view of control B should also be changed to show the same view. Is this possible? And if it is, what the methods and events should I use? Thanks lot in advance! Gary Lets assume that both listboxes have the same information. I would catch the scroll message (WM_VSCROLL) of the listboxes, when I a scroll happened, I get the top index of the listbox, and set t...

Add Record from form into two tables
I have a form (frm_Invoice) that records phone serial # from customers. I want to create a new record in both the tbl_Inventory and tbl_Inventory_Detail when someone scans in a DEC_SN into the frm_Invoice. The issue I am running across is that the tbl_Inventory_Details has a child relationship to the tbl_Inventory. I chose this set up because most of the inventory is manually entered from shipments received from a warehouse. I created a form and sub form for the inventory tying the SN_ID from each table on a one to many relationship. I do not know how to update both tables at ...

Printing to a network printer in Publisher 2003
When I try to print to a network printer in Publisher 2003 I get the following error messages "Publisher cannot continue printing because of an error. For more information, press F1" followed by "Please choose another printer. Publisher cannot find the printer \\printserver\printershare for this publication. To select a different printer, click OK. To return to Publisher now, click Cancel." All my other Office XP products print fine as do non-microsoft apps. Can anyone shed any light on this? neilvilla wrote: > When I try to print to a network printer in Publi...

Momo Style Printing
unable to select printer when printing from outlook in memo style. When selecting Table style I am able to select printer ...

How to automate zoom+ in Print Preview
Hi, Is anybody know how to automate zoom+ (big) when we make print preview in Access?. Everytime I make a report, I always print preview first before I print the report to printer. But the problem is, access always zoom- on print preview. So we have to do 1 click tomake it bigger. For computer illeterate, sometimes the don't know how to make it bigger. I tried to look on the print properties, bit I can't find out. Thanks in advance. KF -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-reports/200708/1 On Aug 31, 6:24 am, "KimTong vi...

Printing Receipts after Transactions
Is there any way to set up RMS to ask a cashier if they want to print one or two copies of a transaction. It seems like a waste of paper to print two copies for anything but a credit card transaction. -- Shane This is a multi-part message in MIME format. ------=_NextPart_000_060B_01C6F884.E56AEFC0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Shane, No, but you can create a Custom Button to reprint the last receipt. http://tinyurl.com/yfof27 Must have access to CustomerSource --=20 * Get Secure! - www.microsoft.com/security You must...

Printing changes from 2000 to 2003
Documents that were set up in 2000 with printing set to say one page, are now printing to 2 pages or more in 2003 as if the printing set up has not been remembered. Does anyone know of a way to get around this without changing the print set up in every document that is opened? Thanks Shelagh Maybe being more conservative in the page setup would help. (I'd guess that this is more a difference in printers/printer drivers than an excel issue.) Use the settings for the worst printer you can find. Then hope that you found the worst one. Shelagh wrote: > > Documents that were se...

Non printing of check boxes in a Report
I have come back to using Access and although I have managed it before I cannot get Check Boxes to print in a Report. They are visible on screen but when I want to print the Reports the space where the check boxes should be whether 'a tick' or 'blank' is empty. Try changing the font. It may be something your printer doesn't have the font for, while substituting another similar font for other characters. "Jenny" <Jenny@discussions.microsoft.com> wrote in message news:71D46938-AA7C-4C43-8284-B763FD955FAB@microsoft.com... >I have come back to using ...

Two Accounts
Hi Have setup two accounts, and they show up as expected. However get this messsage when trying to send account B. Account A works just fine. Have an email in B which stays in outbox and B will not receive either.Each account is a different ISP but that should not make any difference. All the settings are the same for each account. **** host smtp server could not be found Windows live mail error ID: 0x800CCC0D .....Socket error 11003 **** There must be a setting that requires changing. Any ideas ? Thanks Charlie Harris "sswcharlie" wrote in messa...

Two Problems #2
When starting up and shutting down Excel 2007 I get the error message, "Compile error in hidden module: DistMon. It seems to work ok in spite of this. Any ideas on how to fix this? http://support.microsoft.com/kb/307410 -- Jim "petervana" <petervana@discussions.microsoft.com> wrote in message news:C78605BD-4C58-4AA5-BE81-786DA61131B2@microsoft.com... | When starting up and shutting down Excel 2007 I get the error message, | "Compile error in hidden module: DistMon. It seems to work ok in spite of | this. | | Any ideas on how to fix this? I went to thi...

printing report with OLE images
I can't get my report to print with the linked photos...everything else prints fine, but there is a blank space where the photo is supposed to be. I created a database for fifth graders at our school for the memory book. Need asap to send to printer. ...

The same table 'All' cannot be the child table of two nested relat
Using VS2005 beta 2, I have an xsd provided by a vendor that I want to make into a strongly typed data set. In VS 2003 the MSDataSetGenerator tool gives a similar error, which I was told was to be fixed in VS 2005. And in fact the xsd tool does now correctly process the .xsd and create a .vb for it which compiles just fine. But at runtime when I try to new the strongly typed data set, I get the above error. This schema comes to me from a vendor that has several others that I must also work with, and is valid according to XMLSpy and other commercial XML tools, and they all have sim...

Two Questions #2
1)I have a user on Office 2000. Outlook 2K as well as Word 2K work fine. But when she tries to send a document directly from Word, she gets the message "The host 'http' could not be found. Please verify that you have entered the server name correctly. Account: 'http', Server: 'http', Protocol: SMTP, Port: 25, Secure(SSL): No, Socket Error: 11001, Error Number: 0x800CCC0D". The address book from Outlook does not appear in Word either, as in when she hits the To... button to the left of the associated address field. This problem only occurs on that particula...

How do I sequentially number Tickets Printed on Business cards?
I am using Publisher 2003 and want to print tickets on business card stock. How can I sequentially number the tickets? Thanks HO homills wrote: > I am using Publisher 2003 and want to print tickets on business card stock. > How can I sequentially number the tickets? Use a Mail Merge database of sequential numbers; design a single ticket on a page and use Page Setup to lay it up however many times you need per page. Print preview will be wrong (will show the same number n times on a page), printing a test page should be correct. -- Ed Bennett - MVP Microsoft Publisher http://ed....

Update on client side throws exception
Hi all, I'm updating a SQL Server 2008 database table using SqlDataAdapter/DataSets and Visual Studio C# on the client side. TARGET TABLE TO UPDATE: T_Order FIELDS: TAXOR [nvarchar] (255) NULL, TAXPARTSIZE [nvarchar] (255) NULL TAXSBO [nvarchar] (255) NULL TAXGRP [nvarchar] (255) NULL TAXSBGRP [nvarchar] (255) NULL SOURCE TABLE: ConusSolLyr FIELDS: TAXOR [nvarchar] (255) NULL, TAXPARTSIZE [nvarchar] (255) NULL TAXSBO [nvarchar] (255) NULL TAXGRP [nvarchar] (255)...

Printing worksheet #2
How do I print the colums at top and the numbered rows with the lines showing? When I try to print, it just gives me the column at top and the rest of the page is blank. "Robyn M" <Robyn M@discussions.microsoft.com> wrote in message news:6ED1A505-CCAB-4200-B5FD-3D8D72224EFE@microsoft.com... > How do I print the colums at top and the numbered rows with the lines > showing? When I try to print, it just gives me the column at top and the > rest > of the page is blank. Page Setup - Sheet - Print Row and Column Headings. -- Asking a question? Please tell us the ...

merging two accounts
This seems like something that should be easy, but it's totally stumped me. I use my laptop at home and at work. At work, I log onto a domain, so that I actually have two accounts on my laptop: "username" and "username.domain". So far so good. My problem is that I use the same email accounts both at work and at home. To avoid having two independent Outlooks on my computer that check the same email accounts, I moved the data file (.pst) locations of both accounts to one place. This worked fine, and when I opened Outlook from both accounts, it shows the sa...

Symbol not appear when print
When I print, the symbol theta doesn't appear however is displayed on print preview and the worksheet. Do I need to change a setting somewhere? ...

How do I get a "&" to print in a header?
How do I get a "&" to print in a header? && -- Gary's Student "aj4444" wrote: > How do I get a "&" to print in a header? ...

Importing CSV
Hi All, I have to import CSV files into excel. A regular issue with this is that often the CSV files will contain data (in this case account codes) that excel interprets as dates (such as '3-8000' being converted to 1 Mar 8000). Nothing unusual so far, in that we handle that issue by importing manually (External Data - Text import), and specifying that the field in question is imported as TEXT not GENERAL. However, I have a file that, when I double click on it, it opens up perfectly (except with dates where it should be text as outlined above), but if I manually import that f...

Record data on two lines
Sorry about repeating the post but I think I messed up the first one yeaterday! I am receiving a spreadsheet from an agency with record information on two lines. Example: Record 1: A1, B1, C1, D1, A2, B2, C2 Line 3 blank Record 2: A4, B4, C4, D4, A5, B5, C5 There are over 100 records like this. They claim they can't fix it... It originates from a Crystal Report. How can I change the data so each record is on one line: Record 1: A1, B1, C1, D1, E1, F1, G1 Record 2: A2, B2, .......................G2 Thanks for any help! Dan A simple way is to 1) select all of the data fields. 2) Cli...

How to speed up printing speed?
Hi: In my application, I use the Windows GDI functions such as PolyLine() and SetPixel() to print the ECG wave and backgroud grids; But when the printer driver's resolution is updated to 600 dpi, the printing meta file size dramatically increases; I tried to use memory bitmap method to printing the ECG waves, but it still can not print in high speed; Is there any better method to speed up the printing task with the window GDI function? Any suggestion is appreciated; Loggy Use emf.exe on www.fengyuan.com\download to decode the EMF file to see what is inside, or s...

merged print names 4 up post card
USING PUBLISHER 2000 - The merged print dialog box does not provide a selection for print side 1, print side 2 separately (instead printing side 1,2 side 1,2 etc,) I desire to print the clients <<first name>> (as in dear <<first name>>) on side 1, and mailing address <<first name>>,<< last name>>, <<address>>, etc. on side 2. I did follow the site instructions to create two separate files - but names will not line up on the 4 up post card. I do not have a duplexing unit on my HP8550 printer, so I must flip the stack over and ru...