| | |
Help on Creating Class in VB6
![]() |
•
•
Join Date: Jul 2005
Posts: 2
Reputation:
Solved Threads: 0
Hello.
Could someone help me on how to create classes in VB6?
I need to create a class that would enable me to add 2 numbers then show the sum... simple enough? but im having a hard time looking for tutes out there. I could easily learn with some examples...
A walkthrough would be greatly appreciated. Links will also be a great help.
Thanks in advance!
Could someone help me on how to create classes in VB6?
I need to create a class that would enable me to add 2 numbers then show the sum... simple enough? but im having a hard time looking for tutes out there. I could easily learn with some examples...
A walkthrough would be greatly appreciated. Links will also be a great help.
Thanks in advance!
•
•
Join Date: May 2005
Posts: 508
Reputation:
Solved Threads: 19
See the Attached file.
Study the code and read the comments and it will walk you through creating a class
Study the code and read the comments and it will walk you through creating a class
•
•
Join Date: Jul 2005
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by techniner
See the Attached file.
Study the code and read the comments and it will walk you through creating a class
Here are some more clarifications(if that's what it should be called) or inquiry:
Do i always have to put my classes in a class module? Or can i have declare classes in a module? my prof. told me u can declare a class (vb6) in a module... i had show him a program i made which was like the one you gave me but he told me to make a class in a module...
Heres my program:
frmMain.frm
has 3 textboxes(txtrate, txtHours, txtPay) and a command button (cmdCompute)
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Public gf_MyPay As New CCompPay Private Sub cmdCompute_Click() If txtHours.Text <> "" And txtRate.Text <> "" Then If CInt(txtHours.Text) > 0 And CDbl(txtRate.Text) > 0 Then gf_MyPay.NoHours = CInt(txtHours.Text) gf_MyPay.Rate = CDbl(txtRate.Text) txtPay.Text = gf_MyPay.Pay Else MsgBox "Error: Zero Value Found...", vbOKOnly, "May Error po" End If Else MsgBox "Error: Blank information Found!!!", vbOKOnly, "May Error po" End If End Sub
and my class module:
CCompPay.cls
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private m_NoHours As Integer Private m_Rate As Double Private m_Pay As Double Public Property Get NoHours() As Integer NoHours = m_NoHours End Property Public Property Let NoHours(ByVal iNewValue As Integer) m_NoHours = iNewValue End Property Public Property Get Rate() As Double Rate = m_Rate End Property Public Property Let Rate(ByVal dNewValue As Double) m_Rate = dNewValue ShowPay End Property Private Sub ShowPay() m_Pay = m_NoHours * m_Rate End Sub Public Property Get Pay() As Double Pay = m_Pay End Property Public Property Let Pay(ByVal dNewValue As Double) m_Pay = dNewValue End Property
Is this correct? i does work but my professor told me it was not a class... im a bit confused about it. its the only way i know how to create a class in VB6.
any enlightment about this?
Thanks again
•
•
Join Date: May 2005
Posts: 508
Reputation:
Solved Threads: 19
Ahh, Ok...
OK what he is saying to do is add module.bas
Decalere your code a s a function...
So when you goto command_button1 you can say
fucntion1()
and it will run the code.
Reason being is that now you can call function1() throughtout your entire project.
So you take that code turn it into a function and stick it in a module.
Well in this case I am saying function but yo ucan make a class this way as
well...
The genral idea your prof is saying is to be able to ref class or fucntion throughout the entire project through a single module
OK what he is saying to do is add module.bas
Decalere your code a s a function...
So when you goto command_button1 you can say
fucntion1()
and it will run the code.
Reason being is that now you can call function1() throughtout your entire project.
So you take that code turn it into a function and stick it in a module.
Well in this case I am saying function but yo ucan make a class this way as
well...
The genral idea your prof is saying is to be able to ref class or fucntion throughout the entire project through a single module
http://www.officecomputertraining.co...ges/page42.asp is a pretty good tutorial about classes in VB. Hopefully it will help some.
![]() |
Similar Threads
- USING CLASSES in VB6 (Visual Basic 4 / 5 / 6)
- creating a class and declaring objects (C++)
- need help in creating class string (C++)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Is It possible to change the original caption of the button permanently ?
- Next Thread: Goyal
| Thread Tools | Search this Thread |
* 6 2007 access activex add age basic beginner birth bmp calculator cd cells.find click client code college connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit excel excelmacro file filename form header iamthwee image inboxinvb internetfiledownload listbox listview liveperson login looping microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading refresh remotesqlserverdatabase report save search sendbyte sites sql sql2008 sqlserver subroutine tags time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






