home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.visual.basic      MS Visual Basic discussions, NOT dot-net      10,840 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 10,351 of 10,840   
   Jan Hyde to All   
   Re: Error when calculating probablity   
   02 Jan 07 08:53:11   
   
   From: StellaDrinker@REMOVE.ME.uboot.com   
      
   "Lisa" 's wild thoughts were released   
   on Tue, 02 Jan 2007 04:42:52 GMT bearing the following   
   fruit:   
      
   >In translating the formula for calculating lottery odds for various   
   >conditions into a Visual Basic Program, I have apparently missed something   
   >in that I get errors in the part of the calculation where the number of ways   
   >of failure (pFal) is calculated   
   >Both errors happen in the code section   
   >   
   >   x1 = Draw - MatchesReq   
   >   x2 = Field - Selections   
   >   For Counter = 1 To (Draw - MatchesReq - 1)   
   >       x1 = x1 * (Draw - MatchesReq - Counter)   
   >       x2 = x2 * (Field - Selections - Counter)   
   >   Next   
   >   pFal = x2 / x1   
   >   
   >The first type of error is created when the number of matches required is   
   >equal to the number of balls drawn.   
   >This makes x1 = 0 so when it hits the calculation pFal a divide by zero   
   >occurs.   
   >   
   >The second type of error is created when the number of balls selected is   
   >equal to the field.   
   >This makes x1 = 0 so when it hits the calculation pFal a divide by zero   
   >occurs.   
   >   
   >If anyone can spot my error I would greatly appreciate it.   
   >Lisa   
      
   Haven't you just identified the error? Divide by zero? If   
   zero is a possibility then you should always check for it in   
   code.   
      
   J   
      
      
   Jan Hyde (VB MVP)   
      
   --   
   So I was in Tesco's and I saw this man and woman wrapped in a barcode.   
   I said "Are you two an item?"   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca