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
981 Views

Similar Articles

[PageSpeed] 2

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:

Clistctrl on NT4 throws out of memory error
Hi all My App is developed with MS VC++ 6.0 and it works fine almost everywhere I access an mdb database to fill some listboxes (used as a search engine) and a list (CListCtrl). I found a machine running NT4 that fills the listboxes but it does not fill the clistctrl. I get an "out of memory" error when trying to fill the list with data. Can it be some flag (for example LVS_FULLROWSELECTED) or the one for displaying the grid, or the imagelist connected to the list, or the LVITEM that I add every row. It seems that some operation is not supported on that system. What can it be? Pleas...

Crystal Reports-totalling a Summary
Have a question on totalling a summary field in Crystal Reports, I am using the Minimum, Maximum and average functions to summarize purchase order line items for a bill of materials. I would also like to total these min, max and averages for all the items on a bill of materials but I cant figure out how to make crystal do this. maybe it isnt possible? I get the message that I cant total on a running total field or summary field. any suggestions? -- Doug Doug you may want to go on over to http://www.tek-tips.com/threadminder.cfm?pid=149 I go to this forum and others on tek-tips....

calculated total in query
I have 2 fields in query. Qty1 and Qty 2. I added Total:qty1+qty2. However, if qty1 has some number but qty2 is blank, my total is blank, instead of just show the sum. In Access You need to use the NZ function to force a ZERO. Or use an IIF clause. Total: Nz(Qty1,0) + Nz(Qty2,0) or Total: IIF(Qty1 is Null,0,Qty1) + IIF(Qty2 is Null,0,Qty2) John Spencer Access MVP 2002-2005, 2007-2010 The Hilltop Institute University of Maryland Baltimore County Song wrote: > I have 2 fields in query. Qty1 and Qty 2. I added Total:qty1+qty2. > However, if qty1 has some number b...

Time Sheet
I have a time sheet with four fields: Time In (C2), Lunch Out (D2), Lunch In (E2), Time Out (F2) I'm trying to create a formula in cell G2 to calculate the regular hours and another formula in H2 for the overtime hours, but have been unsuccessful. Current fields are formatted as Number | Custom | h:mm AM/PM for C2 thru F2 and are formatted as Number | Custom | h:mm for G2 and H2. Can anyone help me. Hi, Look into CPearson Web it has all the working with overtime Hs http://www.cpearson.com/excel/overtime.htm "Kathy" wrote: > I have a time sheet wi...

Quick Print issue
We are having an issue when using the Quick Print Setup. In general we have three main sites (which are named X, Y, and Z) with a printer defined for each site (using the Named Printers utility). When printing the pick tickets we specify to print separate picking ticket per site (each site has its own printer). If we do this printing process manually we get each picking ticket in its corresponding printer (per site). To make things easier we decided to use the Quick Print in this process. When using the Quick Print, only the pick ticket associated to the X site is being printed in the X site ...

Printing Labels using Access 2007
I am trying to print address labels on an Avery sheet (3 columns by 7 rows), but all I can get is 1 label per A4 page. Can anyone suggest a solution please? Robert Have you tried the Label Wizard in the Reports? Reports | New | Label Wizard It lets you select from among the various Avery label types and automatically configures your columns correctly. Once the wizard has done its thing, you can go in and tweak the format of the labels. HTH Dale "Robert" <nauntons@dial.pipex.com> wrote in message news:AOCdnRnRyf4nEmvbnZ2dneKdnZylnZ2d@pipex.net... >I am trying to...

print copies at printer instead of sending multi-copies to printer
Does anyone know how to send 1 copy of the page to a hp color laser and have the printer itself make the copies to save time / bandwidth. I noticed that it was sending a new copy of the page for each copy. ...

Different Total for end of day sales report
I am currently using RMS 1.2 on a Windows XP/SP2 computer. My problem is when i run various reports at the end of the day like Tender Summary and Detailed Sales report to see the total sales for the day, neither one matches my physical count. Can someone explain to me why i am getting this kind of result? And what i can do to correct it or get the right information? Or maybe i need a custom report to get an accurate total? Thank you in advance. Tender summary and detailed sales reports will have different totals since one (tender summary) includes all monies taken in, including taxes,...

