ASCII code

A

Abubakar

I want to get characters for given ascii codes. Dont wanna use the CHR or
ChrW functions. What r the .NET equivilents of the Chr & ChrW functions?

Regards,

Abubakar.
 
C

Cor

Hi Abukar,

The Chr and the ChrW are normal functions in the Net the same as the + the +
and the =.

Why would do you not want to use those?

Cor
 
A

Armin Zingler

Cor said:
Hi Armin,
Now I never get the answer from Akubar,
:-(

When I answered, your answer was not here, yet. For ASCII values, chr/chrw
don't help anyway.
 
A

Abubakar

Why would do you not want to use those?
because they require a reference to microsoft.visualbasic.dll, and I dont
use that. I always program by removing its reference from project "imports".
I dont use anything that comes from the vb dll. Like for example, instead of
using the old mid function I'll use the substring function of the string
class. Wanna b more close to .net that the language.
 
J

Jay B. Harlow [MVP - Outlook]

Abubakar,
You do realize that ChrW is inlined as IL by the VB.NET compiler, if you
give it an integer constant? Which means that you can use ChrW with Char &
String Constants!

It only calls into microsoft.visualbasic.dll if you give it a variable
parameter!

Of course you need to import the namespace in either case.

Initial tests suggest that AscW is always inlined for chars! And is only
calls microsoft.visualbasic.dll for String variables.

If you don't believe me check the IL produced with ILDASM.EXE.

I would recommend using ChrW! Seems a little naive to avoid ALL the
functions in Microsoft.VisualBasic, especially considering ALL the functions
are valid .NET!!! Usable from C# & other .NET languages as equally well as
VB.NET! Hell! its even installed as part of the framework itself!

Hope this helps
Jay
 
T

Tom Shelton

because they require a reference to microsoft.visualbasic.dll, and I dont
use that. I always program by removing its reference from project "imports".
I dont use anything that comes from the vb dll. Like for example, instead of
using the old mid function I'll use the substring function of the string
class. Wanna b more close to .net that the language.

Why would you do that? Did you know that the compiler inserts the
reference even if you remove it? There is no reason to remove it.
Those functions are the functions that make vb.net - well vb.net. If
you don't want to use those functions then you might as well be using
C#. If your worried they are going to be removed then, stop worrying.
It is only the functions in Microsoft.VisualBasic.Compatability.dll that
will be removed eventually. Further, there are a lot of handy functions
in the Microsoft.VisualBasic.dll. In fact, I have added this reference
to a couple of C# projects to use the financial functions since it was
easier then coding them myself :)

About the only functions that I would suggest you avoid from the
standard VB.NET runtime is the File IO functions.... They are wicked
slow...
 
J

Jay B. Harlow [MVP - Outlook]

Armin,
Actually I understand that Chr uses System.Test.Encoding.Default, as it
honors your Windows Code Page. However system.text.encoding.ascii will give
the Ascii characters, which as you state is 7 bit. (I suspect Abubakar may
actually want ANSI characters in a particular code page).

ChrW is suppose to be "Straight Unicode" no encoding involved. Using
ILDASM.EXE on ChrW itself it checks to be certain the 32bit integer is
within "range", then calls Convert.ToChar.

I really don't know why anyone would want to avoid ChrW & AscW personally,
as my other post suggests, they are in-lined by the VB.NET compiler itself
most of the time! In other words VB.NET doesn't even wait for the JIT
compiler to possible inline them, it does it itself!

Hope this helps
Jay
 
A

Abubakar

Why would you do that? Did you know that the compiler inserts the
reference even if you remove it? There is no reason to remove it.
well I dont think so, u know Rotor ? Its the open source .net. What I do is
sometimes I compile my programs in vbc and execute them in rotor, they work
fine if the vb dll is not referenced in it. Although I love C# and make
utilities in it but sometimes VB is a must as ordered by my seniors so I
like to program in such a way that I dont want to use vb dll specific
functions. And if I know everything through .NET classes and not by the
language, I'm pretty comfortable programming in any given language as I'v
already told u that I do program in C# and VB.net almost at the same time.
 
A

Abubakar

thanx for the nice reply and I understand your confusion about y I would
want to avoid it. Actually as a developer in a software company I'm a big
fan of C# but I 'm sometimes forced to use vb.net for some apps/libs by my
team. I program all my code by using only .net classes and not any language
specific functions. In C# I'm more close to doing this as u know that its a
new language and made specifically for .net. In vb however these extra
fucntions are avilable which r not part of .net class library but r specific
to vb. Now since I switch languages often it is very comfortable for me if I
know how things are done in .net instead of how they r done in vb.net or any
other programming language.
 
A

Armin Zingler

Abubakar said:
because they require a reference to microsoft.visualbasic.dll, and I
dont use that. I always program by removing its reference from
project "imports". I dont use anything that comes from the vb dll.

Then don't using system.windows.forms.dll because it is also a part of the
framework just like microsoft.visualbasic.dll. Maybe you mix it up with
microsoft.visualbasic.compatibility.dll which should only be used for
upgraded projects.
Like for example, instead of using the old mid function I'll use the
substring function of the string class. Wanna b more close to .net
that the language.

It is a .NET assembly.

What is the replacement for the Right function in the Framework?


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
A

Armin Zingler

C

Cor

Hi Akubar,

