LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default I need help with this program written in Visual Basic for Excel 2007.

Dear Programmers,
I wanted to run a program that is on page 49 of 'Excel VBA Programming for the absolute beginner'

Though I am sure I have copied the text of it, it doesn't run, and takes exception to the first line, also subsequent lines of code appear in red, I think this is the 'knock on' effect of something amiss in the earlier part of the program, but I can't see where.

Thank you for reading.

Yours
Simon

Option Explicit
Private Sub cmdCalculate_Click()
Dim username As String
Dim yrPassed As Single, moPassed As Single, dayPassed As Single
Dim hrPassed As Single, minPassed As Single, secPassed As Single
Dim userBday As Date, curDate As Date
Dim bDate As String, bMonth As String
Dim bDay As Integer, bYear As Integer
Const SECSPERMIN = 60, MINSPERHOUR = 60
Const HOURSPERDAY = 24, DAYSPERYEAR = 365.25
Const PHYSICAL = 23, EMOTIONAL = 28, INTELLECTUAL = 33
Const PI = 3.14159265358979
'---------------------------
'Get the user's name and birth date.
'---------------------------
username = LCase(InputBox("What is your name?", "Name"))
userBday = DateValue(InputBox("When is your birthday? (month/day/year)", _"Birth Date"))
'--------------------------------
'Calculate length of life in different units.
'-------------------------------
curDate = Now 'Gets current time and date.
secPassed = DateDiff("s", userBday, curDate)
minPassed = secPassed / SECSPERMIN
hrPassed = minPassed / MINSPERHOUR
dayPassed = hrPassed / HOURSPERDAY
yrPassed = dayPassed / DAYSPERYEAR
moPassed = yrPassed * 12
'--------------------------------
'Get users birthday in proper format.
'----------------------------------
bDate = Format(userBday, "dddd")
bMonth = Format(userBday, "mmmm")
bDay = Day(userBday)
bYear = Year(userBday)
'---------------------------------
'Format user's name.
'---------------------------------
username = StrConv(username, vbProperCase)
'-----------------------------------
'Enter time values into appropriate cells in worksheet.
'-----------------------------------------
Range("G28").Value = Trim(Left(username, InStr(1, username, " ")))
Range("H28").Value = Trim(Right(userName, _ Len(userName) - Len(Range("G28").Value)))
Range("G29").Value = bMonth & " " & Str(bDay)
Range("H29").Value = bYear & "(" & bDate & ")"
Range("G30").Value = yrPassed
Range("G31").Value = moPassed
Range("G32").Value = dayPassed
Range("G33").Value = hrPassed
Range("G34").Value = minPassed
Range("G35").Value = secPassed
'------------------------------------
'Formula for day of cycle.
'-----------------------------------
Range("A38").Value = (Range("G32").Value / PHYSICAL - _
Int(Range("G32").Value / PHYSICAL)) * PHYSICAL

Range("A39").Value = (Range("G32").Value/EMOTIONAL-_
Int(Range("G32").Value/EMOTIONAL))*EMOTIONAL

Range("A40").Value = (Range("G32").Value/INTELLECTUAL -_
Int(Range("G32").Value/INTELLECTUAL))* INTELLECTUAL
'------------------------------------------------------
'Formula for magnitude of biorhythm.
'------------------------------------------------------
Range("B38").Value = Sin((Range("G32").Value/PHYSICAL-_
Int(Range("G32").Value/PHYSICAL))*_
PHYSICAL*2 * PI/PHYSICAL)
Range("C39").Value = Sin((Range("G32").Value/EMOTIONAL-_
Int(Range("G32").Value/EMOTIONAL))*_
EMOTIONAL *2 *PI/EMOTIONAL)
Range("D40").Value = Sin((Range("G32").Value/INTELLECTUAL -_
Int(Range("G32").Value/INTELLECTUAL))*_
INTELLECTUAL *2*PI/INTELLECTUAL)
End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
On opening program get MS Visual Basic error KT Excel Discussion (Misc queries) 1 February 25th 09 01:05 AM
A simple visual basic program wilchong via OfficeKB.com New Users to Excel 2 October 22nd 08 09:16 AM
Enabling Visual Basic in Excel 2007 RandyS Excel Discussion (Misc queries) 1 March 31st 07 11:10 AM
how do you read a visual basic program codes jaydee Excel Programming 1 February 9th 06 12:00 PM
PLEASE READ IF YOU PROGRAM: Help Continue Visual Basic Harlan Grove Excel Programming 104 December 1st 05 09:30 PM


All times are GMT +1. The time now is 01:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"