Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String lenghts

Status
Not open for further replies.

CleoMan

Programmer
Jun 18, 2003
110
ZA
Once again i have a stupid question:

I want to declare a string type variable to have only a fixed size limit, for instace 2 characters.

I know Visual Basic allows you to do this in the type declaration (Dim x as string*2), is there a similar command in Paradox 9?

Thanks in advance
Richard
 
Hmmm, the short answer to a not so stupid question is NO. Shouldn't be to difficult to code around though but still not as easy as in vb.

Perrin
 
Richard,

Perrin's right, ObjectPAL strings aren't sets of characters, as they are in some other languages, such as C++, etc. You can always validate the length of a string using size(), substr(), and so on.

If you're trying to limit data entry to two characters, try defining a Picture either on a field object or as a validity check (valcheck) on the field in the table's structure. (It depends on how hard you want this restriction enforced. If the field is used by more than one form, the valcheck is the better way to go. On the other hand, it's sometimes helpful for code to be able to "break" the rules when needed; in those cases, the field object is a better choice.

Hope this helps...

-- Lance
 
The values come from a table (or various tables) and the size of the strings in the table is not the same size as is prescribed for another part of the program.

See I need to limit the size of my declared strings becuase i need to write those strings to a batch text file and if the specifications of the file are not met precisely, then... well it's not a good thing!

Any suggestions? Maybe i could use substr?

Thanks a bunch
Richard
 
Should be simple to handle, something like:

var
sLength nuber
modifiedString string
endVar

sLength = 2 ; desired string length
modifiedString = field.to.evaluate
if modifiedString.size() > sLength then
modifiedString = modifiedString.substr(1,sLength)
endif

For ease of use and re-usability I'd put the code in a method and have it return the modifiedString

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top