ASCII code

  • Thread starter Thread starter Abubakar
  • Start date Start date
Hi Abubakar,

I have looked up what are the equivalents of this C# code in VB.net
byte b= 65;
dim b as byte = 65
char a= 'A';
dim a as Char = "A"c
MessageBox.Show( ((char)b).ToString() );
Messagebox.show(Chr(b).tostring)
Cast the value type to Char
MessageBox.Show( ((int)a).ToString());
Messagebox.show(Asc(a).ToString
Cast the the value from Char to a decimal type and represent it as string

All others are not equivalents but other code.

:-))

Cor
 
:) heheh
yeah you are using the Chr here again,,,,, after all this discussion :)
I'v know chr for the past 3 years :)
 
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
I'm not the one who is confused here! ;-)

Did you read the part about how ChrW & AscW will create IL directly, no
function calls involved?

If ChrW & AscW does not generate a call to a DLL, you should be able to
safely use them on Rotor... Of course sometimes ChrW & AscW does generate
the function call...

I say "should be able to" as I don't know if the Rotor loader looks for the
referenced assembly when it loads the primary assembly, or it looks for the
referenced assembly when it uses the assembly. The regular Framework (for
Win32) looks for the assembly when it JIT's a function that uses the
assembly.

Personally if running my VB.NET programs on Rotor or Mono was a requirement,
I would ensure that there was a version of the Microsoft.VisualBasic
assembly (at least the part that I use) available on that platform, even if
I needed to implement that part myself. It appears that www.go-mono.com is
61% complete with their implementation of Microsoft.VisualBasic...


I believe your confusion is steaming from you consider ChrW to be a VB.NET
specific library function, I consider it a VB.NET "keyword" (yes I know it
is not an actual keyword). I would use ChrW where you were using Casting in
your other example... Maybe this is where you think I'm confused.

I suspect the other part you are confused about is the name VisualBasic in
Microsoft.VisualBasic.DLL. Despite the VisualBasic in the name I consider
them to be an extended runtime available to any .NET language, including C#!


The way I am reading your message is: I need to use VB.NET, however I only
want to use a limited (suboptimal) subset, which to me is naive. However I
can understand your reasons for thinking that way.

I say suboptimal subset, as I suspect you also avoid actual keywords, such
as CType, CInt, CSng and the like that call into Microsoft.VisualBasic.DLL.
At least if you don't based on your explanations you may want to start!

IMHO its "better" to fully learn a language so that I can fully leverage the
language, rather then going out of my way to avoid features that enable me
to more quickly write programs!

Don't get me wrong, I like to know what VB.NET's runtime is doing and how to
do it in the Framework itself and I may choose the Framework method over the
runtime function. I just do not agree with "I need to avoid VB.NET features,
at all cost!" mentality! As a lot of times the VB.NET's runtime functions do
it with significantly "less pain for the gain", which means that I can call
a simple runtime function (which again ARE usable in C#!) or I can write the
"same" function myself.

Hope this helps
Jay
 
Hi Jay B,

See the last 4 messages in my messagethread above this, I think Abubakar
agreed.

:-))

Cor
 
Abubakar said:
As I said that I never use Mid,

I wrote "Right", not Mid. There is *no* equivalent in the String class.
[...] Same thing
for other features like unsafe blocks.
yes , unsafe is not CLSCompliant and I would not use it.

That's really strange!
[...] 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.

You mustn't use it in C# because it's not available in VB. ;-)

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
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.

I haven't used Rotor. I use .NET and Mono. But, all you have to do is
look at the IL for a compiled VB.NET program and you will see the
reference... Here is the manifest for a VB.NET winforms app compiled
with the Mircrosoft.VisualBasic reference removed:

..assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
// .z\V.4..
.ver 1:0:5000:0
}
..assembly extern Microsoft.VisualBasic
{
.publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )
// .?_....:
.ver 7:0:5000:0
}
..assembly extern System
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
// .z\V.4..
.ver 1:0:5000:0
}
..assembly extern System.Data
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
// .z\V.4..
.ver 1:0:5000:0
}
..assembly extern System.Drawing
{
.publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )
// .?_....:
.ver 1:0:5000:0
}
..assembly extern System.Windows.Forms
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
// .z\V.4..
.ver 1:0:5000:0
}
..assembly extern System.Xml
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
// .z\V.4..
.ver 1:0:5000:0
}
..assembly OfficeExperiment
{
.custom instance void
[mscorlib]System.CLSCompliantAttribute::.ctor(bool) = ( 01 00 01 00 00 )
.custom instance void
[mscorlib]System.Reflection.AssemblyCopyrightAttribute::.ctor(string) =
( 01 00 00 00 00 )
.custom instance void
[mscorlib]System.Reflection.AssemblyTitleAttribute::.ctor(string) = ( 01
00 00 00 00 )
.custom instance void
[mscorlib]System.Reflection.AssemblyTrademarkAttribute::.ctor(string) =
( 01 00 00 00 00 )
.custom instance void
[mscorlib]System.Runtime.InteropServices.GuidAttribute::.ctor(string) =
( 01 00 24 42 33 31 42 42 32 31 46 2D 37 30 41 32 // ..$B31BB21F-70A2
2D
34 35 36 43 2D 42 32 32 38 2D 35 35 34 43 37 // -456C-B228-554C7
44
43 35 34 42 33 39 00 00 ) // DC54B39..
.custom instance void
[mscorlib]System.Reflection.AssemblyProductAttribute::.ctor(string) = (
01 00 00 00 00 )
.custom instance void
[mscorlib]System.Reflection.AssemblyCompanyAttribute::.ctor(string) = (
01 00 00 00 00 )
.custom instance void
[mscorlib]System.Reflection.AssemblyDescriptionAttribute::.ctor(string)
= ( 01 00 00 00 00 )
.hash algorithm 0x00008004
.ver 1:0:1502:16446
}
..mresource public OfficeExperiment.Form1.resources
{
}
..module OfficeExperiment.exe
// MVID: {B13E844D-D6DF-4B51-ACC5-ABEE666F77EC}
..imagebase 0x11000000
..subsystem 0x00000002
..file alignment 4096
..corflags 0x00000001
// Image base: 0x06ba0000

Notice the reference to Microsoft.VisualBasic?
 
I wrote "Right", not Mid. There is *no* equivalent in the String class
the way substring works, it gives the functionality of right and left and mid at the same time. Try it.
 
* "=?Utf-8?B?QWJ1YmFrYXI=?= said:
the way substring works, it gives the functionality of right and left
and mid at the same time. Try it.

ACK. The question "Why?" still remains unanswered.
 
I'm not the one who is confused here! ;-
[...]Maybe this is where you think I'm confused
well english is not my native language I think I shouldnt have used the word "confused", I was not able to make my self clear in words :
I say "should be able to" as I don't know if the Rotor loader looks for th
referenced assembly when it loads the primary assembly, or it looks for th
referenced assembly when it uses the assembly.
Just for the sake of discussion, to test what you said I wrote a small console application code that used chr function and compiled it (VS.NET2003 ) after including Microsoft.VisualBasic namespace and after building the code i ran that application in rotor through clix and it worked just fine. So CLR is not trying to load the assembly first just because its code maybe used but it'll load it when its actually needed. And as you said that chr function is inlined and does not refernce any other assembly so vb dll is not needed. After that I replaced the code to use the Left function, also inside the vb namespace, but the clix gave an exception that microsoft.visualbasic file was not found. Thanx for giving me an idea to experiment and I learned something new here. And yes, vb Casting works successfully in clix
Although I dont understand the IL
IL_0006: ldc.i4.s 6
IL_0008: box [mscorlib]System.Cha
this IL is the result of the chr(65). Why is it boxing 65 and whats the system.char, is it the return type. No other code
I just do not agree with "I need to avoid VB.NET features
at all cost!" mentality
well I was never of that mentality that avoid vb dll function calls at all cost. I just wanted to know the .net equivilent of chr function so if I have to do it in some other .net lanaguage I'll be able to do it. I already know the C# way, why not see what functions are available in the .net bcl for it. I dont see anything wrong with that
 
Abubakar said:
the way substring works, it gives the functionality of right and left
and mid at the same time. Try it.

No, the missing functionality is the calculation of the remaining length.
Using Substring, I have to calculate it on my own. Try it.
 
I'm not the one who is confused here! ;-)
[...]Maybe this is where you think I'm confused.
well english is not my native language I think I shouldnt have used the word "confused", I was not able to make my self clear in words :)
I say "should be able to" as I don't know if the Rotor loader looks for the
referenced assembly when it loads the primary assembly, or it looks for the
referenced assembly when it uses the assembly.
Just for the sake of discussion, to test what you said I wrote a small console application code that used chr function and compiled it (VS.NET2003 ) after including Microsoft.VisualBasic namespace and after building the code i ran that application in rotor through clix and it worked just fine. So CLR is not trying to load the assembly first just because its code maybe used but it'll load it when its actually needed. And as you said that chr function is inlined and does not refernce any other assembly so vb dll is not needed. After that I replaced the code to use the Left function, also inside the vb namespace, but the clix gave an exception that microsoft.visualbasic file was not found. Thanx for giving me an idea to experiment and I learned something new here. And yes, vb Casting works successfully in clix.
Although I dont understand the IL:
IL_0006: ldc.i4.s 65
IL_0008: box [mscorlib]System.Char
this IL is the result of the chr(65). Why is it boxing 65 and whats the system.char, is it the return type. No other code.
I just do not agree with "I need to avoid VB.NET features,
at all cost!" mentality!
well I was never of that mentality that avoid vb dll function calls at all cost. I just wanted to know the .net equivilent of chr function so if I have to do it in some other .net lanaguage I'll be able to do it. I already know the C# way, why not see what functions are available in the .net bcl for it. I dont see anything wrong with that.

Interesting... I've never really tried rotor, so I wasn't sure how that
would work. Another place you may have trouble is with the string
concatenation operators (&, &=). I believe these make calls into the
VB.NET runtime library. So, you'll want to use String.Concat instead.
 
Although I dont understand the IL:
IL_0006: ldc.i4.s 65
IL_0008: box [mscorlib]System.Char
this IL is the result of the chr(65). Why is it boxing 65 and whats the system.char, is it the return type. No other code.

I don't think the box instruction was due to the ChrW call, but more
likely the following statement in your code? What did you do with the
result?



Mattias
 
Tom,
Interesting... I've never really tried rotor, so I wasn't sure how that
would work. Another place you may have trouble is with the string
concatenation operators (&, &=). I believe these make calls into the
VB.NET runtime library. So, you'll want to use String.Concat instead.

I've only seen & and &= use String.Concat, I've never seen them use a VB.NET
specific routine.

However I'm not saying they don't!

Jay

Tom Shelton said:
I'm not the one who is confused here! ;-)
[...]Maybe this is where you think I'm confused.
well english is not my native language I think I shouldnt have used the word "confused", I was not able to make my self clear in words :)
I say "should be able to" as I don't know if the Rotor loader looks for the
referenced assembly when it loads the primary assembly, or it looks for the
referenced assembly when it uses the assembly.
Just for the sake of discussion, to test what you said I wrote a small
console application code that used chr function and compiled it
(VS.NET2003 ) after including Microsoft.VisualBasic namespace and after
building the code i ran that application in rotor through clix and it worked
just fine. So CLR is not trying to load the assembly first just because its
code maybe used but it'll load it when its actually needed. And as you said
that chr function is inlined and does not refernce any other assembly so vb
dll is not needed. After that I replaced the code to use the Left function,
also inside the vb namespace, but the clix gave an exception that
microsoft.visualbasic file was not found. Thanx for giving me an idea to
experiment and I learned something new here. And yes, vb Casting works
successfully in clix.
Although I dont understand the IL:
IL_0006: ldc.i4.s 65
IL_0008: box [mscorlib]System.Char
this IL is the result of the chr(65). Why is it boxing 65 and whats the system.char, is it the return type. No other code.
I just do not agree with "I need to avoid VB.NET features,
at all cost!" mentality!
well I was never of that mentality that avoid vb dll function calls at
all cost. I just wanted to know the .net equivilent of chr function so if I
have to do it in some other .net lanaguage I'll be able to do it. I already
know the C# way, why not see what functions are available in the .net bcl
for it. I dont see anything wrong with that.
 
Abubakar,
I just wanted to know the .net equivilent of chr function
so if I have to do it in some other .net lanaguage
I'll be able to do it. I already know the C# way,
why not see what functions are available in the .net
bcl for it. I dont see anything wrong with that.
In light that ChrW & AscW will inline, there is no direct .NET replacement
per se.

However as I stated in another message, ChrW ultimately calls
System.Convert.ToChar(int32).

I would expect you should be able to use System.Convert.ToInt32(char) as a
replacement for AscW.

However calling the BCL functions will intail a function call, where as ChrW
& AscW do not necessarily involve a function call. Of course the JIT may (or
may not) inline the System.Convert methods...

For Chr & Asc, you can use the respective System.Text.Encoding classes.

Hope this helps
Jay

Abubakar said:
I'm not the one who is confused here! ;-)
[...]Maybe this is where you think I'm confused.
well english is not my native language I think I shouldnt have used the
word "confused", I was not able to make my self clear in words :)
Just for the sake of discussion, to test what you said I wrote a small
console application code that used chr function and compiled it
(VS.NET2003 ) after including Microsoft.VisualBasic namespace and after
building the code i ran that application in rotor through clix and it worked
just fine. So CLR is not trying to load the assembly first just because its
code maybe used but it'll load it when its actually needed. And as you said
that chr function is inlined and does not refernce any other assembly so vb
dll is not needed. After that I replaced the code to use the Left function,
also inside the vb namespace, but the clix gave an exception that
microsoft.visualbasic file was not found. Thanx for giving me an idea to
experiment and I learned something new here. And yes, vb Casting works
successfully in clix.
Although I dont understand the IL:
IL_0006: ldc.i4.s 65
IL_0008: box [mscorlib]System.Char
this IL is the result of the chr(65). Why is it boxing 65 and whats the
system.char, is it the return type. No other code.
well I was never of that mentality that avoid vb dll function calls at all
cost. I just wanted to know the .net equivilent of chr function so if I have
to do it in some other .net lanaguage I'll be able to do it. I already know
the C# way, why not see what functions are available in the .net bcl for it.
I dont see anything wrong with that.
 
Interesting... I've never really tried rotor, so I wasn't sure how that
would work. Another place you may have trouble is with the string
concatenation operators (&, &=). I believe these make calls into the
VB.NET runtime library. So, you'll want to use String.Concat instead.
I'v checked with rotor, and executing the assembly with using clix (program
loader for managed apps), no problem excuting the & operator and &=, does
not make a call to vb dll. Ildasm shows it calls System.String::Concat:
so for the following code :
Dim s As String = "hello "
s &= "world"
Console.Write(s)

it produces the following msil:

IL_0001: ldstr "hello "
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: ldstr "world"
IL_000d: call string [mscorlib]System.String::Concat(string,
string)
IL_0012: stloc.0
IL_0013: ldloc.0
IL_0014: call void [mscorlib]System.Console::Write(string)


I'm not the one who is confused here! ;-)
[...]Maybe this is where you think I'm confused.
well english is not my native language I think I shouldnt have used the word "confused", I was not able to make my self clear in words :)
I say "should be able to" as I don't know if the Rotor loader looks for the
referenced assembly when it loads the primary assembly, or it looks for the
referenced assembly when it uses the assembly.
Just for the sake of discussion, to test what you said I wrote a small
console application code that used chr function and compiled it
(VS.NET2003 ) after including Microsoft.VisualBasic namespace and after
building the code i ran that application in rotor through clix and it worked
just fine. So CLR is not trying to load the assembly first just because its
code maybe used but it'll load it when its actually needed. And as you said
that chr function is inlined and does not refernce any other assembly so vb
dll is not needed. After that I replaced the code to use the Left function,
also inside the vb namespace, but the clix gave an exception that
microsoft.visualbasic file was not found. Thanx for giving me an idea to
experiment and I learned something new here. And yes, vb Casting works
successfully in clix.
Although I dont understand the IL:
IL_0006: ldc.i4.s 65
IL_0008: box [mscorlib]System.Char
this IL is the result of the chr(65). Why is it boxing 65 and whats the system.char, is it the return type. No other code.
I just do not agree with "I need to avoid VB.NET features,
at all cost!" mentality!
well I was never of that mentality that avoid vb dll function calls at
all cost. I just wanted to know the .net equivilent of chr function so if I
have to do it in some other .net lanaguage I'll be able to do it. I already
know the C# way, why not see what functions are available in the .net bcl
for it. I dont see anything wrong with that.
 
I don't think the box instruction was due to the ChrW call, but more
likely the following statement in your code? What did you do with the
result?

well the actual code was this:

Sub Main()
Console.Write("character {0}", chr(65))
End Sub

for which the following IL was generated:
IL_0000: nop
IL_0001: ldstr "character {0}"
IL_0006: ldc.i4.s 65
IL_0008: box [mscorlib]System.Char
IL_000d: call void [mscorlib]System.Console::Write(string,
object)
IL_0012: nop
IL_0013: nop
IL_0014: ret


works fine on rotor. I couldnt understand whats being boxed.

Wait a minute. Is it that the character type is being boxed because it is
being passed to the console as string. String is a ref type and char is
value. And because vb does not restrict us to explicitly cast it from char
to string, it does that sutomaticaly and hence also generates the box
instruction for us behind the scenes. I'm not sure, please confirm.



Although I dont understand the IL:
IL_0006: ldc.i4.s 65
IL_0008: box [mscorlib]System.Char
this IL is the result of the chr(65). Why is it boxing 65 and whats the
system.char, is it the return type. No other code.
 
Tom,

I've only seen & and &= use String.Concat, I've never seen them use a VB.NET
specific routine.

However I'm not saying they don't!

Jay

It doesn't... See, a long time ago - when I was first learning .NET,
I used to always remove the reference to Microsoft.VisualBasic. I don't
remember the context, but I was in a discussion once were it was
revealed to me about the automatic inclusion by the compiler. I started
playing around with using ILDASM to generate il files, removing the
reference, and then using ILASM to regenerate the assemblies. In the
process I found several situations where the compiler inserted calls to
some Microsoft.VisualBasic.CompilerHelper class (or something like that,
it's been a couple of years ago, so I don't remember all of the
details). I seem to remember & and &= being one of those cases, but the
OP as proven that to be mistaken... For all I know, that could have
been during the Beta or RC days, and it has since changed during release :)

--
Tom Shelton [MVP]
Powered By Gentoo Linux 1.4
"Zaphod grinned two manic grins, sauntered over to the bar
and bought most of it."

- Zaphod in paradise.
 
Wait a minute. Is it that the character type is being boxed because it is
being passed to the console as string.

No, it's being boxed because the second parameter of WriteLine has the
type Object.



Mattias
 
Tom,
It doesn't... See, a long time ago - when I was first learning .NET,
...
I seem to remember & and &= being one of those cases, but the
OP as proven that to be mistaken...
I don't know if the OP has proven that it never does! He has simple
confirmed my statement ;-)

I suspect you saw & and &= call into the runtime, when VB.NET was converting
one of the arguments to String!

For example the following calls functions in
Microsoft.VisualBasic.CompilerServices namespace in the
Microsoft.VisualBasic assembly:

Dim i As Integer
Dim ch As Integer
Dim s As String

s &= ch & i

To convert the ch & i variables to strings, then it calls String.Concat.

Although in the above case, VB.NET could simply call the String.Concat that
accepted Objects, and box i & ch...

Hope this helps
Jay


 
Back
Top