' Add the following controls:
' ComboBox1
' Button1
' FolderBrowserDialog1
Public Class Form1
Dim dir_path As String = ""
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim file_name As String = ""
ComboBox1.Text = ""
ComboBox1.Items.Clear()
FolderBrowserDialog1.SelectedPath = ""
Do
FolderBrowserDialog1.ShowDialog()
dir_path = FolderBrowserDialog1.SelectedPath & "\"
Loop While FolderBrowserDialog1.SelectedPath = ""
file_name = Dir(dir_path, FileAttribute.Normal)
Do While file_name <> ""
If Is_Log_File(file_name) Then
ComboBox1.Items.Add(file_name)
End If
file_name = Dir()
Loop
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Shell("c:\windows\notepad.exe " & dir_path & ComboBox1.SelectedItem, AppWinStyle.NormalFocus)
End Sub
Private Function Is_Log_File(ByVal file_name As String) As Boolean
Dim file_ext As String = "", pos As Integer = 0, valid = False
If InStr(file_name, ".") > 0 Then
pos = file_name.LastIndexOf(".")
file_ext = LCase(Mid(file_name, pos + 2))
If file_ext = "txt" Then
valid = True
ElseIf file_ext = "log" Then
valid = True
End If
Else
' File name has no file extension
valid = True
End If
Return valid
End Function
End Class