很长时间没用VB做东西了,vb中有结构体吗.如果有的话,各位能和我说说怎么定义吗.
如果没有,我想问得是.把一个字符串里的东西想用类似C中结构体那样储存,该如何去做呢.
意思是这样的.我用C表示一下 
{
    struct student
    {
       char name[20];
       char address[20];
    }
    struct student stu[3];
    
    
}
不知道你们理解我意思没.给我个类似的定义例子,谢谢.我在线等.

解决方案 »

  1.   

    private type student 
        name as string*20 
        address as string*20 
    end type 
    dim stu(2) as student
      

  2.   


    Option ExplicitPublic Type student
           name As String * 20
           address As String * 20
    End TypeSub main()
        
        Dim students(10) As student
        
        students(0).name = "111"
        students(0).address = "aaaaaaaa"
        
        Debug.Print students(0).name
        Debug.Print students(0).address
    End Sub
    模塊中可以用關鍵字 public,窗口中不能。
      

  3.   

    I suggest using byte instead of a fixed string,otherwise,you may lost Unicode in some others locale ID system.Option ExplicitPrivate Type tStudent
           sName() As Byte
           sAddress() As Byte
    End TypePrivate Sub Form_Load()
      Dim students(10) As tStudent
         
        students(0).sName = (ChrW(&H60C5) & ChrW(&H4EBA) & ChrW(&H8282))
        students(0).sAddress = (ChrW(&H60C5) & ChrW(&H4EBA) & ChrW(&H8282)) & " No.1"
         
     Dim sPrompt As String
     Dim Chs As String
     Dim sName As String
     Dim sAddress As String
     sName = students(0).sName
     sAddress = students(0).sAddress
       sPrompt = "Chinese String is Unicode"
       Chs = "Name is " & sName & "   Road is " & sAddress
        ShellMsgBox sPrompt, "Title " & Chs, vbApplicationModalEnd SubFunction ShellMsgBox(ByVal sPrompt As String, _
       Optional ByVal sTitle As String, _
       Optional lFlags As VbMsgBoxStyle = vbOKCancel Or vbInformation) As VbMsgBoxResult
       
       Dim WshShell As Object
       Set WshShell = CreateObject("WScript.Shell")
       ShellMsgBox = WshShell.Popup(sPrompt, 0, sTitle, lFlags)
       Set WshShell = Nothing
    End Function
      

  4.   

    http://www.hexi5.com/bbs/dispbbs.asp?boardID=6&ID=248&page=1
      

  5.   

    订正:
    还是用定长的字符串好些,容易处理:
    Private Type WinDataType
       ISBalance As String * 1000
       Filler       As String * 100
    End TypePrivate Type WinIODataType
      Filler       As String * 2
      Data         As WinDataType
    End TypePrivate Type WinComDataType
      Filler       As String * 2
      Inp          As WinIODataType
      Out          As WinIODataType
    End Type
      

  6.   

    你的例子应该这样: 
    Private Type student  
        name as string*20  
        address as string*20  
    End Type  
    Dim stu(2) As student 如果你用CopyMemory进行将结构体置换到数组或字符串中,要记得student 结构体的长度是40,字节数40*2=40bytes
      

  7.   

    我现在对这种结构ISBalance As String * 1000 的理解为动态定长对吗?