Kirk Charles Niverba Kirk Charles Niverba - 5 months ago 12
Vb.net Question

How to open a file with Visual Basic?

I'm making a application opener on Visual Basic, and this idea comes into my mind. What if the file isn't accessible, what would the application do? If the file isn't accessible or it isn't found: a message box will show (note that this is VB on 2012 Version).

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
System.Threading.Thread.Sleep(1000)
Process.Start("C:\Users\{Censored}\Desktop\Bungeecord.bat")
End Sub
End Class

Answer

I would use try/catch sentences

Try
    [...]
    Process.Start("C:\Users\{Censored}\Desktop\Bungeecord.bat")
Catch ex As Exception
    MsgBox("Can't access file " & vbCrLf & ex.Message)
End Try

If you canĀ“t access the file the message will be shown