• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • Last Modified:

App_Code Class

How can I place the attached Function in the App_Code folder and a class called "myMethods" so it is accessible site wide instead of copying into every page?
Function RemoveNonDigits(ByVal s As String) As String
        Dim regex As New System.Text.RegularExpressions.Regex("[^\d]")
        RemoveNonDigits = regex.Replace(s, "")
    End Function

Open in new window

0
lrbrister
Asked:
lrbrister
  • 2
  • 2
1 Solution
 
derftoyCommented:
In VB instead of a class, create a class file and create a Public Module instead of Public Class and put your function in it.
0
 
lrbristerAuthor Commented:
derftoy:
I recognized the words and idea...got an example?

I'm in Visual Studio 2008 and it's a Web Site
0
 
derftoyCommented:
In your app code folder add a new class.  It will default to something like class.vb... name the file whatever you want.  Just remove the class declaration inside the file and replace with the Public Module like I show witht he code below.  

Replace the generated Class code with Public Module and put your functions in it.  Make sure your functions are public as well.  You will then be able to call those functions within your app from anywhere.

I have attached some code I use with some constants and such.
Public Module LoginCode
    Public Const APP As String = "PERMITTRAX"
    Public Const BAR_X As Integer = 760
    Public Const BAR_YUP As Integer = 130
    Public Const BAR_YDN As Integer = 530
    Public Const APPDBVER As String = "02162010"
    Public Const RPTVER As String = "01202010"

    Public Function CheckDBVersion(ByVal CONID As String) As Boolean
        Dim i As New DataIO
        Dim bReturnVal As Boolean = False

        i.OpenDS("SELECT * FROM Console_Settings WHERE Setting_Option = 'APPDBVER'", GetAppConnection(CONID))
        If i.RecCount = 0 Then
            i.DSCommand(DataIO.DSCommands.AddRecord)
            i.PutField("Setting_Option", "APPDBVER")
            i.PutField("Field_Text_1", APPDBVER)
            i.PutField("Setting_Desc", "Application Database Version")
            i.DSCommand(DataIO.DSCommands.UpdateRecord)
            bReturnVal = True
        Else
            ' Check Version
            If i.GetField("Field_Text_1").ToString <> APPDBVER Then
                bReturnVal = False
            Else
                bReturnVal = True
            End If
        End If
        i.CloseDS()

        Return bReturnVal
    End Function

    Public Function ValidateRegistration(ByVal ID As String) As Boolean
        Dim i As New DataIO
        Dim cn As New Connections

        Try
            If ID = "" Then Return False
            i.OpenDS("SELECT * FROM APP_Registration WHERE AutoKey = " & ID, cn.GetConString(Connections.APPS.APPLICATION))
            If i.RecCount <> 0 Then
                If Not IsDate(i.GetField("Reg_Completed")) Then
                    Exit Try
                End If
            End If
            i.CloseDS()
        Catch ex As Exception
            Return False
        End Try

        Return True
    End Function

End Module

Open in new window

0
 
lrbristerAuthor Commented:
Thanks...that's it.  
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now