教程中国
PHOTOSHOP CS9.0中文版 MAYA 8.5 FOR WINDOWS Corel Painter v9.0 Flash MX2004 中文版 Illustrator cs2 中文版
VC++6.0含sp6 中英文版 VB6.0 +sp6 简体中文版 Borland Delphi 7汉化版 MSDN for vb6.0中文版 Visual Studio 2005简体
教程中国下属 文件存储共享专家BIBIDU.COM 提供大型软件,教材,源码,电影,音乐,图书等下载 更多精品请点此进入
  您目前所在位置: 教程中国 >> 编程基地 >> VB >> 初识object-第一个object RSS订阅
初识object-第一个object
教程(视频,书籍)下载:  ASP.NET AutoCAD 数据库 C# ASP java photoshop 网页设计 delphi 3dmax Flash C++ VB 张孝祥 实例   更多请进入BIBIDU搜索
IT搜索引擎   
My first object!

So far we have discussed objects as controls in VB (the Textbox and RichTextBox - you should be remembering these by now!)

In this example, we注释:re going to make a different kind of object. When you make a control, it has a user interface (that means you can visually see something on the screen, such as the textbox itself). Another kind of object is one that doesn注释:t have a user interface, and we call this a DLL (of Dynamic Link Library if you want to impress your friends).

To make one of these, click File, New Project and select ActiveX DLL:



This makes a new project with one empty class module in it. On the properties pane, make sure that the Instancing property is set to 5 - MultiUse. This allows us to compile the DLL and expose the class module to other programs (such as the object browser (This is starting to get complicated! (Espically with all these brackets :)))

We only want this example to be simple, so why don注释:t we base it around the cheesy Hello World project we talked about earlier on.

Lets add a new method called SayHello that pops up a message box saying Hello World! on it.

But before you rush off to start coding. let me show you a useful tool that VB has. It注释:s called the VB Class Builder. To open it, click Project Add Class module and select VB Class Builder:



You注释:ll probably get a message box telling you that the project contains a class module not generated by the Class Builder, but just ignore it and press ok.

We want to add a new method, so click on Class1 and select File, New, Method. Enter a name as SayHello and click OK. You should now see the item SayHello in the right hand pane (contact me if you don注释:t, or simply scream :)

As that注释:s all we want, click File, Exit and Yes to update the project.

As you will see, we didn注释:t achieve much there! Two lines of procedure code - not much for all that faffying around. But as we continue through this series, you will get a handle on the uses of the Class Builder.

We only want a message box to show up, nothing too serious. Add this line of code:

Msgbox "Hello World!"
The procedure should look like this:

Public Sub SayHello()
    MsgBox "Hello World!"
End Sub
Time to build! Save the project, and a click File, Make Project1.DLL.

There you go! You注释:ve just complied your first object! (OK, so maybe this isn注释:t your first time, but who cares?)

Now all we need to do is test it. Lets add another project - File, Add Projcet, Standard EXE. (Uhh? How do we load up the object - it doesn注释:t appear under the components dialog box)

Good question (I dunno who asked it, but it was good :) Because a DLL is not a control, we need to make a reference to it (because we are not loading any kind of user interface)

So, click File, References and scroll down and select Project1:



(If it注释:s not there, click on the browse button and locate the Project1.DLL)

Click ok and your object is now loaded. Just to make sure, press F2 to load up the object browser and select Projec1 from the combo box. See the SayHello method there? Good.

Now lets do some cool coding and call the SayHello method:

- Add a declaration of the object:


Dim m_clsProject1 As Class1

- Now, under the Form_Load event, create the object:


Set m_clsProject1 = New Class1

And call the SayHello method:


m_clsProject1.SayHello

Run the project and see the message box appear! (If you get an error let me know and I will sort it out :)

Wow! Is that the time? I better be on my way for now, but next week I注释:ll come back to looking at what we have just done (creating objects and all that stuff) but for now, download the sample files:

Download the files!

And let me know what you thought of this article! (Remeber, click Post Feedback Now just below this text)

Have a nice week! (or was it Have a nice day? I注释:m losing my memory at the moment - more sleep required!)

C ya next week!
Sam

来源:upschool.cn
作者:
关键字:初识object,第一,object
发表日期:2006-12-20 18:14:56

网页显示有限 阅读全文请下载本文完整版WORD文档

上一篇:用Mid$命令超速字符串添加操作   下一篇:初识object-如何使用objects?


2009-1-10 9:09:36
本文的相类似文章
  • 第一次亲密接触网络防火墙
  • DIY第一课:了解主板上的各种插针
  • IE7第一个正式漏洞—弹窗URL欺诈
  • 3ds max 6.0 建模手册-第一章 MAX6.0的用户界面及基础知识
  • 3ds max 6.0 建模手册-第一章(2)认识主菜单
  • 连接数据库的第一步:C#与Oracle的连接
  • Oracle webserver中文介绍-第一章
  • oracle817视图中object_type的'Undefined'
  • 如何用grub引导非第一个硬盘上的windows系统
  • 关系型数据库:应用第一范式
  • 在学习中进步 在进步中成长 教程中国相随您的成长之路
    华腾联合科技股份有限公司版权所有
    广告联系:Rosibo@163.com