如何在同一个VB项目中的不同类或表单中使用该模块?

huangapple go评论100阅读模式
英文:

How to use the module in a different class or form in same vb project?

问题

我需要在同一个VB项目中的不同类中使用已创建的数据库连接模块。

我需要代码块来在同一项目的另一个类中调用模块。我想知道如何将该模块与同一VB.NET文件中的新类连接起来。

英文:

I need to use already created module of database connection code in a different class in same vb project

I need the code block to recall a module in another class of the same project. I want to know how to connect the module with a new class in the same vb.net file.

答案1

得分: 1

假设您在App_Code文件夹中有一个名为SomeModule.vb的模块:

  1. Public Module SomeClass
  2. Public Function DoSomething(OneThing As String, AnotherThing As Integer) As String
  3. End Function
  4. End Module

您应该能够在项目的任何地方引用此代码:

  1. Dim NewString As String = DoSomething("一件事", 5)

对于任何Sub过程,您也可以这样做。

英文:

Suppose you have a module SomeModule.vb in your App_Code folder:

  1. Public Module SomeClass
  2. Public Function DoSomething(OneThing As String, AnotherThing As Integer) As String
  3. End Function
  4. End Module

You should be able to reference this code anywhere in your project:

  1. Dim NewString As String = DoSomething("A thing", 5)

You can do the same for any Sub procedures.

huangapple
  • 本文由 发表于 2023年6月26日 23:34:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76558175.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定