I’m converting a bunch of foxweb programs to asp.net. Some of the functions I invoke in the asp code use “external functions,” by which I mean functions that I have defined in .vb files. For example, FileExists() is a nice function I would like to pull out into a common thing called clsCommon.vb .
I have implemented it like this:
Option Explicit On
Option Strict On
Imports System
Imports System.Web.UI
Imports System.Web.UI.Page
Public Class clsCommon
Inherits Page
Public Shared Function FileExists(ByVal filename As String) As Boolean
If Dir$(filename) <> "" Then
Return True
Else
Return False
End If
End Function
End Class
I have tried using both DIR$() and DIR(). In each case, the error returned on the web page reads:
Compiler Error Message: BC30451: Name ‘Dir’ is not declared.
As with other functions I have written I invoke FileExists() something like this:
<%@ page Debug="true" inherits="clsCommon" src="clsCommon.vb" %>
<%
Dim filename as String = "example.txt"
If clsCommon.FileExists(filename) then
Response.Write(filename & " Exists")
else
Response.Write(filename & " does not Exist")
end if
%>
Note 1: While I want to solve this specific problem, what I’m really looking for is the general way to get to these functions like DIR(), CHR(), etc., that I have come to rely on in VB.
Note 2: asp seems to only look at the vb text file – and not at the compiled dll file, so I don’t think the references I use have any effect on it.
Anyone see what I’m missing?
TheGeekYouNeed is certainly right. The best approach is to either keep your code in VB (if it ain’t broke, don’t fix it) or consider investing some time in learning .Net
I have seen code conversion tools for turning VB code into VB.Net. I can’t imagine them working for non-trivial projects though. Likewise, you can go out of your way to keep your code as ‘VB like’ as possible, but I think it’s like burning down your house to avoid having to sweep the floor.
Anyway, the DIR function does still exist in the
Microsoft.VisualBasicnamespace.http://msdn.microsoft.com/en-us/library/dk008ty4(v=vs.71).aspx
The more generally accepted way of doing this in .NET would be to use
File.Existshttp://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx