不熟悉VB,如有不妥的地方请包涵!
10余年的平原网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整平原建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“平原网站设计”,“平原网站推广”以来,每个客户项目都认真落实执行。
Public Class Stack
Dim aryData() As Integer
Sub New(ByVal Num As Integer)
Dim aryData(Num) As Integer
End Sub
Function Pop() As Integer
If (aryData.Length = 0) Then
Return 0
Else
Dim a As Integer
a = aryData(aryData.Length)
aryData(aryData.Length) = Convert.ToInt32(DBNull.Value)
Return a
End If
End Function
Sub Push(ByVal n As Integer)
For Each i As Integer In aryData
If (aryData(i) = Convert.ToInt32(DBNull.Value)) Then
aryData(i) = n
End
Else
Continue For
End If
Next
End Sub
Sub PrintStack()
For Each i As Integer In aryData
If (aryData(i) = Convert.ToInt32(DBNull.Value)) Then
End
Else
Print(aryData(i))
End If
Next
End Sub
End Class
代码已测试。
一、测试需要的INI文件。名称为“setinfo.ini”,存放路径为你解决方案里“Bin“文件夹的”Debug“文件夹里。
内容:
[Location]
pnlTime.Location.X=787
pnlTime.Location.Y=0
[TopMost]
Top=True
二、操作INI文件的类。新建一个类,类中内容为:
Public Class Class1
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _
( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Int32, _
ByVal lpFileName As String _
) As Int32
End Class
三、界面代码:
Imports System.IO 'for path
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
getINI()
End Sub
Private Sub getINI()
Dim iniclass As New Class1 '
Dim myBf As String 'get set_info 开辟存储的内存
myBf = New String(CChar(""), 256)
Dim myFN As String '配置文件的文件路径
myFN = Path.Combine(My.Application.Info.DirectoryPath, "setinfo.ini")
Dim myAN As String 'Application_NAME,也是Section名称
myAN = Me.TextBox1.Text
Dim myKN As String 'KEY_NAME,关键字名称
myKN = Me.TextBox2.Text
Class1.GetPrivateProfileString(myAN, myKN, "", myBf, myBf.Length, myFN) '调用读取INI文件的操作
TextBox3.Text = Microsoft.VisualBasic.Left(myBf, InStr(myBf, Chr(0)) - 1) '截取有用部分,有必要
End Sub
End Class
四、测试截图如下
Public Class Name1
Public Function fun1()
...
End Function
....
End Class
模块:相当于全局级变量。
类:可以实例化,继承等。
对于你这样的初学者来说,可以视作 模块变量=类的public shared变量。
最好的方法是:项目-添加-类-粘贴代码。
'这是数组的一个方法了,可是可以给数组定义扩展方法来实现这种形式。不过要给Item每个成员能动态生成相应方法,想不出其它简单点的办法,只能一个一个的添加扩展方法。
Namespace 测试
Public Class Item
Public Number() As String
Public Name As String
Public Symbol As String
Public Value As Single
Public Unit As String
Public Description As String
Public Remarks As String
End Class
Public Class XX
Public tty() As Item
Public Sub New()
tty(0).Name = "Women"
tty(0).Value = 198000
tty(1).Name = "temen"
tty.Name("temen").Value = 99999
End Sub
End Class
Public Module Module1
System.Runtime.CompilerServices.Extension() _
Public Function Name(ByVal she As Item(), ByVal key As String) As Item '定义扩展方法功能 在net.3.5前的版本像似没有。
For Each it In she
If it.Name = key Then
Return it
End If
Next
Return Nothing
End Function
End Module
End Namespace
其实就是结构体,如下面
Public Structure My_type
Public type_1 As Integer
Public type_2 As String
Public type_3 As Double
End Structure
当前标题:vb.net创建自己的类 vbnet createobject
URL链接:https://www.cdcxhl.com/article40/docjieo.html
成都网站建设公司_创新互联,为您提供虚拟主机、云服务器、微信小程序、商城网站、静态网站、外贸网站建设
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联