很长时间没用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
        
    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 Explicit Private Type tStudent 
           sName() As Byte 
           sAddress() As Byte 
    End Type 
    Private 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, vbApplicationModal End Sub Function 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.   

    订正: 
    还是用定长的字符串好些,容易处理: 
    Private Type WinDataType 
       ISBalance As String * 1000 
       Filler       As String * 100 
    End Type Private Type WinIODataType 
      Filler       As String * 2 
      Data         As WinDataType 
    End Type Private Type WinComDataType 
      Filler       As String * 2 
      Inp          As WinIODataType 
      Out          As WinIODataType 
    End Type 你的例子应该这样:
    Private Type student 
        name as string*20 
        address as string*20 
    End Type 
    Dim stu(2) As student
    如果你用CopyMemory,要记得student 结构体的长度是40,字节数40*2=40bytes