I need help using a class module - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

I need help using a class module

Here is a description of my last project. my comments mean that I do not have to put them in a class for example('Stays the same), or I could not get that line of code to work with my class for example('With mclsWindow

' Screen.ActiveForm.GetClass.SetFontBold = Not _

' Screen.ActiveForm.GetClass.SetFontBold



' Screen.ActiveForm.txtDisplay.SetFontBold = Not _

' Screen.ActiveForm.GetClass.SetFontBold

'End With.)





This my text Edit program. I want to use bold, Italic, FontSizes 12, 14, 18, Save, Open, SaveDataBase, and OpenDataBase in a Class. I also have to raise an event such as InvalidFileName. I have to give the user the ability to save and open their document to a database. SaveDataBase will be called for a save operation, and OpenDataBase will be called for an Open and fetch operation using DAO for DataBase access. several documents stored in the database. I have to use a unique key to associate with each document, and raise any event necessary to trap database errors.





Thank you for any help that you can provide.



' This is my MDIForm1



Option Explicit

Private mclsWindow As CWindow



Private Sub MDIForm_Load()

Set mclsWindow = New CWindow

End Sub



Public Function GetClass() As CWindow

Set GetClass = mclsWindow

End Function



Private Sub mnu12_Click()

Screen.ActiveForm.txtDisplay.FontSize = mnu12.Caption

End Sub



Private Sub mnu14_Click()

Screen.ActiveForm.txtDisplay.FontSize = mnu14.Caption

End Sub



Private Sub mnu18_Click()

Screen.ActiveForm.txtDisplay.FontSize = mnu18.Caption

End Sub



Private Sub mnuArrangeIcons_Click()

MDIForm1.Arrange vbArrangeIcons 'Stays the same

End Sub



Private Sub mnuBackground_Click()

CommonDialog1.Flags = cdlCCRGBInit 'Stays the same

CommonDialog1.ShowColor

Screen.ActiveForm.txtDisplay.BackColor = _

CommonDialog1.Color

End Sub



Private Sub mnuBold_Click()

'Set mclsWindow = New CWindow

'With mclsWindow

' Screen.ActiveForm.GetClass.SetFontBold = Not _

' Screen.ActiveForm.GetClass.SetFontBold



' Screen.ActiveForm.txtDisplay.SetFontBold = Not _

' Screen.ActiveForm.GetClass.SetFontBold

'End With

GetClass.SetFontBold = True

'Screen.ActiveForm.txtDisplay.FontBold = Not _

'Screen.ActiveForm.txtDisplay.FontBold

End Sub



Private Sub mnuCascade_Click()

MDIForm1.Arrange vbCascade 'Stays the same

End Sub



Private Sub mnuCopy_Click()

Clipboard.Clear 'Stays the same

Clipboard.SetText Screen.ActiveControl.SelText

End Sub



Private Sub mnuCut_Click()

Clipboard.Clear 'Stays the same

Clipboard.SetText Screen.ActiveControl.SelText

Screen.ActiveControl.SelText = ""

End Sub



Private Sub mnuExit_Click()

End 'Stays the same

End Sub



Private Sub mnuForeground_Click()

CommonDialog1.Flags = cdlCCRGBInit

CommonDialog1.ShowColor

Screen.ActiveForm.txtDisplay.ForeColor = _

CommonDialog1.Color

End Sub



Private Sub mnuItalic_Click()

Screen.ActiveForm.txtDisplay.FontItalic = Not _

Screen.ActiveForm.txtDisplay.FontItalic

End Sub



Private Sub mnuMaximizeAll_Click()

MDIForm1.WindowState = vbMaximized 'Stays the same

End Sub



Private Sub mnuMinimizeAll_Click()

MDIForm1.WindowState = vbMinimized 'Stays the same

End Sub



Private Sub mnuNew_Click()

Static TextEditCount As Long

Dim frm As Form

TextEditCount = TextEditCount + 1

Set frm = New frmChild

frm.Caption = "Text Edit " & TextEditCount

frm.Show

Set frm = Nothing



mnuPrint.Enabled = True

mnuAttributes.Enabled = True

mnuEdit.Enabled = True

End Sub



Private Sub mnuNormal_Click()

MDIForm1.WindowState = vbNormal 'Stays the same

End Sub

Private Sub mnuOpen_Click()

Dim File As String

With CommonDialog1

.DialogTitle = "Open"

.CancelError = False

.Filter = "All Files (*.*)|*.*"

.ShowOpen

If Len(.FileName) = 0 Then

Exit Sub

End If

File = .FileName

End With

Screen.ActiveForm.txtDisplay.LoadFile File

Screen.ActiveForm.Caption = File

End Sub



Private Sub mnuOpenDatabase_Click()

Dim File As String

With CommonDialog1

.DialogTitle = "Open"

.CancelError = False

.Filter = "Access databases|*.mdb|All files|*.*"

.ShowOpen

If Len(.FileName) = 0 Then

Exit Sub

End If

File = .FileName

End With

Screen.ActiveForm.txtDisplay.LoadFile File

Screen.ActiveForm.Caption = File

End Sub



Private Sub mnuPaste_Click()

Screen.ActiveControl.SelText = Clipboard.GetText

'Stays the same

End Sub



Private Sub mnuPrint_Click()

Printer.Print frmChild.Caption 'Stays the same

Printer.Print Screen.ActiveForm.txtDisplay.Text

Printer.EndDoc

End Sub



Private Sub mnuSave_Click()

Dim File As String

If Left$(Screen.ActiveForm.Caption, 8) = "Document" Then

With CommonDialog1

.DialogTitle = "Save"

.CancelError = False

.Filter = "All Files(*.*)|*.*"

.ShowSave

If Len(.FileName) = 0 Then

Exit Sub

End If

File = .FileName

End With

Screen.ActiveForm.txtDisplay.SaveFile File

Else

File = Screen.ActiveForm.Caption

Screen.ActiveForm.txtDisplay.SaveFile File

End If

End Sub



Private Sub mnuSaveAs_Click()

Dim File As String

If Screen.ActiveForm Is Nothing Then Exit Sub

With CommonDialog1

.DialogTitle = "Save As"

.CancelError = False

.Filter = "All Files(*.*)|*.*"

.ShowSave

If Len(.FileName) = 0 Then

Exit Sub

End If

File = .FileName

End With

Screen.ActiveForm.Caption = File

Screen.ActiveForm.txtDisplay.SaveFile File

End Sub



Private Sub mnuSaveDatabase_Click()

Dim File As String

If Left$(Screen.ActiveForm.Caption, 8) = "Document" Then

With CommonDialog1

.DialogTitle = "Save"

.CancelError = False

.Filter = "All Files(*.*)|*.*"

.ShowSave

If Len(.FileName) = 0 Then

Exit Sub

End If

File = .FileName

End With

Screen.ActiveForm.txtDisplay.SaveFile File

Else

File = Screen.ActiveForm.Caption

Screen.ActiveForm.txtDisplay.SaveFile File

End If

End Sub



Private Sub mnuSetCaption_Click()

frmChild.Caption = _

InputBox("Please Enter A New Caption") 'Stays the same

End Sub



Private Sub mnuTileHorizontal_Click()

MDIForm1.Arrange vbTileHorizontal 'Stays the same

End Sub



Private Sub mnuTileVertical_Click()

MDIForm1.Arrange vbTileVertical 'Stays the same

End Sub



Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)

