Vb.net Can';在VB中不使用类型
下面的代码有什么问题吗?它在Vb.net Can';在VB中不使用类型,vb.net,winforms,Vb.net,Winforms,下面的代码有什么问题吗?它在Form_Load()行失败,并对此进行投诉 Private Sub Form_Load() Type Human Name As String End Type Dim stu As Student With Human: .Name = "Someone" End With Debug.Print ("Name: " & stu.Name) End Sub 您有两个选
Form_Load()
行失败,并对此进行投诉
Private Sub Form_Load()
Type Human
Name As String
End Type
Dim stu As Student
With Human:
.Name = "Someone"
End With
Debug.Print ("Name: " & stu.Name)
End Sub
您有两个选择:
1.
创建一个新类
Private Class Human
Public Name As String
End Class
(显然,最好将名称包装在公共属性中,但为简单起见,将其公开为公共变量更容易。)
2.
创建新结构:
Structure Human
Dim Name As String
End Structure
注意需要注意的是,这两个选项都必须在函数外部执行,而不是在Form_Load函数中执行关键字不再是Type;现在是结构。类型在VB6和更早版本中使用,但在.NET中没有使用。您可以做得更好,而不是VB.NET中不支持“投诉”类型关键字。VB.NET使用Structure关键字-和VB6 struct-