Solved: Visual basic 6.0 small correction please help

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

enda101

Thread Starter
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
MsgBox "Please enter valid criteria"


End If


While amount < 1000000
amount = amount + (amount * Raise)
years = years + 1
Wend
MsgBox ("You will become millionaire in " & years & " years")
End Sub
 
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?
 

enda101

Thread Starter
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.
 
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:
amount = amount + (amount * Raise)
to:
amount = amount + Text1.Text + (amount * Raise)
Now to try to explain it.
amount * raise
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:

Private Sub Command1_Click()
years = 0
salary = Text1.Text
gender = Combo1.Text
totalAmount = 0
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
MsgBox "Please enter valid criteria"
End If


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

enda101

Thread Starter
Joined
Feb 25, 2009
Messages
28
thanks Olive you where indeed right in the second one but i beat you to it :p. 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
thanks Ollie you where indeed right in the second one but i beat you to it :p. 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!
Your welcome. Glad you managed to solve it.

:)
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Members online

Top