Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Custom Class In VBA


OK first off im used to Classes in C++, I read a few places and I am
trying my best to set up a Class in VBA although my syntax may be off
or something. Basically Im asking what i am doing wrong in trying to
pass a class variable and it doesnt like what I am trying to do.

here is my code for custom class -SSched
Option Explicit


Public NumWorkers As Integer
Public DaysOn As Integer
Public Daysoff As Integer
Public MinMan As Integer
Public UserCell As Variant
Public EndWeek As Boolean
Private Sub Class_Initialize()
UserCell = Array("G", "H", "I", "J", "K", "L", "M", "N", "O",
"P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "AA", "AB", "AC",
"AD", "AE", "AF", "AG", "AH", "AI", "AJ", "G")
End Sub

-
now here is the code when I try to call it

-Private Sub cmdCalcWD_Click()
Dim SSheet As SSched

SSheet.NumWorkers = Cells(3, "AP").Value - 1
SSheet.DaysOn = Cells(6, "AO").Value
SSheet.Daysoff = Cells(7, "AO").Value

cmdClear_Click
SetDays SSheet.NumWorkers, SSheet.DaysOn, SSheet.Daysoff, 2
End Sub-

the error I get when trying to set the vars is
- RUN-TIME ERROR '91':

OBJECT VARIABLE OR BLOCK VARIABLE NOT SET-

I dunno, am I calling it wrong? Also will I be able to pass the whole
variable through functions? Thanks in advance


--
Xiazer
------------------------------------------------------------------------
Xiazer's Profile: http://www.excelforum.com/member.php...o&userid=31581
View this thread: http://www.excelforum.com/showthread...hreadid=542055

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default Custom Class In VBA

Hi,

You need to create an instance of the object.

Dim SSheet As SSched

' create an instance of your class object
Set SSheet = New SSched

SSheet.NumWorkers = Cells(3, "AP").Value - 1
SSheet.DaysOn = Cells(6, "AO").Value
SSheet.Daysoff = Cells(7, "AO").Value

Cheers
Andy

Xiazer wrote:
OK first off im used to Classes in C++, I read a few places and I am
trying my best to set up a Class in VBA although my syntax may be off
or something. Basically Im asking what i am doing wrong in trying to
pass a class variable and it doesnt like what I am trying to do.

here is my code for custom class -SSched
Option Explicit


Public NumWorkers As Integer
Public DaysOn As Integer
Public Daysoff As Integer
Public MinMan As Integer
Public UserCell As Variant
Public EndWeek As Boolean
Private Sub Class_Initialize()
UserCell = Array("G", "H", "I", "J", "K", "L", "M", "N", "O",
"P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "AA", "AB", "AC",
"AD", "AE", "AF", "AG", "AH", "AI", "AJ", "G")
End Sub

-
now here is the code when I try to call it

-Private Sub cmdCalcWD_Click()
Dim SSheet As SSched

SSheet.NumWorkers = Cells(3, "AP").Value - 1
SSheet.DaysOn = Cells(6, "AO").Value
SSheet.Daysoff = Cells(7, "AO").Value

cmdClear_Click
SetDays SSheet.NumWorkers, SSheet.DaysOn, SSheet.Daysoff, 2
End Sub-

the error I get when trying to set the vars is
- RUN-TIME ERROR '91':

OBJECT VARIABLE OR BLOCK VARIABLE NOT SET-

I dunno, am I calling it wrong? Also will I be able to pass the whole
variable through functions? Thanks in advance



--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Custom Class In VBA


Thanks, it works like a charm now.


--
Xiazer
------------------------------------------------------------------------
Xiazer's Profile: http://www.excelforum.com/member.php...o&userid=31581
View this thread: http://www.excelforum.com/showthread...hreadid=542055

Reply
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
2003 - 2007 custom macro and custom button restore. Scott Sornberger Excel Discussion (Misc queries) 11 May 23rd 08 02:41 PM
Adding custom list and text boxes to the custom tool bar from Excel C API Mousam Excel Discussion (Misc queries) 0 August 7th 07 09:19 AM
Custom Class and Properties Rich_z[_30_] Excel Programming 4 July 12th 05 04:57 PM
Specify which method is default in custom class Bing Excel Programming 1 December 23rd 04 10:33 PM
RaiseEvent from a class contained in a 2nd class collection? Andrew[_16_] Excel Programming 2 January 6th 04 04:22 PM


All times are GMT +1. The time now is 12:06 AM.

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"