从课堂调用func [英] Call func from class

查看:62
本文介绍了从课堂调用func的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!我有一个Vb.net的新问题。现在我正在编写在新类中创建的函数。但后来我想在一些form1,2,3中的代码中使用它....我怎么能从form1引用这个函数?我已经尝试过form1这个:class1.MyFunction ......但它不起作用!

Hi everyone!!! I have a new problem with Vb.net. Now i''m writting the function that have been created in new class. But then i want to use it in a code in some form1, 2, 3.... How could i refer to this function from the form1? I''ve tried in form1 this: class1.MyFunction...but it doesn''t work!

推荐答案

除非函数是共享只能通过类实例访问,而不能通过类名访问。但如果它是共享,它就无法访问任何非共享类变量或方法。



所以如果你需要要使用类数据,您需要查找或创建类的实例:

Unless the function is Shared is can only be accessed via a class instance, not the class name. But if it is Shared it cannot access any non-shared class variables or methods.

So if you need it to work with class data, you need to either find or create an instance of your class:
Dim mc As New class1()
mc.MyFunction()


我已经解决了。



共享MyFunction(byval ...)as byte

.....

结束函数< br $>


必须定义为共享
I''ve solved it.

Shared MyFunction(byval...) as byte
.....
End Function

It must have been defined as Shared


这篇关于从课堂调用func的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