Checking for reference file existance before use

  • Thread starter Thread starter Jm
  • Start date Start date
J

Jm

Hi all

Im a bit of a newbie to VB.NET. Under vb6 if i used a class library DLL and
it wasnt available i could use the on error resume next to get past the code
that calls it and trap it afterwards and display a custom error messageor
move on. I was wondering if this is possible in VB.NET, it seems to just end
the program with a vb frameworkish error. Basically my code says:

Imports My_Project
.......
Dim MyProjectObj As New Project1

(Project1 being the class inside the My_Project namesapce)

Any help is greatly appreciated
 
Jm said:
Hi all

Im a bit of a newbie to VB.NET. Under vb6 if i used a class library DLL and
it wasnt available i could use the on error resume next to get past the code
that calls it and trap it afterwards and display a custom error messageor
move on. I was wondering if this is possible in VB.NET, it seems to just end
the program with a vb frameworkish error. Basically my code says:

Imports My_Project
......
Dim MyProjectObj As New Project1

(Project1 being the class inside the My_Project namesapce)

Any help is greatly appreciated
..NET uses a try-catch method, so:

TRY
<insert critical code here>
CATCH ex as exception
MessageBox(ex.message)
FINALLY
<code here to wrap up things if you need to>
END TRY
 
Jm

In addition to Rinze

For file existence you would not use error trapping.

Error trapping should be done with situation that you cannot know or test
before because they happens not under your control.

When your program is on the same drive as your program, than your disk is
working therefore this should be enough.

\\\
If Not file.exist(myfile) then messagebox.show("the file does not exist")
///

I hope this helps?

Cor
 
Jm said:
Im a bit of a newbie to VB.NET. Under vb6 if i used a class library DLL
and
it wasnt available i could use the on error resume next to get past the
code
that calls it and trap it afterwards and display a custom error messageor
move on. I was wondering if this is possible in VB.NET, it seems to just
end
the program with a vb frameworkish error. Basically my code says:

Does this error even occur when you use 'On Error Resume Next'?
 
Hi All

Ok i looked at all replys, thanks for sending them so quick. To answer the
last one, when i use the on error resume next it still ends the program. I
didnt mention earlier that this program is a service. As a bit of further
background what im trying to trap is a dll file used for licesneing control,
basically i will use the dim statement to reference it and under vb6 this
was fine because i could on error resume next. But under .NET i did try the
following:

Try

Dim MyObj As New Project1

Catch ex As Exception

MsgBox("LicFail", MsgBoxStyle.Critical, "LicFail")

Finally

End

End Try

But it does the same as before, and doesnt disaply the message box. Is it
possible to do what i used to under Vb6 in .Net ? Many thanks all
 
Jm said:
Dim MyObj As New Project1

Catch ex As Exception

MsgBox("LicFail", MsgBoxStyle.Critical, "LicFail")

Finally

End

End Try

But it does the same as before, and doesnt disaply the message box. Is it
possible to do what i used to under Vb6 in .Net ? Many thanks all

What's 'Project1'? A class in your library?
 
Yes, the dim statement works fine as long as you can access the dll file,
but when i purposely remove it is when i have the issue, which i could get
around under vb6
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top