Results 1 to 4 of 4

Thread: string data type max size problem

  1. #1

    Thread Starter
    Registered User Lior's Avatar
    Join Date
    Jan 2000
    Posts
    307
    Guys,
    If i wanna set A to be of the data type of String,
    But I want it to be able to get max characters number of 8

    How do I do this?
    I tried this code:
    Code:
     
    Dim A as String *8
    But when I do A="XX" so A actually gets "XX " instead of just "XX"

    Could you help me, please?

  2. #2
    Guest
    You could use a property to make sure a never exeeds 8

    Code:
    Option Explicit
    Private m_a As String
    
    Private Property Let a(ByVal NewA As String)
        If Len(NewA) > 8 Then
            NewA = Left$(NewA, 8)
        End If
        m_a = NewA
    End Property
    
    Private Property Get a() As String
        a = m_a
    End Property
    Now you just use a as the 'String', when you put a value in a, it goes to the proerty let, it the size exeeds 8 it only takes the first 8 characters and stores them in m_a, when you access/get a it returns the value in m_a.


    Code:
        a = "This is a test!"
        MsgBox a

    Hope it helps

  3. #3
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ottawa,ON,Canada
    Posts
    217
    Lior,

    I'm not quite sure what you're asking, but I can tell you that when you specify a string to be a fixed size VB automatically fills the string with NULL characters. What does this mean, you may ask. Well, whatever you assign to the variable will be padded with NULLs in other words if you displayed the string after assigning it "XX" it would look something like "XX000000" where 0 is a NULL character which will display as a non-printable character. Also. if you try concatenating this string with another string on to the end it won't append, this is because in the string data-type, a NULL character marks the end of a string and anything beyond its end will not be displayed. VB will only look into the string as far as the first NULL char. An easy fix to this is to simply assign your fixed length string to another variable-length string and then do your appending operations.

    Again, I'm not quite sure if this is what you wanted, or not, but I hope it points you in the correct direction.

    As a side note, please be respectfull to the other memebers of this forum, we are all trying to help one another the best we can. If you don't like a response to one of your threads, then just ignore it! Otherwise I don't think you'll get too many responses and will mostly get flamed. Just a bit of advice. If you want a more mature forum then try out vb-zone.com at dev-x, there are alot of jerks there to.

  4. #4

    Thread Starter
    Registered User Lior's Avatar
    Join Date
    Jan 2000
    Posts
    307

    Thumbs up Thanks Man. It really helped me.

    Read the above.

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