步驟 4:填入 [詳細資料] 文字方塊

若要填入 [詳細資料] 文字方塊,請建立名為 recFields 的新副程式,並插入下列程式碼:

Sub recFields(r As Record, l As ListBox, t As TextBox)  
    Dim f As Field  
    Dim s As Stream  
    Set s = New Stream  
    Dim str As String  
  
    For Each f In r.Fields  
        l.AddItem f.Name & ": " & f.Value  
    Next  
    t.Text = ""  
    If r!RESOURCE_CONTENTCLASS = "text/plain" Then  
        s.Open r, adModeRead, adOpenStreamFromRecord  
        str = s.ReadText(1)  
        s.Position = 0  
        If Asc(Mid(str, 1, 1)) = 63 Then '//63 = "?"  
            s.Charset = "ascii"  
            s.Type = adTypeText  
        End If  
        t.Text = s.ReadText(adReadAll)  
    End If  
End Sub  

此程式碼會以傳至 recFields 之簡單記錄的欄位和值填入 lstDetails。 如果資源是文字檔,則會從資源記錄開啟文字資料流。 程式碼會判斷字元集是否為 ASCII,並將資料流內容複製到 txtDetails 中。

另請參閱

網際網路發佈案例
步驟 3:填入 [欄位] 清單方塊