Fox243 Fox243 - 3 months ago 26
Vb.net Question

Loop through file extensions

Try
Dim lImage As Image = Image.FromFile(appPath + "\" + "ActiveDisplay" + "\" + "Helmets" + "\" + vData + **"extension loop need"**)
ResizePicture(Me.PictureBox1, lImage)
Catch ex As Exception

End Try


I'm searching for a image name in viewer and need to loop through extensions
any help would be appreciated

Answer

You can use a String array and a For Each

    Dim extensions As String() = {".png", ".jpg", ".bmp"}
    For Each ext As String In extensions
        Dim file As String = appPath + "\" + "ActiveDisplay" + "\" + "Helmets" + "\" + vData + ext

        'I recomend use:  Dim file As String= String.Format("{0}\ActiveDisplay\Helmets\{1}\{2}", appPath, vData, ext)

        If IO.File.Exists(file) Then
            Dim lImage As Image = Image.FromFile(file)
        End If
    Next
Comments