投稿日 | : 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
としているのですが、どうすればリストの中の項目に空のデータを表示しないようにできるのでしょうか?
よろしくお願いします。