|
-
Jan 13th, 2003, 05:23 PM
#1
Thread Starter
Addicted Member
Sub Classes?
I don't know how to do this, but this is what I want to do in code:
Code:
Dim oWeek as new FiscalWeek(iWeekNumber, iYearNumber)
iWeek = oWeek.CurrentWeek.WeekNumber
iYear = oWeek.CurrentWeek.YearNumber
iNextWeek = oWeek.NextWeek.WeekNumber
iLastWeek = oWeek.NextWeek.YearNumber
I can "kinda" do it by making a class inside a class:
Code:
Public Class FiscalWeek
Private Shared iNextWeek As Integer
Private Shared iLastWeek As Integer
Private Shared iCurrentWeek As Integer
Private Shared iNextYear As Integer
Private Shared iLastYear As Integer
Public CurrentWeek As New cCurrentWeek()
Public NextWeek As New cNextWeek()
Class cCurrentWeek
Public ReadOnly Property WeekNumber() As Integer
Get
Return iCurrentWeek
End Get
End Property
Public ReadOnly Property YearNumber()
Get
Return iCurrentYear
End Get
End Property
End Class
Public Class cNextWeek
Public ReadOnly Property WeekNumber() As Integer
Get
Return iNextWeek
End Get
End Property
Public ReadOnly Property YearNumber()
Get
Return iNextYear
End Get
End Property
This was working pretty much, but I've found when I created two seperate instances of oWeek the Current week gets changed in both when I change it in one. it dosn't make sense to me, but I must be doing this wrong, what is the propper way to have a "nested property"?
Last edited by Dmyze; Jan 13th, 2003 at 05:35 PM.
-Daryl
"Two More Rolls of Duct tape, and the world is mine!"
VB.NET Guru
-
Jan 13th, 2003, 06:22 PM
#2
Shared will share the same data for all instances which is not what you want. Try something along this line:
VB Code:
Public Class FiscalWeek
Private _CurrentWeek As New SubWeek()
Private _NextWeek As New SubWeek()
Public Property CurrentWeek() As SubWeek
Get
Return _CurrentWeek
End Get
Set(ByVal Value As SubWeek)
_CurrentWeek = Value
End Set
End Property
Public Property NextWeek() As SubWeek
Get
Return _NextWeek
End Get
Set(ByVal Value As SubWeek)
_NextWeek = Value
End Set
End Property
End Class
Public Class SubWeek
Private _WeekNumber As Integer
Private _YearNumber As Integer
Public ReadOnly Property WeekNumber() As Integer
Get
Return _WeekNumber
End Get
End Property
Public ReadOnly Property YearNumber()
Get
Return _YearNumber
End Get
End Property
Public Sub New()
End Sub
Public Sub New(ByVal wkNum As Integer, ByVal yrNum As Integer)
_WeekNumber = wkNum
_YearNumber = yrNum
End Sub
End Class
-
Jan 13th, 2003, 06:22 PM
#3
Fanatic Member
if i understand what you are trying to do try this code for the class
Code:
Public Class returnDates
Dim currentWeek As Integer
Dim currentYear As Integer
Public Sub New(ByVal tempWeek As Integer, ByVal tempYear As Integer)
currentWeek = tempWeek
currentYear = tempYear
End Sub
Public Function returnCurrentWeek() As Integer
Return currentWeek
End Function
Public Function returnCurrentYear() As Integer
Return currentYear
End Function
Public Function returnNextWeek() As Integer
Return currentWeek + 1
End Function
Public Function returnNextYear() As Integer
Return currentYear + 1
End Function
End Class
and then use this code to create class and call functions
Code:
Dim a As New returnDates(1, 2003)
Dim b As New returnDates(10, 2010)
Dim temp As Integer
temp = a.returnCurrentWeek
temp = a.returnCurrentYear
temp = a.returnNextWeek
temp = a.returnNextYear
temp = b.returnCurrentWeek
temp = b.returnCurrentYear
temp = b.returnNextWeek
temp = b.returnNextYear
hope i got it and this helps!
Nick
-
Jan 13th, 2003, 07:26 PM
#4
Thread Starter
Addicted Member
That is where I started, but I have so many properties that I want to add to the weeks like, start date, end date, weeknumber, year number, that it seems to me that it would make sense to have it grouped together.
ie:
oWeek.CurrentWeek.YearNumber
oWeek.CurrentWeek.WeekNumber
oWeek.CurrentWeek.StartDate
oWeek.CurrentWeek.EndDate
and then that repeted for LastWeek, NextWeek, and LastYear.
I did figure out how to get it thead safe, it does everything i want it to do except when you referance it oWeek. you get the oWeek.cCurrentWeek and I'd like that to be invisible. If I make the sub class private, it won't let me use the "Public CurrentWeek As cCurrentWeek"
Code:
Public Class FiscalWeek
Public CurrentWeek As cCurrentWeek
Public NextWeek As cNextWeek
Public LastWeek As cLastWeek
Public LastYear As cLastYear
Public Sub New(ByVal WeekNumber As Integer, ByVal YearNumber As Integer, ByVal sSQLSP As String)
...
CurrentWeek = New cCurrentWeek(WeekNumber, YearNumber, cn)
...
End Sub
Class cCurrentWeek
Private m_Week As Integer
Private m_Year As Integer
Private m_Start As Date
Private m_End As Date
Sub New(ByVal iWeek As Integer, ByVal iYear As Integer, ByVal cn As SqlConnection)
m_Week = iWeek
m_Year = iYear
FindDates(iWeek, iYear, cn)
End Sub
Private Sub FindDates(ByVal iWeek As Integer, ByVal iYear As Integer, ByVal cn As SqlConnection)
..
End Sub
Public ReadOnly Property WeekNumber() As Integer
Get
Return m_Week
End Get
End Property
Public ReadOnly Property YearNumber()
Get
Return m_Year
End Get
End Property
Public ReadOnly Property StartDate() As Date
Get
Return m_Start
End Get
End Property
Public ReadOnly Property EndDate() As Date
Get
Return m_End
End Get
End Property
End Class
End Class
-Daryl
"Two More Rolls of Duct tape, and the world is mine!"
VB.NET Guru
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|