# visual basic 6.0 simple age calculator

• (2 Pages)
• 1
• 2

## 23 Replies - 67713 Views - Last Post: 02 July 2011 - 01:57 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=86884&amp;s=b6827ca3dec99dbffda33fee4cd29783&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #16 luigiplumbersinc

Reputation: 4
• Posts: 82
• Joined: 16-February 09

## Re: visual basic 6.0 simple age calculator

Posted 20 February 2009 - 05:01 AM

naser123456, on 20 Feb, 2009 - 03:45 AM, said:

hi lumbersinc thank you very mach in advance finaly i could do it and i have finished with my project but i have another project to do if i get any problem i'll tell you .

best regards
good luck

I'm glad i could help <3 goodluck with your next project... atm i umm cant really move off my computer... so hopefully i will be able to respond immediantly... of course i do sleep... and i live in australia

### #17 naser123456

Reputation: 0
• Posts: 16
• Joined: 11-December 08

## Re: visual basic 6.0 simple age calculator

Posted 20 February 2009 - 09:53 AM

hi lumbersinc

this is my next project topic:
Write a Visual Basic program that asks the user to input two different numbers (e.g. using text boxes). The program then prints all numbers between the two entered values.

so far i have this :
```Private Sub cmdprint_Click()
Dim a As Long
Dim b As Long
a = txtnumber1
b = txtNumber2

For outernumber = a To b
For innernumber = a + 1 To b - 1
Print innernumber
Next innernumber
Next outernumber
End Sub

```

this is working but the problen is when i put negative number in txt1 and txt2 if the the negative number which i pu in txt1 is smaller than negative number in txt2 it won't give me a result ?

im stuck here i will appreciate if you could help me .
many thanks

### #18 luigiplumbersinc

Reputation: 4
• Posts: 82
• Joined: 16-February 09

## Re: visual basic 6.0 simple age calculator

Posted 20 February 2009 - 10:36 AM

naser123456, on 20 Feb, 2009 - 08:53 AM, said:

hi lumbersinc

this is my next project topic:
Write a Visual Basic program that asks the user to input two different numbers (e.g. using text boxes). The program then prints all numbers between the two entered values.

so far i have this :
```Private Sub cmdprint_Click()
Dim a As Long
Dim b As Long
a = txtnumber1
b = txtNumber2

For outernumber = a To b
For innernumber = a + 1 To b - 1
Print innernumber
Next innernumber
Next outernumber
End Sub

```

this is working but the problen is when i put negative number in txt1 and txt2 if the the negative number which i pu in txt1 is smaller than negative number in txt2 it won't give me a result ?

im stuck here i will appreciate if you could help me .
many thanks

well for one if the negative number is "smaller" in txt1 than that in txt2 its not really smaller its bigger so you shouldnt put in that input anyway. however the ABSOLUTE VALUE IS LARGER this is irrelevant so perhaps an if will solve all our problems

as for coding tips you have a useless for loop i have no idea why. it simply prints out the numbers more than once

also you should probably make a new topic dont want yo get into trouble do you? D:

```Dim a As Long
Dim b As Long
a = txtnumber1
b = txtNumber2

if a > b then
for index = b + 1 to a -1
print index
next index
else
for index = a + 1 to b -1
print index
next index
end if

```

### #19 naser123456

Reputation: 0
• Posts: 16
• Joined: 11-December 08

## Re: visual basic 6.0 simple age calculator

Posted 20 February 2009 - 08:22 PM

hi lumbersing

i hope you are alright and happy.
thankyou for the previous project code that you have told me previously. it work perfect. now i'm donig another one as fallow:

Write a Visual Basic program that allows the user to enter as many positive whole numbers as they wish, and to enter 0 to indicate they have finished. The program counts and displays the number of even values and the number of odd values entered by the user. Use the Mod operator to work out whether a number is even or odd

sofar i have this :
```Private Sub cmdresult_Click()

Dim a As Double

a = Val(InputBox("Enter a number (zero to quit):", "Input Loop"))

Do Until a = 0

a = Val(InputBox("Enter a number (zero to quit):", "Input Loop"))

Loop

```

it doesn't work at all could you help me to do this ? thank you very machhhhhhhhhhhhhhhh......

This post has been edited by Core: 20 February 2009 - 08:36 PM

### #20 luigiplumbersinc

Reputation: 4
• Posts: 82
• Joined: 16-February 09

## Re: visual basic 6.0 simple age calculator

Posted 22 February 2009 - 07:38 PM

```Private Sub cmdresult_Click()

Dim a As Double

a = Val(InputBox("Enter a number (zero to quit):", "Input Loop"))

Do Until a = 0

a = Val(InputBox("Enter a number (zero to quit):", "Input Loop"))

Loop

Exit 'This will quit when a = 0

```

but before you exit you need to display the ammount of odd and even numbers perhaps 2 counts would be appropriate

```dim oddCount as Integer
dim eventCount as Integer

```

then each time they enter a you check if its not 0
```if a <> 0 then
'Check if it odd or even and add to count
end if

```

do you understand?

### #21 honey_yhaz

Reputation: 0
• Posts: 12
• Joined: 23-February 09

## Re: visual basic 6.0 simple age calculator

Posted 23 February 2009 - 01:57 AM

