VB 结构体初始化为零

devile55 2016-11-15 09:18:13
如题,VB中怎样将结构体 初始化为零,有这样一个函数?
...全文
709 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
devile55 2016-11-25
  • 打赏
  • 举报
回复
引用 4 楼 of123 的回复:
如果楼主是想将已经使用过的结构(VB 中称为用户定义类型)变量清空,只需让其等于一个新声明的同类结构变量。

' A user-defined type:
Private Type udtSomeType
SubVariableOne As Integer
SubVariableTwo As String
SubVariableThree As Long
End Type

' A couple of class-level user-defined type variables:
Private TypeVariableOne As udtSomeType
Private TypeVariableTwo As udtSomeType

' A method in the class:
Private Sub ResetData()
    Dim CleanTypeVariable As udtSomeType
    TypeVariableOne = CleanTypeVariable
    TypeVariableTwo = CleanTypeVariable
End Sub
上面哪个是用过的结构变量,哪个是新定义的?
舉杯邀明月 2016-11-15
  • 打赏
  • 举报
回复
引用 5 楼 Tiger_Zhao 的回复:
[quote=引用 3 楼 Chen8013 的回复:]VB6没有提供函数,可以用API: RtlZeroMemory  把指定的“内存区”清0。 RtlFillMemory  用某个指定的“字节值”填充指定的内存区。
不能这样做,成员是字符串、动态数组、对象时都会有问题。 还不如of123这样简单、安全。[/quote] 是的,成员包含“字符串、动态数组、对象”时,用4楼的方法很好,数据空间可以“立即释放”。 但用API清0时,程序“正常结束”时那些“数据空间”仍然会正常释放。 当然用API清0,最好还是只用于“成员全是数值类型”的情况下。
赵4老师 2016-11-15
  • 打赏
  • 举报
回复
4楼确确实实是高人啊!Orz
Tiger_Zhao 2016-11-15
  • 打赏
  • 举报
回复
引用 3 楼 Chen8013 的回复:
VB6没有提供函数,可以用API: RtlZeroMemory  把指定的“内存区”清0。 RtlFillMemory  用某个指定的“字节值”填充指定的内存区。
不能这样做,成员是字符串、动态数组、对象时都会有问题。 还不如of123这样简单、安全。
of123 2016-11-15
  • 打赏
  • 举报
回复
如果楼主是想将已经使用过的结构(VB 中称为用户定义类型)变量清空,只需让其等于一个新声明的同类结构变量。

' A user-defined type:
Private Type udtSomeType
SubVariableOne As Integer
SubVariableTwo As String
SubVariableThree As Long
End Type

' A couple of class-level user-defined type variables:
Private TypeVariableOne As udtSomeType
Private TypeVariableTwo As udtSomeType

' A method in the class:
Private Sub ResetData()
    Dim CleanTypeVariable As udtSomeType
    TypeVariableOne = CleanTypeVariable
    TypeVariableTwo = CleanTypeVariable
End Sub
舉杯邀明月 2016-11-15
  • 打赏
  • 举报
回复
VB6没有提供函数,可以用API: RtlZeroMemory  把指定的“内存区”清0。 RtlFillMemory  用某个指定的“字节值”填充指定的内存区。
Tiger_Zhao 2016-11-15
  • 打赏
  • 举报
回复
结构体创建时VB会自动“清零”,方便吧!
舉杯邀明月 2016-11-15
  • 打赏
  • 举报
回复
在VB6中,成员的“默认值”都是“0”的。

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