[BEGINNER HElP] Multiple pictures extensions choices
Hello, i am writting a little program and i want to select a picture with one extensions but several possibilities. my first option is .png but i want to add ".gif"vpicture if "png" picture is not found.
i am starting in coding. i tried this:
Code:
PictureBox9.Image = Image.FromFile(Application.StartupPath & "\DANfiles\challengersgif\" & Me.ComboBox1.Text & (".png" or ".gif"))
but i have a error!
please! give me a hand ! i am looking for a solution. thank you in advance for your answer!
Re: [BEGINNER HElP] Multiple pictures extensions choices
vb.net Code:
Dim filePath = Path.Combine(Application.StartupPath,
"DANfiles\challengersgif",
Me.ComboBox1.Text & ".png")
If Not File.Exists(filePath) Then
filePath = Path.ChangeExtension(filePath, ".gif")
End If
'Use filePath here.
You may want to add a check to see that the second file path exists if there's a possibility that it might not.
Re: [BEGINNER HElP] Multiple pictures extensions choices
Here's another option that incorporates a check for at least one existent file and can be easily extended to more extensions just by adding more elements to the array:
vb.net Code:
Dim filePath = Path.Combine(Application.StartupPath,
"DANfiles\challengersgif",
Me.ComboBox1.Text)
Dim extensions = {"png", "gif"}
filePath = extensions.Select(Function(ext) Path.ChangeExtension(filePath, ext)).
FirstOrDefault(Function(fp) File.Exists(fp))
If filePath IsNot Nothing Then
'Use filePath here.
End If
Re: [BEGINNER HElP] Multiple pictures extensions choices
ok thank you very much for your help