如題,VB中怎樣將結構體 初始化為零,有這樣一個函式?
uj5u.com熱心網友回復:
在VB6中,成員的“默認值”都是“0”的。
uj5u.com熱心網友回復:
結構體創建時VB會自動“清零”,方便吧!uj5u.com熱心網友回復:
VB6沒有提供函式,可以用API:RtlZeroMemory 把指定的“記憶體區”清0。
RtlFillMemory 用某個指定的“位元組值”填充指定的記憶體區。
uj5u.com熱心網友回復:
如果樓主是想將已經使用過的結構(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
uj5u.com熱心網友回復:
不能這樣做,成員是字串、動態陣列、物件時都會有問題。
還不如of123這樣簡單、安全。
uj5u.com熱心網友回復:
4樓確確實實是高人啊!Orzuj5u.com熱心網友回復:
是的,成員包含“字串、動態陣列、物件”時,用4樓的方法很好,資料空間可以“立即釋放”。
但用API清0時,程式“正常結束”時那些“資料空間”仍然會正常釋放。
當然用API清0,最好還是只用于“成員全是數值型別”的情況下。
uj5u.com熱心網友回復:
如果樓主是想將已經使用過的結構(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
上面哪個是用過的結構變數,哪個是新定義的?
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/65399.html
標籤:VB基礎類