Two types of crash in XP?
Hi, I'm trying to track down a very intermittent bug in an MFC application. When the error occurs it says something about a memory address and there's an OK/cancel button (not seen the error for a while so I don't recall exactly - possibly "unhandled exception"). Yet when I put code like this in the app - char *p = 0; *p = '1'; I get the "product.exe has encountered a problem and needs to close. We are sorry for the inconvenience." dialogue and get the option to send something to Microsoft. Why do I get that dialogue for my simple test code and so...

How to display the TOTAL of a sub form on the parent Form?
on my sub form (subDetails) I have a totals column. I then Total the totals column in the footer of the subform in a field named (txtOrderTotal) I want to display that total on the Parent form (frmOrders) (I do not want to just show the footer of the sub form due to placment issues) So on my parrent form I have a text box with this code in the control source =Forms!subDetails.txtOrderTotal BUT all I get is "#NAME?!" I have doubled checked my spelling. Am I going about this wrong? Any help here will be appreciated. Thanks in advance Dave On Fri, 24 Aug 2007 10:38:35 -0700...

Force Report Footing to print at bottom of page
Hhi, I'm using Access on Office XP Pro. Is there anyway to force the Report Footing (not page footing) to print at the bottom of the current page. Currently, the report ends 10 lines into a new page, so the report footing start printing on line 11. I would like it to print at the bottom of the page. Is there anyway to do this? -- Dennis On Tue, 2 Feb 2010 12:38:03 -0800, Dennis wrote: > Hhi, > > I'm using Access on Office XP Pro. > > Is there anyway to force the Report Footing (not page footing) to print at > the bottom of the cu...

How to include the Grand Total Column in a pivot table chart?
Hi, I have a simple pivot table with two columns A and B against several rows of responses. The pivot table also shows the Grand Total Column. I can graph the pivot table quickly and simply with the chart wizard (a bar chart in this instance) and it will display a bar for column A and a bar for B grouped per row response. Great. I want to add what is effectively the third column in the pivot - Grand total column, so I would have 3 bars per row response; A, B and Grand Total. I can then compare A and B to the total bar. How do I add/show the grand total in the pivot chart? Thanks! Yo...

Binding two table into one Crecordset
I am trying to bind two tables in a database into one recordset. I have added all the Column and Binded them with Class wizard and have added the Games table to the GetDefaultSQL() method and the filter to the set object. When I run the program it tells me that I have: Attemped to scroll past the end or before beginning of the data. This the section of my code that I added the filter to. it is in my OnInitialUpdate for my recordview m_pSet = &GetDocument()->m_leagueManagerDBSet; m_pSet->m_strFilter = "Teams.Teams_ID = Games.ID"; CRecordView::OnInitialUpdate(); G...

How do I split a column of information into two?
I have a column of information that I would like to split into two columns. As follows Mr John Smith (johnsmith@hotmail.com) Mrs Katie Brown (katiebrown@hotmail.com) I need to put everything in the bracket into a new column! Can anyone help? One way, assuming data as posted in A2 down In B2: =LEFT(A2,SEARCH("(",A2)-1) In C2: =RIGHT(A2,LEN(A2)-SEARCH("(",A2)+1) Select B2:C2, copy down as far as required -- Max Singapore http://savefile.com/projects/236895 xdemechanik --- "Nigel" <Nigel@discussions.microsoft.com> wrote in message news:64C2A4BD-CCF9-439...

Print Sequence
I want to convert a booklet to a pdf for online viewing. I want it in numeric sequence instead of the sequence needed to be published by a commericial printer PTA Mom <PTA Mom@discussions.microsoft.com> was very recently heard to utter: > I want to convert a booklet to a pdf for online viewing. I want it in > numeric sequence instead of the sequence needed to be published by a > commericial printer Change the paper size in your PDF application to the size of one individual page, then set the Page Setup to Full Page. -- Ed Bennett - MVP Microsoft Publisher Thanks. T...

Print preview look different than the page I am creating
I created a poster on a page 8.5 x 11. I use a background gray that fills the entire page. When I select Print Preview, there is a white border around the page. Why is this and how do I get rid of it? Is this just to frame my poster and doesn't it print on the page? I'd like to know before I print because this will use up a lot of ink that I don't wish to waste. "DTravz" <DTravz@discussions.microsoft.com> wrote in message news:4B7AF632-28B0-4610-BA34-D25886401C2E@microsoft.com... > I created a poster on a page 8.5 x 11. I use a background gray that fills th...

Excell
Formula to count if two conditions. I want to count column b when = "CAS" and if the number in column J is a negative number. I have tried =COUNTIF(B7:B21,"=CAS")=SUM(J7:J21,""<0) but it returns a "false" read. Column "b" are all words and Column "J" is numbers, but sometimes a negative number and I only want it to count if it is "0" or Less (negative) =SUMPRODUCT((B7:B21="CAS")*(J7:J21<0)) -- Gary''s Student - gsnu201002 "linda" wrote: > Formula to count i...

Postscript Printing Problem
Until yesterday I was able to print all my Publisher documents just fine on my Okidata 5151N printer. Now for reasons unknown to me I keep getting a ($*)#& message saying my printer doesn't support the version of Postscript required by the program. What I've attempted to far: - Uninstall and reinstall the print driver. - Checked settings in printer preferences (there are no Postscript options whatsoever). - Experimented with different printing and color settings in Publisher. - Printing a new, blank document from Publisher. - Downloaded/installed latest Office updates...

Print Outlook Calendar with an Excel form on back of same sheet
I work for a large company where all employees print two forms everyday. One is their Outlook calendar and the other is an Excel Form used to collect data during the completion of a daily process throughout the day. I would like to automate the printing of these two forms by combining them into a single print function with the output resulting in their Outlook Calendar Daily View on the front and the data collection Form on the back of a single sheet. I've tried exporting my calendar data into a sheet in the Excel workbook, but formatting the schedule data to look graphi...

Printing right to the edge of the page without borders???
I have an image that I need to print to the exact page size (A5). I have changed the image dimensions to match the page dimensions but when I print it keeps cutting part of the iamge off?? Does anyone know how I can fix this?? Sharina wrote: > I have an image that I need to print to the exact page size (A5). I > have changed the image dimensions to match the page dimensions but > when I print it keeps cutting part of the iamge off?? Does anyone > know how I can fix this?? ======================== Maybe your printer doesn't print full bleed (edge to edge)? "How to find ...

How to pause or resume a new print job on print server?
Hi, I need to write an app to take control of the printing process to enforce some security policy. My app running on network printer server needs to be actived as soon as a new print job comes in. It checks the ip address where the new job is from and blocks some special users. Can I call OpenPrintProcessor and ControlPrintProcessor for the default processor: WinPrint? How to trap a new print job? Any ideas or code samples? Thank you very much in advance. ...

Payable not match to total vendor ballance
What is possible reason account payable does not match to total of vendors ballances? 1. a gl batch was deleted before it was posted. 2. someone posted directly to the gl account and not through payables. several reasons. -- Richard L. Whaley Author / Consultant / MVP 2006-2008 Documentation for Software Users Get our Free Tips and Tricks Newsletter and check out our books at http://www.AccoladePublications.com "icc" wrote: > What is possible reason account payable does not match to total of vendors > ballances? As Richard stated, there are a num...

passing data between two databases
I want to pass a value from one database system to a text box field of a form in a seperate database system. Is it possible and how would I do it? Any help will be appreciated. Thanks Are you asking if it is possible to reference one form to another form in seperate DB's? I don't think that's a desirable solution. 1. Why not use a linked table where you can reference from 2. Export the value by passing it through via Append Query which references the other DB. You could create an empty table in that referenced DB and place the values there. Maurice "Justin" wr...

Two Reports into one pdf file
Is it possible to output two different reports into one pdf file, and if so, how Thanks in adavance. ...

Invoice Printing
I cannot believe that GP10 does not allow the user to reprint a range of invoices. This should be basic functionality. Many times invoices get lost and the customer wants you to reprint them. We are in the process reprinting over 200 invoices and we have to do this an invoice at a time. You should be able to pull up a form that lists all of the invoices and you should be able to check or toggle each invoice you want to reprint. Its not that hard. -- Craig Craig, I hear you, however, if you can actually use the Sales Order Processing Document Inquiry window or the Sales Inquiry R...