1 Attachment(s)
Initializing Char variables the easy way
My programming policy prohibits the use of the Microsoft.VisualBasic namespace, this is to ensure good programming practice and future-proofing. There has been only 1 annoying problem with this...
I was fed up with the non-existant way to give a Char variable an initial value.
This is my remedy.
It is a small class that wraps a private byte buffer that allows rapid callup of char values based on their ascii code.
I'll let the code speak for itself, it is commented with VBCommenter :)
If you only have to initialise one or two chars then you might as well do it manually, but for many char assignments (ie in a loop) then this is the most efficient approach (more or less ;)).
So if you too find yourself without the VisualBasic namespace, this is my gift to you :D
EDIT: UPDATED VERSION WITH AN ASC() FUNCTION :D
Re: Initializing Char variables the easy way
Whats wrong with
VB Code:
Option Strict On
Option Explicit On
'...
Private ContantCharacter as Char = "D"c
'...
Re: Initializing Char variables the easy way
You won't always want "D" at runtime. Maybe you don't know what you'll need until the program is running. This has been discussed before.
Say you need an array of chars ranging from 0 to 255, are you telling me you'd want to sit there and hard-code 255 lines? Nah me neither. You'd do it in a loop. Getting chars from their ascii number is awkward in proper VB.Net code. Well, it used to be. :D
Re: Initializing Char variables the easy way
UPDATED Version. See first post's attachment.