By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 845 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

Creating a custom class/Namespace

P: n/a
Hello,

I have code that I wish to use in many web applications. Basically
sort of stand utility stuff. So from Visual Studio Project I select
add a component and chose Component Class. Lets say I enter code at
the end of this question in to the code section.

How then would I reference this in a new Web Application (or in the
same web application for that matter?)

I have tried:
<%@ Import Namespace="ByteArray.ByteArray" %>
and
<%@ Import Namespace="ByteArray" %>

But when I run the page it just gives me a message that the Namespace
can't be found.

Thanks,
Ryan

------------CODE FOLLOWS-----------------------------

Imports System.Globalization
Namespace ByteArray
Public Class ByteArray
Inherits System.ComponentModel.Component
|Component Designer generated code...|

Public Function CreateTypeByte(ByVal strInput As String) As
Byte()
Dim i As Integer
Dim arrChar As Char()

arrChar = strInput.ToCharArray()
Dim arrByte(arrChar.Length - 1) As Byte
For i = 0 To arrByte.Length - 1
arrByte(i) = Convert.ToByte(arrChar(i))
Next
Return arrByte
End Function

Public Function CreateTypeHex(ByVal strInput As String) As
Byte()
Dim i As Integer
Dim arrString As String()

arrString = strInput.Split(New Char() {"-"})
Dim arrByte(arrString.Length - 1) As Byte
For i = 0 To arrByte.Length - 1
arrByte(i) = Byte.Parse(arrString(i),
NumberStyles.HexNumber)
Next
Return arrByte
End Function
End Class
End Namespace

Nov 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Did you compile it ?

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

<ry************@kp.org> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hello,

I have code that I wish to use in many web applications. Basically
sort of stand utility stuff. So from Visual Studio Project I select
add a component and chose Component Class. Lets say I enter code at
the end of this question in to the code section.

How then would I reference this in a new Web Application (or in the
same web application for that matter?)

I have tried:
<%@ Import Namespace="ByteArray.ByteArray" %>
and
<%@ Import Namespace="ByteArray" %>

But when I run the page it just gives me a message that the Namespace
can't be found.

Thanks,
Ryan

------------CODE FOLLOWS-----------------------------

Imports System.Globalization
Namespace ByteArray
Public Class ByteArray
Inherits System.ComponentModel.Component
|Component Designer generated code...|

Public Function CreateTypeByte(ByVal strInput As String) As
Byte()
Dim i As Integer
Dim arrChar As Char()

arrChar = strInput.ToCharArray()
Dim arrByte(arrChar.Length - 1) As Byte
For i = 0 To arrByte.Length - 1
arrByte(i) = Convert.ToByte(arrChar(i))
Next
Return arrByte
End Function

Public Function CreateTypeHex(ByVal strInput As String) As
Byte()
Dim i As Integer
Dim arrString As String()

arrString = strInput.Split(New Char() {"-"})
Dim arrByte(arrString.Length - 1) As Byte
For i = 0 To arrByte.Length - 1
arrByte(i) = Byte.Parse(arrString(i),
NumberStyles.HexNumber)
Next
Return arrByte
End Function
End Class
End Namespace

Nov 19 '05 #2

P: n/a
check this out, it may help:

http://www.mcdonalds.com/
ry************@kp.org wrote:
Hello,

I have code that I wish to use in many web applications. Basically
sort of stand utility stuff. So from Visual Studio Project I select
add a component and chose Component Class. Lets say I enter code at
the end of this question in to the code section.

How then would I reference this in a new Web Application (or in the
same web application for that matter?)

I have tried:
<%@ Import Namespace="ByteArray.ByteArray" %>
and
<%@ Import Namespace="ByteArray" %>

But when I run the page it just gives me a message that the Namespace
can't be found.

Thanks,
Ryan

------------CODE FOLLOWS-----------------------------

Imports System.Globalization
Namespace ByteArray
Public Class ByteArray
Inherits System.ComponentModel.Component
|Component Designer generated code...|

Public Function CreateTypeByte(ByVal strInput As String) As
Byte()
Dim i As Integer
Dim arrChar As Char()

arrChar = strInput.ToCharArray()
Dim arrByte(arrChar.Length - 1) As Byte
For i = 0 To arrByte.Length - 1
arrByte(i) = Convert.ToByte(arrChar(i))
Next
Return arrByte
End Function

Public Function CreateTypeHex(ByVal strInput As String) As
Byte()
Dim i As Integer
Dim arrString As String()

arrString = strInput.Split(New Char() {"-"})
Dim arrByte(arrString.Length - 1) As Byte
For i = 0 To arrByte.Length - 1
arrByte(i) = Byte.Parse(arrString(i),
NumberStyles.HexNumber)
Next
Return arrByte
End Function
End Class
End Namespace


Nov 19 '05 #3

P: n/a
I built and rebuilt the project and solution and get no skips and no
errors. Just a report of success...But then when I test my ASP page in
my browser, I get the message in the compiler output that my namespace
could not be found.

Any thoughts?

Ryan

Juan T. Llibre wrote:
Did you compile it ?

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

<ry************@kp.org> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hello,

I have code that I wish to use in many web applications. Basically
sort of stand utility stuff. So from Visual Studio Project I select
add a component and chose Component Class. Lets say I enter code at
the end of this question in to the code section.

How then would I reference this in a new Web Application (or in the
same web application for that matter?)

I have tried:
<%@ Import Namespace="ByteArray.ByteArray" %>
and
<%@ Import Namespace="ByteArray" %>

But when I run the page it just gives me a message that the Namespace
can't be found.

Thanks,
Ryan

------------CODE FOLLOWS-----------------------------

Imports System.Globalization
Namespace ByteArray
Public Class ByteArray
Inherits System.ComponentModel.Component
|Component Designer generated code...|

Public Function CreateTypeByte(ByVal strInput As String) As
Byte()
Dim i As Integer
Dim arrChar As Char()

arrChar = strInput.ToCharArray()
Dim arrByte(arrChar.Length - 1) As Byte
For i = 0 To arrByte.Length - 1
arrByte(i) = Convert.ToByte(arrChar(i))
Next
Return arrByte
End Function

Public Function CreateTypeHex(ByVal strInput As String) As
Byte()
Dim i As Integer
Dim arrString As String()

arrString = strInput.Split(New Char() {"-"})
Dim arrByte(arrString.Length - 1) As Byte
For i = 0 To arrByte.Length - 1
arrByte(i) = Byte.Parse(arrString(i),
NumberStyles.HexNumber)
Next
Return arrByte
End Function
End Class
End Namespace


Nov 19 '05 #4

P: n/a
re:
How then would I reference this in a new Web Application
(or in the same web application for that matter?)

To reference that code in a new web Application, you'd have
to compile the code from the command-line, and reference
*that* assembly in your VS.NET project.

To compile a single source code file, use :

csc /t:library /out:utils.dll utils.cs

To compile all .cs files in a directory to utils.dll ,
use : csc /t:library /out:utils.dll *.cs

If you need to reference a .Net Framework assembly or assemblies,
add them, separated by slashes :

csc /t:library /r:system.dll /r:system.data.dll /out:utils.dll *.cs

If you're using VB.NET instead of C#,
use vbc and source files ending in .vb
instead of using csc and source files ending in .cs.

The syntax is the same for vb and c#.

Once you have compiled your assembly, place it in the /bin
directory of your application, and import the Namespace :

<%@ Import Namespace="ByteArray" %>

If you're working strictly with VS.NET, compile your assembly
as described and add a reference to it in your VS.NET project.

That will allow you to use Intellisense and get your
assembly's properties, methods, etc. when coding.


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

<ry************@kp.org> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
I built and rebuilt the project and solution and get no skips and no
errors. Just a report of success...But then when I test my ASP page in
my browser, I get the message in the compiler output that my namespace
could not be found.

Any thoughts?

Ryan

Juan T. Llibre wrote: Did you compile it ?

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

<ry************@kp.org> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hello,

I have code that I wish to use in many web applications. Basically
sort of stand utility stuff. So from Visual Studio Project I select
add a component and chose Component Class. Lets say I enter code at
the end of this question in to the code section.

How then would I reference this in a new Web Application (or in the
same web application for that matter?)

I have tried:
<%@ Import Namespace="ByteArray.ByteArray" %>
and
<%@ Import Namespace="ByteArray" %>

But when I run the page it just gives me a message that the Namespace
can't be found.

Thanks,
Ryan

------------CODE FOLLOWS-----------------------------

Imports System.Globalization
Namespace ByteArray
Public Class ByteArray
Inherits System.ComponentModel.Component
|Component Designer generated code...|

Public Function CreateTypeByte(ByVal strInput As String) As
Byte()
Dim i As Integer
Dim arrChar As Char()

arrChar = strInput.ToCharArray()
Dim arrByte(arrChar.Length - 1) As Byte
For i = 0 To arrByte.Length - 1
arrByte(i) = Convert.ToByte(arrChar(i))
Next
Return arrByte
End Function

Public Function CreateTypeHex(ByVal strInput As String) As
Byte()
Dim i As Integer
Dim arrString As String()

arrString = strInput.Split(New Char() {"-"})
Dim arrByte(arrString.Length - 1) As Byte
For i = 0 To arrByte.Length - 1
arrByte(i) = Byte.Parse(arrString(i),
NumberStyles.HexNumber)
Next
Return arrByte
End Function
End Class
End Namespace

Nov 19 '05 #5

P: n/a
Hi Juan,

Thanks for your help. I have tried what you suggested and am getting
some errors. Here, first, are the contents of my .vb file:
---------------------------------------------
Imports System.Globalization
Namespace ByteArray
Public Class ByteArray
Inherits System.ComponentModel.Component
#Region " Component Designer generated code "

Public Sub New(ByVal Container As
System.ComponentModel.IContainer)
MyClass.New()

'Required for Windows.Forms Class Composition Designer
support
Container.Add(Me)
End Sub

Public Sub New()
MyBase.New()

'This call is required by the Component Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent()
call

End Sub

'Component overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Component Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Component
Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
components = New System.ComponentModel.Container
End Sub

#End Region
Public Function CreateTypeByte(ByVal strInput As String) As
Byte()
Dim i As Integer
Dim arrChar As Char()

arrChar = strInput.ToCharArray()
Dim arrByte(arrChar.Length - 1) As Byte
For i = 0 To arrByte.Length - 1
arrByte(i) = Convert.ToByte(arrChar(i))
Next
Return arrByte
End Function

Public Function CreateTypeHex(ByVal strInput As String) As
Byte()
Dim i As Integer
Dim arrString As String()

arrString = strInput.Split(New Char() {"-"})
Dim arrByte(arrString.Length - 1) As Byte
For i = 0 To arrByte.Length - 1
arrByte(i) = Byte.Parse(arrString(i),
NumberStyles.HexNumber)
Next
Return arrByte
End Function
End Class
End Namespace
---------------------------------------------

I then compile it using:

c:\WINNT\Microsoft.NET\Framework\v1.1.4322\csc.exe /target:library
/out:ByteArray.dll /r:System.dll
C:\Inetpub\wwwroot\testApp\ByteArray.vb

I get a bunch of errors of four basic types:

-Preprocessor directive expected.
-Single Line Comment or End-of-Line expected.
-Newline in constant.
-A Namespace does not directly contain members such as fields or
methods.

Do you know why I am getting them. If I take out the system generated
code, the errors decrease, but I thought that the system generated code
was supposed to make my class more usuable. (Plus, I still get some of
the errors even without the system generated code.)

Thanks,
Ryan

Juan T. Llibre wrote:
re:
How then would I reference this in a new Web Application
(or in the same web application for that matter?)


To reference that code in a new web Application, you'd have
to compile the code from the command-line, and reference
*that* assembly in your VS.NET project.

To compile a single source code file, use :

csc /t:library /out:utils.dll utils.cs

To compile all .cs files in a directory to utils.dll ,
use : csc /t:library /out:utils.dll *.cs

If you need to reference a .Net Framework assembly or assemblies,
add them, separated by slashes :

csc /t:library /r:system.dll /r:system.data.dll /out:utils.dll *.cs

If you're using VB.NET instead of C#,
use vbc and source files ending in .vb
instead of using csc and source files ending in .cs.

The syntax is the same for vb and c#.

Once you have compiled your assembly, place it in the /bin
directory of your application, and import the Namespace :

<%@ Import Namespace="ByteArray" %>

If you're working strictly with VS.NET, compile your assembly
as described and add a reference to it in your VS.NET project.

That will allow you to use Intellisense and get your
assembly's properties, methods, etc. when coding.


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

<ry************@kp.org> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
I built and rebuilt the project and solution and get no skips and no
errors. Just a report of success...But then when I test my ASP page in
my browser, I get the message in the compiler output that my namespace
could not be found.

Any thoughts?

Ryan

Juan T. Llibre wrote:
Did you compile it ?

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

<ry************@kp.org> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hello,

I have code that I wish to use in many web applications. Basically
sort of stand utility stuff. So from Visual Studio Project I select
add a component and chose Component Class. Lets say I enter code at
the end of this question in to the code section.

How then would I reference this in a new Web Application (or in the
same web application for that matter?)

I have tried:
<%@ Import Namespace="ByteArray.ByteArray" %>
and
<%@ Import Namespace="ByteArray" %>

But when I run the page it just gives me a message that the Namespace
can't be found.

Thanks,
Ryan

------------CODE FOLLOWS-----------------------------

Imports System.Globalization
Namespace ByteArray
Public Class ByteArray
Inherits System.ComponentModel.Component
|Component Designer generated code...|

Public Function CreateTypeByte(ByVal strInput As String) As
Byte()
Dim i As Integer
Dim arrChar As Char()

arrChar = strInput.ToCharArray()
Dim arrByte(arrChar.Length - 1) As Byte
For i = 0 To arrByte.Length - 1
arrByte(i) = Convert.ToByte(arrChar(i))
Next
Return arrByte
End Function

Public Function CreateTypeHex(ByVal strInput As String) As
Byte()
Dim i As Integer
Dim arrString As String()

arrString = strInput.Split(New Char() {"-"})
Dim arrByte(arrString.Length - 1) As Byte
For i = 0 To arrByte.Length - 1
arrByte(i) = Byte.Parse(arrString(i),
NumberStyles.HexNumber)
Next
Return arrByte
End Function
End Class
End Namespace


Nov 19 '05 #6

P: n/a
It looks like you're trying to use a Windows Forms class in ASP.NET.
'Required for Windows.Forms Class Composition Designer support

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

<ry************@kp.org> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Hi Juan,

Thanks for your help. I have tried what you suggested and am getting
some errors. Here, first, are the contents of my .vb file:
---------------------------------------------
Imports System.Globalization
Namespace ByteArray
Public Class ByteArray
Inherits System.ComponentModel.Component
#Region " Component Designer generated code "

Public Sub New(ByVal Container As
System.ComponentModel.IContainer)
MyClass.New()

'Required for Windows.Forms Class Composition Designer
support
Container.Add(Me)
End Sub

Public Sub New()
MyBase.New()

'This call is required by the Component Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent()
call

End Sub

'Component overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Component Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Component
Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
components = New System.ComponentModel.Container
End Sub

#End Region
Public Function CreateTypeByte(ByVal strInput As String) As
Byte()
Dim i As Integer
Dim arrChar As Char()

arrChar = strInput.ToCharArray()
Dim arrByte(arrChar.Length - 1) As Byte
For i = 0 To arrByte.Length - 1
arrByte(i) = Convert.ToByte(arrChar(i))
Next
Return arrByte
End Function

Public Function CreateTypeHex(ByVal strInput As String) As
Byte()
Dim i As Integer
Dim arrString As String()

arrString = strInput.Split(New Char() {"-"})
Dim arrByte(arrString.Length - 1) As Byte
For i = 0 To arrByte.Length - 1
arrByte(i) = Byte.Parse(arrString(i),
NumberStyles.HexNumber)
Next
Return arrByte
End Function
End Class
End Namespace
---------------------------------------------

I then compile it using:

c:\WINNT\Microsoft.NET\Framework\v1.1.4322\csc.exe /target:library
/out:ByteArray.dll /r:System.dll
C:\Inetpub\wwwroot\testApp\ByteArray.vb

I get a bunch of errors of four basic types:

-Preprocessor directive expected.
-Single Line Comment or End-of-Line expected.
-Newline in constant.
-A Namespace does not directly contain members such as fields or
methods.

Do you know why I am getting them. If I take out the system generated
code, the errors decrease, but I thought that the system generated code
was supposed to make my class more usuable. (Plus, I still get some of
the errors even without the system generated code.)

Thanks,
Ryan

Juan T. Llibre wrote: re:
How then would I reference this in a new Web Application
(or in the same web application for that matter?)


To reference that code in a new web Application, you'd have
to compile the code from the command-line, and reference
*that* assembly in your VS.NET project.

To compile a single source code file, use :

csc /t:library /out:utils.dll utils.cs

To compile all .cs files in a directory to utils.dll ,
use : csc /t:library /out:utils.dll *.cs

If you need to reference a .Net Framework assembly or assemblies,
add them, separated by slashes :

csc /t:library /r:system.dll /r:system.data.dll /out:utils.dll *.cs

If you're using VB.NET instead of C#,
use vbc and source files ending in .vb
instead of using csc and source files ending in .cs.

The syntax is the same for vb and c#.

Once you have compiled your assembly, place it in the /bin
directory of your application, and import the Namespace :

<%@ Import Namespace="ByteArray" %>

If you're working strictly with VS.NET, compile your assembly
as described and add a reference to it in your VS.NET project.

That will allow you to use Intellisense and get your
assembly's properties, methods, etc. when coding.


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

<ry************@kp.org> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
I built and rebuilt the project and solution and get no skips and no
errors. Just a report of success...But then when I test my ASP page in
my browser, I get the message in the compiler output that my namespace
could not be found.

Any thoughts?

Ryan

Juan T. Llibre wrote:
Did you compile it ?

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

<ry************@kp.org> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hello,

I have code that I wish to use in many web applications. Basically
sort of stand utility stuff. So from Visual Studio Project I select
add a component and chose Component Class. Lets say I enter code at
the end of this question in to the code section.

How then would I reference this in a new Web Application (or in the
same web application for that matter?)

I have tried:
<%@ Import Namespace="ByteArray.ByteArray" %>
and
<%@ Import Namespace="ByteArray" %>

But when I run the page it just gives me a message that the Namespace
can't be found.

Thanks,
Ryan

------------CODE FOLLOWS-----------------------------

Imports System.Globalization
Namespace ByteArray
Public Class ByteArray
Inherits System.ComponentModel.Component
|Component Designer generated code...|

Public Function CreateTypeByte(ByVal strInput As String) As
Byte()
Dim i As Integer
Dim arrChar As Char()

arrChar = strInput.ToCharArray()
Dim arrByte(arrChar.Length - 1) As Byte
For i = 0 To arrByte.Length - 1
arrByte(i) = Convert.ToByte(arrChar(i))
Next
Return arrByte
End Function

Public Function CreateTypeHex(ByVal strInput As String) As
Byte()
Dim i As Integer
Dim arrString As String()

arrString = strInput.Split(New Char() {"-"})
Dim arrByte(arrString.Length - 1) As Byte
For i = 0 To arrByte.Length - 1
arrByte(i) = Byte.Parse(arrString(i),
NumberStyles.HexNumber)
Next
Return arrByte
End Function
End Class
End Namespace

Nov 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.