Fox243 Fox243 - 1 year ago 139 Question

Loop through file extensions

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 Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download