Select Case Button.Key

Case "mnuNew"

Call mnuNew_Click

Case "mnuPaste"

Call mnuPaste_Click

Case "mnuCut"

Call mnuCut_Click

Case "mnuCopy"

Call mnuCopy_Click 'STAYS THE SAME

Case "mnuPrint"

Call mnuPrint_Click

Case "mnuOpen"

Call mnuOpen_Click

Case "mnuSave"

Call mnuSave_Click

End Select

End Sub



' This is frmChild



Option Explicit

Private mclsWindow As CWindow



Private Sub Form_Load()

Set mclsWindow = New CWindow

End Sub



Private Sub Form_Resize()

Me.txtDisplay.Height = Me.ScaleHeight 'Stays the same

Me.txtDisplay.Width = Me.ScaleWidth

End Sub



Public Function GetClass() As CWindow

Set GetClass = mclsWindow

End Function



' This is My class CWindow



Private mclsBold As Boolean

Private mclsItalic As Boolean

Private mclsFontSize As StdFont





Public Property Get SetFontBold() As Boolean

SetFontBold = mnuBold

End Property



Public Property Let SetFontBold(mnuBold As Boolean)

mnuBold = SetFontBold

End Property



Public Property Get SetFontItalic() As Boolean

SetFontItalic = mclsItalic

End Property



Public Property Let SetFontItalic(mclsItalic As Boolean)

mclsItalic = SetFontItalic

End Property



Public Property Get SetFontSize() As Variant

SetFontSize = mnu12

SetFontSize = mnu14

SetFontSize = mnu18

End Property



Public Property Let SetFontSize(ByVal vNewValue As Variant)

mnu12 = SetFontSize

mnu14 = SetFontSize

mnu18 = SetFontSize

End Property






Sign In or Register to comment.