VB6.0用掲示板の過去のログ(No.1)−VBレスキュー(花ちゃん)
[記事リスト] [新規投稿] [新着記事] [ワード検索] [過去ログ] [管理用]

投稿日: 2003/06/09(Mon) 19:42
投稿者聖魔
Eメール
URL
タイトル動的配列でファイルの入出力・削除

こんばんわ聖魔です
お世話になります

長文失礼します。

いま、動的配列を使用してファイルへの入出力また削除を行って、ファイルの中身をリストボックスに表示させています。

そこで質問なのですが、入出力はできるのですが、削除の仕方が問題あるのかリストボックスの一覧に
空のデータが入ってしまって困っています。

リストにはすでに項目が入っているとして、
標準モジュール
Public Host() As InformationHost
Public Type InformationHost
    StartFlg As String
    HostName As String
    ServerName As String
    UserName As String
    Password As String
    EndFlg As String
End Type

フォームの削除ボタン
Private Sub cmdDeleteHost_Click()
    Dim Index As Long
    Dim FileNo As Integer
    Erase Host
    FileNo = FreeFile
    i = 0
    
    If CHKHostName = True Then
        Open HostFileName For Binary As #FileNo
            While Not EOF(FileNo)
                ReDim Preserve Host(i) As InformationHost
                Get #FileNo, , Host(i)
                i = i + 1
            Wend
        Close #FileNo
        For Index = 0 To UBound(Host)
            If Me.lstHostName.Text = Host(Index).HostName Then
                Exit For
            End If
        Next Index
        
        FileNo = FreeFile
        Open HostFileName For Binary As #FileNo
            For i = 0 To Index - 1
                Put #FileNo, , Host(i)
            Next i
            
            For i = Index + 1 To UBound(Host)
                Put #FileNo, , Host(i)
            Next i
            
        Close #FileNo
        Call GetHostInformation(HostFileName)
    End If
End Sub

Private Function GetHostInformation(ByVal FileName As String)
    Dim FileNo As Integer
    Dim HFlg As Boolean
    Dim strCHKHostName As String
    Dim FileBuf As Long
    On Error Resume Next
    
    GetHostInformation = False
    
    '変数の初期化
    FileNo = FreeFile
    HFlg = False
    i = 0
    Erase Host
    
    Open HostFileName For Binary As #FileNo
        While Not EOF(FileNo)
            ReDim Preserve Host(i) As InformationHost
            Get #FileNo, , Host(i)
            i = i + 1
        Wend
        If i = 0 Then
            Exit Function
        End If
        
    Close #FileNo
    
    frmTop.lstHostName.Clear
    If UBound(Host) <> 0 Then
        For i = 0 To UBound(Host)
            Form1.List1.AddItem Host(i).HostName
        Next
    End If
End Function

としているのですが、どうすればリストの中の項目に空のデータを表示しないようにできるのでしょうか?

よろしくお願いします。


- 関連一覧ツリー (★ をクリックするとツリー全体を一括表示します)

- 返信フォーム (この記事に返信する場合は下記フォームから投稿して下さい)

- Web Forum -