I see you are a C# expert, can you give me the C# function to translate a
byte with a value 65 to a Char "A" and also for the translation of a Char
with a value "A" to 65?

I am looking for that.

:)

Cor
 
A

Abubakar

Then don't using system.windows.forms.dll because it is also a part of the
framework just like microsoft.visualbasic.dll. Maybe you mix it up with
umm, let me say it like this that windows.forms.dll is the default thing
that every language will use for windows apps, right, may it be cobol, perl,
C#, c++, vb etc etc. But the functions that r specific to VB.net r not the
defualt functions that all languages use. This is the point. I'm one of
those developers who switch between .net languages in there projects.
Basically I need everything from .net which can be used from every language.
Ofcourse the microsoft.visualbasic.dll is managed and can be refernced from
any other language and its functions called, but I dont want it this way,
for example if I 'm used to using cobol's native functions which r inside
say somecompany.cobol.dll, I dont want to refernce it in C# and use them.

So the solution is that I'm going to use, say for this thread, encoding
class which is a part of .net which all language developers can use without
thinking that its inside the C# dll or vb dll or cobol etc,, its just going
to be there whenever whichever language u need it from. So again, I wanna be
more close to .net instead of any language so I'll feel more comfortable
using different langauges. And by the way, havnt you heard this, that to be
and good developer in .net you need to be good at .net base class library
than knowing the language..
 
C

Cor

Hi Abubakar,

You are not good in a language if you can translate a instruction in another
language instruction.
You are good in it if you can use the benefits from it.

My old sample is the benchmark test I once saw.

Someone had made a Algol Sort in Cobol.

He showed that he did need more lines in Cobol than in Algol and that it was
in Algol faster.

But he did not use the Cobol instruction Sort because that was not in Algol.

My 2 Euro cents about this

Cor
 
A

Armin Zingler

Abubakar said:
umm, let me say it like this that windows.forms.dll is the default
thing that every language will use for windows apps, right, may it be
cobol, perl, C#, c++, vb etc etc. But the functions that r specific
to VB.net r not the defualt functions that all languages use. This is
the point. I'm one of those developers who switch between .net
languages in there projects. Basically I need everything from .net
which can be used from every language. Ofcourse the
microsoft.visualbasic.dll is managed and can be refernced from any
other language and its functions called, but I dont want it this way,
for example if I 'm used to using cobol's native functions which r
inside say somecompany.cobol.dll, I dont want to refernce it in C#
and use them.

So the solution is that I'm going to use, say for this thread,
encoding class which is a part of .net which all language developers
can use without thinking that its inside the C# dll or vb dll or
cobol etc,, its just going to be there whenever whichever language u
need it from. So again, I wanna be more close to .net instead of any
language so I'll feel more comfortable using different langauges. And
by the way, havnt you heard this, that to be and good developer in
.net you need to be good at .net base class library than knowing the
language..

I think I understand you. Despite, what is wrong in using language specific
features? For example, you can create code comments in C#. Would you refuse
to use them in C# just because they are not available in Vb.NET? Same thing
for other features like unsafe blocks.

On the other side I agree that MSVB.DLL functions that are _only_ wrapper
functions for other Framework function and don't provide additional
features, should not be used. But, for example, the Right function is not a
part of the String class - one of the very few examples.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
A

Abubakar

You are good in it if you can use the benefits from it.
I'm trying to take benefit from .net bcl not vb.
But he did not use the Cobol instruction Sort because that was not in
Algol.
exactly,,,, if I'm using the C# or say Cobol the second day I dont want to
find myself looking for Chr equivilents in the new language when I know that
there was a .net equivilent.

And these r the things which .net solved. Language interoperability. Again,
be "more" good at BCL, languages r not that important in .net. All r RAD,
all are jitted, all r controlled by CLR.
 
A

Abubakar

:) well I can hardly be a C# expert, but here's what u r looking for:
byte b= 65;

char a= 'A';

MessageBox.Show( ((char)b).ToString() );

MessageBox.Show( ((int)a).ToString());

The first messagebox is showing you the translation from 65(byte type) to
"A" char type and than to string for showing in a message box. The second
messagebox is showing u a translation from "A" to int 65 and than to string
for the purpose of showing it in messagebox because that expects string.
Casting does the magic.
 
A

Abubakar

features, should not be used. But, for example, the Right function is not
a
part of the String class - one of the very few examples.
As I said that I never use Mid, because I know that string class has its
equivilent substring function which also is used inplace of right or left
functions. And that'll be true for all .net compliant languages and its so
exciting to realize that I already know that whatever .net language I'll use
in the future will have a string type for handling strings and they'll have
a substring functionality and most of my confusions or problems already gets
solved just because of .net's common type system feature. I remember about 3
years ago I had to make a small project in delphi (approx 1 month coding
time) and I was meeting with delphi programmers most of the time and asking
them how to do conversions and how to use pointers and other stuff. Just an
example.
[...] Same thing
for other features like unsafe blocks.
yes , unsafe is not CLSCompliant and I would not use it.
[...] For example, you can create code comments in C#. Would you refuse
to use them in C# just because they are not available in Vb.NET? Same
thing
well C# code comments is another thing, it helps me to document my code and
thats a very nice feature specific to C# but it does not stop me from
writing code if its not present in VB, I'll just not be able to use it
throuhg VB.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top