943,717 Members | Top Members by Rank

Ad:
Jul 7th, 2005
0

Help on Creating Class in VB6

Expand Post »
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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lordnikotine is offline Offline
2 posts
since Jul 2005
Jul 7th, 2005
0

Re: Help on Creating Class in VB6

See the Attached file.

Study the code and read the comments and it will walk you through creating a class
Attached Files
File Type: zip readINI.zip (3.8 KB, 2979 views)
Reputation Points: 12
Solved Threads: 19
Posting Pro
techniner is offline Offline
521 posts
since May 2005
Jul 7th, 2005
0

Re: Help on Creating Class in VB6

Quote originally posted by techniner ...
See the Attached file.

Study the code and read the comments and it will walk you through creating a class
Thanks for the code!

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)
  1. Public gf_MyPay As New CCompPay
  2.  
  3. Private Sub cmdCompute_Click()
  4. If txtHours.Text <> "" And txtRate.Text <> "" Then
  5. If CInt(txtHours.Text) > 0 And CDbl(txtRate.Text) > 0 Then
  6. gf_MyPay.NoHours = CInt(txtHours.Text)
  7. gf_MyPay.Rate = CDbl(txtRate.Text)
  8. txtPay.Text = gf_MyPay.Pay
  9. Else
  10. MsgBox "Error: Zero Value Found...", vbOKOnly, "May Error po"
  11. End If
  12. Else
  13. MsgBox "Error: Blank information Found!!!", vbOKOnly, "May Error po"
  14. End If
  15. End Sub

and my class module:
CCompPay.cls
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private m_NoHours As Integer
  2. Private m_Rate As Double
  3. Private m_Pay As Double
  4.  
  5. Public Property Get NoHours() As Integer
  6. NoHours = m_NoHours
  7. End Property
  8.  
  9. Public Property Let NoHours(ByVal iNewValue As Integer)
  10. m_NoHours = iNewValue
  11. End Property
  12.  
  13. Public Property Get Rate() As Double
  14. Rate = m_Rate
  15. End Property
  16.  
  17. Public Property Let Rate(ByVal dNewValue As Double)
  18. m_Rate = dNewValue
  19. ShowPay
  20. End Property
  21.  
  22. Private Sub ShowPay()
  23. m_Pay = m_NoHours * m_Rate
  24. End Sub
  25.  
  26. Public Property Get Pay() As Double
  27. Pay = m_Pay
  28. End Property
  29.  
  30. Public Property Let Pay(ByVal dNewValue As Double)
  31. m_Pay = dNewValue
  32. 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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lordnikotine is offline Offline
2 posts
since Jul 2005
Jul 7th, 2005
0

Re: Help on Creating Class in VB6

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
Reputation Points: 12
Solved Threads: 19
Posting Pro
techniner is offline Offline
521 posts
since May 2005
Jul 7th, 2005
0

Re: Help on Creating Class in VB6

http://www.officecomputertraining.co...ges/page42.asp is a pretty good tutorial about classes in VB. Hopefully it will help some.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Dec 22nd, 2008
0

Re: Help on Creating Class in VB6

Click to Expand / Collapse  Quote originally posted by techniner ...
See the Attached file.

Study the code and read the comments and it will walk you through creating a class

hi,

this helped me a lot to understand class structure for vb6.

Thanks.
Mahavir Shah
Reputation Points: 10
Solved Threads: 0
Newbie Poster
coolsun03 is offline Offline
1 posts
since Dec 2008
Nov 22nd, 2009
0

Class module

Pls can you tell me what is class module how does it works and any references also about connecting oracle SQL plus and VB6 as i hve connected VB with SQl but when i insert any data in SQL in VB the data doesnt gets updated (i have used ADODC for connecting)
Pls help me out im having a project on this...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sbs_1993 is offline Offline
1 posts
since Nov 2009
Nov 22nd, 2009
0
Re: Help on Creating Class in VB6
sbs_1993, please do not "hijack" someone elses post. Start your own post in the forum, and we will try and help where we can. To answer your question on the steps needed, herewith -

Quote ...
Steps:
(1) Open a New Project in VB6 and click on the icon "ActiveX DLL"
This will open up and automatically put a class module in your
project.
(2) Click on Project and then onto Project1 properties.
(3) Change the Project Name to the name of your dll file.
Example (MyDll) Then click on ok.
(4) In the Properties window for Class1, change the Instancing
property to 6 - GlobalMultiUse.
(5) Put in your public functions in the coding window.
NOTE: Any function or sub that is public is what you will have
access to. If it is private, you cannot access these functions.
Only the code inside the dll can.
(6) After putting your public functions in, compile the dll.
NOTE: Make sure you have a copy of your new dll in the
"c:\windows\system" directory.
(7) Open up MS-DOS and change the directory to "c:\windows\system"
NOTE: This will register your new dll.
(8) Type in: regsvr32 c:\windows\system\MyDll.dll
NOTE: Where it says MyDll.dll, you would put in your dll filename.

**************************************************
That's it! you have created your dll.
Now it's time to access your functions.
**************************************************

(1) Close out of everything and start a new project in VB6.
Click on the icon "Standard EXE"
(2) Click on Project and then onto References.
(3) Find your dll name in the list, check it and click on ok.
(4) You will now have access to all your public functions and subs.
EXAMPLE: If you had a Public Function like below in your dll:
Public Function Hello()
MsgBox "Hello"
End Function

You could use this call from your standard exe below:

Private Sub Command1_Click()
Hello
End Sub

**************************************************
Dependancy Information. (Optional)
**************************************************

NOTE: Because your dll is new, VB6 does not have any dependancy information
on it. This information is what's used to create a setup for your
program.

(1) Rather than clicking on Standard Setup Package click on
Dependancy File in the Package and development wizard.
(2) Go through the steps and when it comes up saying that it could
not find any information on your dll, click on ok.
(DO NOT CHECK THE BOX NEXT TO IT!)
(3) After all the steps, it has created a .DEP file in the path
you told it to.
(4) Open this file in Notepad and copy the bottom part of the data
to the clipboard.
NOTE: The data will look like this:

[MyDll.dll <0009>]
Dest=$(WinSysPath)
Date=11/15/00
Time=10:21
Version=1.0.0.0

(5) You will need to copy this information to your VB6dep.ini file
NOTE: If you copied it to your clipboard, you can now paste it out
in the VB6dep.ini file.
NOTE: This file is usually located in:
C:\Program Files\Microsoft Visual Studio\VB98\Wizards\PDWizard\VB6dep.ini

(6) After copying that information into VB6dep.ini, save it.

***************************************************
That's It! You can now make all the setups you want
and VB6 will automatically register your dll file
in the users computer that you installed your program
to.
***************************************************
If you need more info, google it. There is plenty help and notes out there.
Reputation Points: 329
Solved Threads: 347
Senior Poster
AndreRet is offline Offline
3,700 posts
since Jan 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: form caption effects
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: transparent forms in vb6





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC