Thread: Fixed String

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Fixed String


    Hey,

    how to create a fixed limit String in VB? In previous versions, it was:
    Dim Name As String * 10 (length of 10 characters)

    But now I'm using VB2012 and it doesn't work.

    Thanks for a reply.
  2. #2
  3. Humble Learner
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Location
    Bangalore, India
    Posts
    280
    Rep Power
    119
    I can't think of any valid reason to use fixed length strings in modern systems. That does not have any performance boost either.
  4. #3
  5. Type Cast Exception
    Devshed Supreme Being (6500+ posts)

    Join Date
    Apr 2004
    Location
    OAKLAND CA | Adam's Point (Fairyland)
    Posts
    14,954
    Rep Power
    8617
    Originally Posted by debasisdas
    I can't think of any valid reason to use fixed length strings in modern systems.
    In older VB I used them was when writing to or reading from fixed length files (or when dealing with binary files but that purpose is obsolete now). Also when making API calls. Haven't needed them lately.

    There is the VBFixedStringAttribute Class which treats a string as if it were fixed, but is not really a fixed string.
    medialint.com

    “Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    289
    Rep Power
    44
    When dealing with calls that require a fixed length buffer, I use a string filled with Null characters (Chr$(0)). For example, to read in a binary file:
    FileNum = OpenFile(FileName, 5, 0, 80)
    strBuffer = String$(LOF(FileNum), Chr$(0))
    Get #FileNum, , strBuffer
    Close #FileNum

    J.A. Coutts

IMN logo majestic logo threadwatch logo seochat tools logo