Discussion in 'Software Development' started by enda101, Apr 23, 2010.

Not open for further replies.

Joined:
Feb 25, 2009
Messages:
28
hey guys i got a huge problem. i have written code and i just cant get it to work so i said i would ask the pro's.
so i have to write a code that counts how many years it takes for a person to become a millionaire. the person has to input their pay and there is a variable of being male or female. males get an increase of 8% a year and females get 5% (i didnt write it my female tutor did)
i have a textbox to put in the amount of money you earn this year
then a combo box with male or female.
then a command button and i wrote the code for it. i will leave at the end.
seriously i have been shifting through this code for 4 days now and i just dont see where i am going wrong. its probably the lack of sleep but i have deadlines so ya know. here is my code. any help would be reallly appreciated. all it normally needs is a fresh pair of eyes and i would be forever greatful.

Private Sub Command1_Click()
years = 0
amount = Text1.Text
gender = Combo1.Text
If Text1.Text = "" Then
MsgBox "fill in current pay"
Elseif
If gender = "Select One" Then
MsgBox "select gender"
Elseif
If gender = "Male" Then
Raise = 8 / 100
Elseif
If gender = "Female" Then
Raise = 5 / 100
Else

End If

While amount < 1000000
amount = amount + (amount * Raise)
years = years + 1
Wend
MsgBox ("You will become millionaire in " & years & " years")
End Sub

2. ### olliea95

Joined:
Nov 19, 2009
Messages:
84
It's been ages since I've worked in VB 6 but I think I might be able to work this one out. What is the exact error you are getting at compile time?

Joined:
Feb 25, 2009
Messages:
28
oh yes i forgot to add. i did 2 tests. for the first one i used 100000 and i got a result of i think 30 years for male and 48 for female then i did a test for 10000 and got a result of 60 and 95.... like i dont even understand how it would have calculated that.

4. ### olliea95

Joined:
Nov 19, 2009
Messages:
84
Ok, I think its just a problem with the maths. Can't get my head around it though :S

Right if you change:
to:
Now to try to explain it.
will calculate the actual raise, so currently you are just taking the amount and adding the raise, and not adding the salary.

Don't know if you followed that but its made sense to me. Hope it works.

Edit:
Come to think about it I think that might not work, give me 10 minutes just to think this through and I will post back.

------------------------------------------------------------------------------------------------------------------------------------------------------

Edit 2: Looked over it all again, and I have renamed a couple of variables to stop me from getting confused, and I have added a totalAmount variable, because what you were doing is looping until the pay was equal to a million. So essentially it is acting as if you were banking the yearly pay plus the raise and the totalAmount variable is the bank balance. I haven't got VB6 on this computer so I can't test, sorry. Here is the complete program:

Joined:
Feb 25, 2009
Messages:
28
thanks Olive you where indeed right in the second one but i beat you to it . really sorry i didnt close it before now but i only just solved it this afternoon and did not think off it. thank you so very much for the help though. massively appreciated!

Joined:
Nov 19, 2009
Messages:
84

As Seen On