Help on Creating Class in VB6

Reply   View First Unread View First Unread

Join Date: Jul 2005
Posts: 2
Reputation: lordnikotine is an unknown quantity at this point 
Solved Threads: 0
lordnikotine lordnikotine is offline Offline
Newbie Poster

Help on Creating Class in VB6

 
0
  #1
Jul 7th, 2005
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!
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 508
Reputation: techniner is an unknown quantity at this point 
Solved Threads: 19
techniner techniner is offline Offline
Posting Pro

Re: Help on Creating Class in VB6

 
0
  #2
Jul 7th, 2005
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, 530 views)
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 2
Reputation: lordnikotine is an unknown quantity at this point 
Solved Threads: 0
lordnikotine lordnikotine is offline Offline
Newbie Poster

Re: Help on Creating Class in VB6

 
0
  #3
Jul 7th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 508
Reputation: techniner is an unknown quantity at this point 
Solved Threads: 19
techniner techniner is offline Offline
Posting Pro

Re: Help on Creating Class in VB6

 
0
  #4
Jul 7th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Help on Creating Class in VB6

 
0
  #5
Jul 7th, 2005
http://www.officecomputertraining.co...ges/page42.asp is a pretty good tutorial about classes in VB. Hopefully it will help some.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1
Reputation: coolsun03 is an unknown quantity at this point 
Solved Threads: 0
coolsun03 coolsun03 is offline Offline
Newbie Poster

Re: Help on Creating Class in VB6

 
0
  #6
Dec 22nd, 2008
Originally Posted by techniner View Post
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 1
Reputation: sbs_1993 is an unknown quantity at this point 
Solved Threads: 0
sbs_1993 sbs_1993 is offline Offline
Newbie Poster

Class module

 
0
  #7
1 Day Ago
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...
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 227
Reputation: AndreRet is an unknown quantity at this point 
Solved Threads: 31
AndreRet AndreRet is offline Offline
Posting Whiz in Training
 
0
  #8
1 Day Ago
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 -

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.
Please mark questions as answered when done.

Be the ONE!!!
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC