Re: Creating a custom class/Namespace

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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...
> ======================
>
> <ryan.d.rembaum@xxxxxx> wrote in message
> news:1125101329.068646.231440@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> 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...
> > ======================
> >
> > <ryan.d.rembaum@xxxxxx> wrote in message
> > news:1125092781.421365.248520@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> > > 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
> > >

.



Relevant Pages

  • Re: You must add a reference to assembly System.Xml
    ... It means you are just importing that namespace, trying to shortcut the need to type fully-qualified names of types residing in System.Xml namespace. ... and they don't necessarily always go hand in hand with assemblies. ... try taking the reference in VS with Add reference dialog ... private DataRowRAdresy; ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Property of Custom Control
    ... Visual Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows ... You must add a reference to assembly ... TextBoxEx.cs: error CS0234: The type or namespace name ... When I am using Desktop assemblies I have no problem ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Namespaces not found
    ... That is importing a namespace. ... referenced assemblies can be imported. ... Reference" on top of "References" and choose System.Web.dll assembly. ... public void Init ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Referencing assemblies and .config files.
    ... > A namespace can be distributed over several assemblies. ... Try to run ildasm.exe on the assemblies that you do have references to - and see what types they contain. ... > I don't know where the reference is. ... >> Firstly I have seen in the designer that for the namespace and many of its>> associated classes of System.Runtime.Remoting are available, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Does project load DLL multiple times?
    ... my EXE webform project also references System.Windows.Forms. ... calls objects in the Forms namespace, ... You can set a reference to as many assemblies as you wish, ...
    (microsoft.public.dotnet.languages.csharp)