PC Review Forums Newsgroups Microsoft DotNet Microsoft VB .NET Re: chr() .Net equivalent

Reply

Re: chr() .Net equivalent

 
Thread Tools Rate Thread
Old 30-03-2008, 05:00 PM   #1
Armin Zingler
Guest
 
Posts: n/a
Default Re: chr() .Net equivalent


"David Griffiths" <dayvg69@yahoo.nospam.co.uk> schrieb
> Hi all
>
> I thought I would convert an old program to use just .net, removing
> the Microsoft.Visual Basic namespace.
>
> I seem to have succeeded except for just one are. What is the .net
> equivalent to chr(). I am capturing the keyboard input and if it's a
> carriage return I call the Caluculate Subroutine.
>
> Private Sub txtVat_KeyPress(ByVal sender As Object, ByVal e As
> System.Windows.Forms.KeyPressEventArgs) Handles txtVat.KeyPress If
> Not (Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar) Or
> e.KeyChar = dp) Then
> e.Handled = True
> End If
>
> If e.KeyChar = Chr(13) Then
> Call Calculate()
> End If
> End Sub
>
> I have tried replacing the chr(13) with
>
> If e.KeyChar = Environment.NewLine Then
> Call Calculate()
> End If
>
> No joy. I'm sure there must be a way to do this in .net.


Microsoft.VisualBasic is part of .Net, so you can keep using Chr(). You
can also use vbCr constant. Or Controlchars.CR. Environment.NewLine is
CR+LF, therefore it does not work. You can also use
"Convert.ToChar(13)".

If you want to handle keys not chars, you should handle the KeyDown
event.


Armin

  Reply With Quote
Old 30-03-2008, 08:11 PM   #2
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
Default Re: chr() .Net equivalent

"Armin Zingler" <az.nospam@freenet.de> schrieb:
> Microsoft.VisualBasic is part of .Net, so you can keep using Chr(). You
> can also use vbCr constant. Or Controlchars.CR. Environment.NewLine is
> CR+LF, therefore it does not work. You can also use
> "Convert.ToChar(13)".


I agree, but note that 'Convert.ToChar' is not known by the compiler and
thus the conversion is performed at runtime. If you are using 'ChrW' or
'ControlChars.CR' a char literal is stored in the IL.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off