naser123456, on 15 Feb, 2009 - 06:46 PM, said:

hi

actualy i have to do the simple age calculator programme in visual basic 6.0 that allows the user to enter two different date of birth and calculate their average age!!!!!!!!!!!!!!!!!!!!!!!!!!

it's very hard for me because i'm just a beignner and i can't handle this task. if anyone code help me i would really appriciate it.

many thanks

=================================================

hi...
i do have a code for a simple calculator.
you may choose on this...
but u must convert some codes for your program as age calculator...

### #22 naser123456

Reputation: 0
• Posts: 16
• Joined: 11-December 08

## Re: visual basic 6.0 simple age calculator

Posted 23 February 2009 - 04:49 AM

hi dear

hear you are :
```Private Sub cmdCalculate_Click()

If txtname1.Text = "" Or txtname2.Text = "" Or Txt3.Text = "" Or Txt4.Text = "" Then
MsgBox "Please complete all the fields", vbExclamation + vbOKOnly, "Error Message"
Else

c = (txtname1.Text)
d = (txtname2.Text)
bdate = Txt3.Text
curdate = Now
lblresult.Caption = Format(DateDiff("yyyy", bdate, curdate) + DateDiff("yyyy", adate, curdate)) / 2 & Space(1) & "years"
lblAverage = c & Space(1) & "and" & Space(1) & d & Space(1) & " have an average age of"
End If
End Sub

Dim c As String
Dim d As String
Dim e As String
Dim curdate As Date
Dim bdate As Date
End Sub

```

i hope it will help u
good luck

### #23 honey_yhaz

Reputation: 0
• Posts: 12
• Joined: 23-February 09

## Re: visual basic 6.0 simple age calculator

Posted 23 February 2009 - 05:25 PM

thanks!!

but i have finished it already this morning.
quite different with your codes but similar logic.

thanks!!!

check this out...
i just need to navigate this game on how i could let it go up, down, right, or left... just a navigation.

thanks again!!!

-yhaz

#### Attached File(s)

•  Pac.zip (107.01K)

### #24 razmehra

Reputation: 0
• Posts: 2
• Joined: 02-July 11

## Re: visual basic 6.0 simple age calculator

Posted 02 July 2011 - 01:57 PM

This is the my own way to Calculate the Actual age. See

```

'First: Draw A standard form with 6 text Boxes and a command 'button:

'TextBox1 (TxtDOB)
'TextBox2 (TxtCurrentDt)
'TextBox3 (TxtLeapDays)
'TextBox4 (TxtAge)
'TextBox5 (TxtAge2)
'TextBox6 (TxtAge3)

'Command Button (Command1)

Private Sub Command1_Click()
Dim DaysOfMonth(1 To 12) As Integer
Dim CDay, CMonth, CYear, BDay, BMonth, BYear As Integer
On Error Resume Next
CDay = Day(Format(Me.TxtCurrentDt, "DD/MM/YYYY"))
CMonth = Month(Format(Me.TxtCurrentDt, "DD/MM/YYYY"))
CYear = Year(Format(Me.TxtCurrentDt, "DD/MM/YYYY"))
BDay = Day(Format(Me.TxtDOB, "DD/MM/YYYY"))
BMonth = Month(Format(Me.TxtDOB, "DD/MM/YYYY"))
BYear = Year(Format(Me.TxtDOB, "DD/MM/YYYY"))
'DaysOfMonth(1) = 31: DaysOfMonth(2) = 28 + IIf((CYear Mod 4) = 0, 1, 0): DaysOfMonth(3) = 31: DaysOfMonth(4) = 30
DaysOfMonth(1) = 31: DaysOfMonth(2) = 28: DaysOfMonth(3) = 31: DaysOfMonth(4) = 30
DaysOfMonth(5) = 31: DaysOfMonth(6) = 30: DaysOfMonth(7) = 31: DaysOfMonth(8) = 31
DaysOfMonth(9) = 30: DaysOfMonth(10) = 31: DaysOfMonth(11) = 30: DaysOfMonth(12) = 31
SYr = BYear + IIf(BMonth <= 2, 0, 1)
EYr = CYear - IIf(CMonth >= 2, 0, 1)
c = 0
For t = BYear To CYear
If t Mod 4 = 0 Then c = c + 1
Next
Me.TxtLeapDays = c
If CDay < BDay Then
CDay = CDay + DaysOfMonth(CMonth): CMonth = CMonth - 1
End If
If CMonth < BMonth Then
CMonth = CMonth + 12: CYear = CYear - 1
End If
Aday = CDay - BDay: AMonth = CMonth - BMonth: AYear = CYear - BYear
Me.TxtAge = AYear & " Year " & AMonth & " Month " & Aday & " Days"
Me.TxtAge2 = AYear & " Year " & AMonth & " Month " & Aday + c & " Days"

If Aday + c >= DaysOfMonth(Month(Format(Me.TxtCurrentDt, "DD/MM/YYYY"))) Then
Aday = (Aday + c) - DaysOfMonth(Month(Format(Me.TxtCurrentDt, "DD/MM/YYYY"))): AMonth = AMonth + 1
Else
End If
If AMonth >= 12 Then AMonth = 0: AYear = AYear + 1
Me.TxtAge3 = AYear & " Year " & AMonth & " Month " & Aday & " Days"

End Sub
```