比如我自定义了下面结构
Public Type UserDefinedTime
    year As Integer
    month As Byte
    day As Byte
    hour As Byte
    minute As Byte
    second As Byte
End Type有没有什么办法知道这个结构需要的字节数?

解决方案 »

  1.   

    不知道是否有那個函數可以知道數據類型的長度?下面是一些數據類型的長度 資料型態  儲存空間大小 範圍 
    Byte 1 個位元組 0 到 255 
    Boolean 2 個位元組 True 或 False 
    Integer  2 個位元組 -32,768 到 32,767 
    Long
    (long integer) 4 個位元組 -2,147,483,648 到 2,147,483,647 
    Single 
    (單精度浮點數) 4 個位元組 負數時從 -3.402823E38 到 -1.401298E-45;正數時從 1.401298E-45 到 3.402823E38 
    Double 
    (雙精度浮點數) 8 個位元組 負數時從 -1.79769313486232E308 到 
    -4.94065645841247E-324;正數時從4.94065645841247E-324 到 1.79769313486232E308 
    Currency 
    (大範圍的整數) 8 個位元組 從 -922,337,203,685,477.5808 到 922,337,203,685,477.5807 
    Decimal 14 個位元組 沒有小數點時為 +/-79,228,162,514,264,337,593,543,950,335,而小數點右邊有 28 位數時為 +/-7.9228162514264337593543950335;最小的非零值為 +/-0.0000000000000000000000000001。 
    Date 8 個位元組 January 1, 100 到 December 31, 9999 
    Object 4 個位元組 任何 Object 引用 
    String 
    (可變長度字串) 10 位元組加字串長度 0 到大約 20 億 
    String
    (固定長度字串) 字串長度 1 到大約 65,400 
    Variant
    (數值) 16 個位元組 任何數值,最大可達 Double 的範圍 
    Variant
    (字元) 22 個位元組 加字串長度 與變動長度 String 有相同的範圍 
    使用者定義
    (利用 Type) 元件所需數目 每個元件的範圍與它本身的資料資料型態的範圍相同。 
      

  2.   

    Private Sub Command1_Click()
        Dim a As UserDefinedTime
        MsgBox Len(a)
    End Sub
      

  3.   

    凑合着用len吧,尽管它不能完全替代C中的sizeof
      

  4.   

    标准的就是用len函数了,
    不过要定义一个变量为那个 UDT 类型,然后对变量取 LEN()。就是 rainstormmaster(暴风雨 v2.0) 的方法了。
      

  5.   

    <a href=http://www.frontiertech.info>www.frontiertech.info</a>