How to limit a field length (of type text)?

erugalathaerugalatha Member Posts: 120
Hi,

I have vars defined of type text and I have set their lengths. In code I want to limit the length of text that goes into that field i.e. I do not want to receive the overflow error. How can I limit the length of data that goes into a text variable (and thus into a field)?

Thanks for your help.

Comments

  • SavatageSavatage Member Posts: 7,142
    I'm assuming these fields are being populated using an outside file.

    http://www.mibuso.com/forum/viewtopic.php?t=12785
  • erugalathaerugalatha Member Posts: 120
    Thanks for reply.

    No I am creating a file on disk using the File.WRITE(Line) where the lines within the file have to be of specific length.

    The lines are made up of fields from the vendor e.g. sort code for a bank account.

    e.g. Sort Code should only ever be 6 chars long so I have defined
    a variable of type text that is of length 6. I then take the data from the Vendor."Sort Code" field and put it into my vSortCode variable and add it to my LINE variable. But before I add the vSortCode variable to the LINE I want to check it is only ever 6 chars.

    When the LINE has the data I require then I write it out to file.

    Thanks.
  • SavatageSavatage Member Posts: 7,142
    But it's your field don't you have control on it always being 6 characters?

    does it have to be a solid 6 for example if the code is AB1 you need to output 000AB1 or something? Do you have codes that are over 6?

    I'm not understanding :-k

    COPYSTR
    Use this function to copy a substring of any length from a specific position in a string (text or code) to a new string.

    NewString := COPYSTR(String, Position [, Length])
  • erugalathaerugalatha Member Posts: 120
    Hi,

    Not necessarily ... the sort code can be 93-47-98, for example. So I am using DELCHR to remove the - but I am finding that I get an overflow sometimes which means there's data in there that may be over 6 chars long.

    If it is I want to raise an error and quit.

    Thanks
Sign In or Register to comment.