Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple VB - COM problem

Status
Not open for further replies.

RushiShroff

Programmer
Jan 23, 2002
216
IN
Here is my Class Module
Project Name : CheckYear
Class Name : LeapYear

Code:
Option Explicit
'Function to return if the specified year is a leap year
Public Function IsLeapYear(yr As Variant) As Boolean
    'If year is divisible by 4 and not divisible by 100, or
    'It is divisible by 400, it is a leap year
    If (yr Mod 4 = 0 And yr Mod 100 <> 0) Or yr Mod 400 = 0 Then
        IsLeapYear = True
    Else
        IsLeapYear = False
    End If
End Function

Here is my standard EXE
Project Name : TestProject

Code:
Dim MyYear As New CheckYear
Private Sub Command1_Click()
    MsgBox MyYear.IsLeapYear(&quot;1999&quot;)
End Sub
Whle clicking Run Time F5,it doesnt take me to runtime window.Rather sometimes it shows me Immediate window.

Rushi Shroff
 
Hi.

I may be wrong, but I think F8 will step though each line of code for you as it executes. At any time you can then type a command in the immediate window to display a variable etc.

Vern
 
Rushi -

What kind of project is your VB project? ActiveX DLL? ActiveX EXE? Regular EXE?

If it's an ActiveX DLL then you'll have to create a temp regular EXE project to instantiate it via a CreateObject call.

Chip H.
 
The code in your Standard exe should be

'The difference is in the first line
Dim MyYear As New CheckYear.LeapYear
Private Sub Command1_Click()
MsgBox MyYear.IsLeapYear(&quot;1999&quot;)
End Sub


This will work if your project has a reference to your CheckYear component. Check Project>Reference.
If your component hasn't been compiled yet and you're still testing and debugging. Add your standard exe project to your COM project to form a project group. Then add the reference.
By the way, to test for a leap year you only just have to check that its divisible by 4. (ie if yr mod 4 = 0)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top