Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
On opening program get MS Visual Basic error | Excel Discussion (Misc queries) | |||
A simple visual basic program | New Users to Excel | |||
Enabling Visual Basic in Excel 2007 | Excel Discussion (Misc queries) | |||
how do you read a visual basic program codes | Excel Programming | |||
PLEASE READ IF YOU PROGRAM: Help Continue Visual Basic | Excel Programming |