Author |
Message |
kk
|
Posted: Tue Jan 03, 2006 1:38 am Post subject: Program Crash |
|
|
Hi, I am wondering whether you could help me out. This program generates a math equation with three numbers; the first two numbers are multiplied, and the answer of the equation is the division of this product with the last number. I am using 1 digit numbers to test the program. The equation that is generated is put in a counted loop but the program crashes(it is NOT RESPONDING) only after the counted loop is finished running.(not shown) Here is a section of code that I am running. Thanks in advance.
I am new to visual basic, so I am not aware of any MEMORY MANAGEMENT issues, so feel free to add any coding optimizations.
I've only included comments and not the code . If they are needed, feel free to ask for them.
code: |
' .. portion of code in CreateQuestion function
' Put two random teams on the stack
Factor1 = NotPrime()
Teams.Push (Factor1)
Answer = Teams.Peek
Factor2 = (Rnd * 100000) Mod ((10 ^ Int(cboPlusMinDigits.Text) - 1)) + 1
Teams.Push (Factor2)
Answer = Answer * Teams.Peek
' Push the / sign on the stack
Signs.Push SIGN_DIVIDE
' Put the division team on the team stack
Teams.Push FactorOf(Answer, Factor1, Factor2)
Answer = Answer / Teams.Peek
' .. portion of code in CreateQuestion function
'-----------------------------------------
' Name: FactorOf
' Recieves:
' Dividend (Long) : Factors are generated from this number(not a prime)
' Exclud1, Exclud2 (Integers) : Return value will exclude the possibility of returning the specified integers
' (factors from multiplication). For any unused parameters, argument should be 1.
' Returns: A Long that is a factor of the Dividend.
' Purpose: To return any factor of the Dividend that is not equal to the specified parameters.
'-----------------------------------------
Private Function FactorOf(ByVal Dividend As Long, ByVal Exclud1 As Long, ByVal Exclud2 As Long) As Long
Dim FactorList() As Long
Dim Num As Long
Dim i As Long ' Counter
'FIND FACTORS OF DIVIDEND
' First in finding factors is that you only have to go half way to find all
' the factors of a given number
' divisor mod i = 0 then this is a factor
'ADD FACTORS TO FACTORLIST ARRAY
' In the case of a prime number send the Dividend Back (covers 1 digit case: 2 x 1 / ?)
' Pick a random factor and send it back. This factor cannot be any of the existing used in multiplication
Do
Num = FactorList(Int((Rnd * 1000) Mod UBound(FactorList)) + 1)
Loop While (Num = Exclud1 Or Num = Exclud2) Or Num > 10 ^ cboDivDigits.Text
FactorOf = Num
End Function
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
HazySmoke)345
![](http://i10.photobucket.com/albums/a121/HazySmoke/clubps2.jpg)
|
Posted: Tue Jan 03, 2006 5:55 pm Post subject: (No subject) |
|
|
Your lines are very confusing indeed... It sounds like a pretty simple program but the script is so long. Since I don't know the whole script, I don't know if the length necessary or not. I'd just simply do something like this:
VisualBASIC: | Private Sub Form_Load()
Dim a
Dim b
Dim c
Randomize
a = Int(Rnd * 10)
b = Int(Rnd * 10)
c = Int(Rnd * 10)
Msgbox a * b / c
End Sub |
|
|
|
|
|
![](images/spacer.gif) |
cool dude
![](http://www.taylorstrategicmarketing.com/images/king.jpg)
|
Posted: Tue Jan 03, 2006 6:40 pm Post subject: (No subject) |
|
|
HazySmoke)345 wrote: VisualBASIC: |
Msgbox a * b / c
|
Shouldn't the a*b be in brackets since it is bedmass |
|
|
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: Tue Jan 03, 2006 8:18 pm Post subject: (No subject) |
|
|
The correct acronym is BEDMAS, and it doesn't matter since multiplication and division just go left to right. Test it out and see for yourself. |
|
|
|
|
![](images/spacer.gif) |
cool dude
![](http://www.taylorstrategicmarketing.com/images/king.jpg)
|
Posted: Tue Jan 03, 2006 11:38 pm Post subject: (No subject) |
|
|
[Gandalf] wrote: The correct acronym is BEDMAS, and it doesn't matter since multiplication and division just go left to right. Test it out and see for yourself.
u r right it is BEDMAS and i did notice it but unfortunately nobody made an edit button for visual basic forums so i couldn't edit it. and yes it doesn't matter about the brackets but i couldn't test it at the moment since i didn't have VB on the computer i was using and thats why i said "shouldn't it be" instead of "it has to be" |
|
|
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: Wed Jan 04, 2006 2:16 am Post subject: (No subject) |
|
|
There's no edit button in any help forum.
What grade are you in? Even if you're not really good in math, you shouldn't really need to check, just think:
a = 6
b = 2
c = 4
a*b/c = 3
(a*b)/c = 3
a*(b/c) = 3
![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
cool dude
![](http://www.taylorstrategicmarketing.com/images/king.jpg)
|
Posted: Wed Jan 04, 2006 10:31 am Post subject: (No subject) |
|
|
[Gandalf] wrote: There's no edit button in any help forum.
![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif)
actually i believe there is an edit button in the turing help forum because i posted there and then i edited my posts. secondly yes i know bedmas so u don't have to teach me it but thanks anyways ![Smile Smile](images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: Wed Jan 04, 2006 4:52 pm Post subject: (No subject) |
|
|
Actually, there is no edit button there either.
Now let's try to keep this topic on topic. ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Brightguy
![](http://compsci.ca/v3/uploads/user_avatars/527435178485ad4c287538.gif)
|
Posted: Wed Jan 04, 2006 10:36 pm Post subject: Re: Program Crash |
|
|
What you posted looks ok, if the loop isn't ending make sure cboDivDigits.Text > 0 and that Dividend has more factors than the excluded ones. |
|
|
|
|
![](images/spacer.gif) |
|