Results 1 to 4 of 4

Thread: Initializing Char variables the easy way

  1. #1

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    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

    EDIT: UPDATED VERSION WITH AN ASC() FUNCTION
    Attached Files Attached Files
    Last edited by wossname; Mar 17th, 2005 at 10:27 AM.
    I don't live here any more.

  2. #2
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Initializing Char variables the easy way

    Whats wrong with

    VB Code:
    1. Option Strict On
    2. Option Explicit On
    3.  
    4. '...
    5.  
    6.    Private ContantCharacter as Char = "D"c
    7.  
    8. '...
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  3. #3

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    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.
    I don't live here any more.

  4. #4

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Initializing Char variables the easy way

    UPDATED Version. See first post's attachment.
    I don't live here any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width