declare a string of fixed length

Posted on 2005-04-08
Last Modified: 2010-08-05
how do you declare a string of fixed length?

Dim myStringVar as String _____

Question by:brokeMyLegBiking
    LVL 2

    Expert Comment

    A string is a data type, and as far as I know of, you are not able to set a size.
    Basically, if you want to specify a exact size, you could create a Char array.

    You could also just programatically allow a specific sized string to be entered into the variable.
    LVL 32

    Expert Comment

    <VBFixedString(15)> Private YourStringName As String
    LVL 32

    Expert Comment

    LVL 4

    Author Comment

    All the <VBFixedString(15)> does is indicate that the string should be fixed length, it doesn't enforce it.

    I would likea a way to force an error to be thrown if the wrong string length is assigned.

    jong3, how do I declare a char array and assign values to it?

    LVL 13

    Expert Comment

    Check this PAQ

    I posted an example of how you could create a fixed lenght string class also.

    LVL 13

    Accepted Solution


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now