A1VBCode Forums

ASP.Net/VB.Net - Advice for Cleaning up my code


http://www.a1vbcode.com/vbforums/Topic27980.aspx

By rathurosamal - 8/2/2009

Can someone please give me some advice on cleaning up my code a little. I have aspx pages with code_behind .vb files.



Typical head of webpage is:

index.aspx

Code:



<%@ Page Inherits="ipod_index_process" Src="index_cb.vb" Debug="true" %>

<%@ Import Namespace="System.Xml" %>







Typical code is:

index_cb.vb

Code:



Imports System

Imports System.Data

Imports System.IO

Imports System.Xml

Imports System.Web

Imports System.Web.UI

Imports System.Web.UI.WebControls

Imports System.Web.UI.HTMLControls



Imports System.Text

Imports System.Text.RegularExpressions

Imports System.Security.Cryptography



public class ipod_index_process



inherits page Public variable declarations...... Logic code....... Call Signature (X,Y,Z) Function Signature (X,Y,Z)



Several Functions......



End Function



End Sub







Several parts of this code are common to many other pages in my site (e.g. the declarations) or need to be used throughout the site (e.g. the Function Signature). Presently they are written out again and again in each .vb page.



What I want to do is to put the 'Public declaration' in a separate file and the 'Functions Signature' and everything in it in another.



I'm an old school VB programmer and not used to using namespaces/inheritance/classes. I'm sure this requires using classes and namespaces but I've tried to get my head around it but failed.
By Mobius - 8/5/2009

Why don't you put all these functions in a public class and call them when you need them?