pxpic.txt 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. This text describes the Paradox picture input masking capabilities. It comes
  2. from chapter 5 of the Paradox PAL Programmers Guide for Paradox 4.0. This is
  3. what the nSEdit() function in the oCrt unit uses to mask user input when a
  4. picture string has been set for the nEC.Picture property.
  5. CHAPTER 5
  6. Using pictures to format input
  7. A PAL picture is a powerful and flexible tool for controlling what a
  8. user can type into a field during data entry. You can use pictures to
  9. a) shape and limit what the user can type into a field
  10. b) make data entry easier by filling in required or default values
  11. automatically.
  12. You can think of pictures as a way to define new field types by
  13. imposing restrictions on existing ones. In effect, the Social Security
  14. number picture in Example 5-1 defines a new type of alphanumeric
  15. field. So would a picture of a telephone number (with or without the
  16. area code), or a part number in which X is always the second
  17. character. Pictures can also help users fill in default or repetitive
  18. values during data entry. For instance, through a picture, you can
  19. specify that the X in the part number will be filled in automatically.
  20. Example 5-1 Using a picture to format input.
  21. Suppose you want a user to enter Social Security numbers. Use a picture
  22. to make sure the input has the proper format.
  23. PICTURE = "###-##-###"
  24. The picture fills in the hyphens automatically and ensures that the user types
  25. the proper number of digits -- no other characters will be accepted.
  26. When a picture is specified, the user must fill it exactly and
  27. completely. In Example 5-1, if a user starts by typing a letter, a beep
  28. results. If someone tries to leave the field before typing all the digits,
  29. Paradox displays the message Incomplete field and leaves the cursor
  30. in the field.
  31. While a user is typing data into a picture, pressing Backspace or Del
  32. erases characters and Ctrl-Backspace clears the field as long as the
  33. resulting entry fills the picture. You can also design the picture to fill
  34. in optional characters when the user presses Space.
  35. How to define pictures
  36. A picture is a kind of pattern. It consists of a sequence of literal
  37. characters interlaced with any of the match characters listed in
  38. Table 5-1.
  39. Table 5-1 Match characters in pictures
  40. Picture element Description
  41. ---------------- --------------------------------------------
  42. Match characters
  43. # Accept only a digit
  44. ? Accept only a letter (upper- or lowercase)
  45. & Accept only a letter, convert to uppercase
  46. @ Accept any character
  47. ! Accept any character, convert to uppercase
  48. t Any character taken literally
  49. Special characters
  50. ; Take next character literally
  51. * Repetition count
  52. [] Option
  53. {} Grouping operators
  54. , Set of alternatives
  55. ---------------------------------------------------------------
  56. Any number, letter, or punctuation character not defined as one of the unique
  57. match or special characters (that is, anything you can type that isn't on this
  58. list) is taken literally.
  59. The Social Security number in Example 5-1 was specified with the
  60. picture ###-##-####. The # is a match character that accepts only
  61. digits in its place. The hyphen is a literal character, meaning that it
  62. must literally appear in the typed value (matched exactly).
  63. Literal characters in a picture are filled in automatically unless
  64. a) you specify otherwise (see "Inhibiting automatic fill-in" later in
  65. this chapter)
  66. b) they occur at the beginning of a picture (this helps to
  67. accommodate blank fields)
  68. For example, when the cursor arrives at a blank field governed by the
  69. picture
  70. ABC-###
  71. the "ABC-" is not filled in automatically because it occurs at the
  72. beginning of the picture. But as soon as the user types A or a, or
  73. presses Space, the "ABC-" appears.
  74. If you want to specify a literal character that happens to be a match
  75. character, precede it with a semicolon (;). For example, here's how
  76. you'd specify a part number that contains three letters, a hyphen, and
  77. a number sign (#):
  78. ???-;#
  79. If you omitted the semicolon, the picture would call for three letters,
  80. a hyphen, and a digit. You can use the semicolon in a picture to
  81. precede any of the characters in Table 5-1 that you want to be taken
  82. literallyincluding the semicolon itself. Here are some other
  83. examples:
  84. $*#.##;@ ; price each, like $345.67@
  85. *?;? ; questions, adding ? to any text
  86. ###;,### ; six-digit number with comma separating thousands,
  87. ; like 345.678
  88. ???;;;# ; part number with three letters, semicolon, and
  89. ; number sign, like ABC;#
  90. Special features of
  91. pictures
  92. The special features of pictures are described in detail in the
  93. following sections. These spedal features are summarized in Table 5-2
  94. Table 5-2 Special features of pictures
  95. Operator Name Examples Satisfied by
  96. -------- -------- ----------------- ---------------------------------------
  97. * Repeat *5# Five numbers; equivalent to #####
  98. *# Zero or more numbers
  99. (*#.##), *#.## Currency amounts, negative or
  100. positive
  101. &*? Initial capitalization of a single word
  102. { } Set *5{##} Ten numbers or five times the set of
  103. two numbers
  104. {20,40,60,75,100}W Light bulbs in different wattages
  105. [ ] Optional ###-####[###[#]] Phone number with or without a 3-
  106. or 4-digit extension
  107. *[&[*?][@][ ]] Any number of capitalized words
  108. and initials
  109. , Alternative RED,BLUE Literals "RED" or "BLUE"; entering
  110. an R fills RED, a B fills BLUE
  111. ###,## 2- or 3-digit number; ##,### would
  112. not work
  113. { } Inhibit ###{-)## The hyphen is not filled in
  114. Fill automatically: the user must press
  115. Space to have the hvohen filled in
  116. ------------------------------------------------------------------------------
  117. Repetition counts
  118. You'll find the repetition count match character (*) useful when
  119. specifying pictures for long fields. For example, these two pictures
  120. are equivalent:
  121. *25#
  122. #########################
  123. The match character * in the first picture is followed by a number,
  124. which is the number of times to repeat the match character or literal
  125. that follows. If you omit the *, the picture would mean the number 25
  126. followed by any other digit.
  127. To repeat a group of match characters, enclose the group in braces {}
  128. following the number of repetitions:
  129. *3{##:} ; equivalent to ##:##:##:
  130. Notice how this picture mixes literal and match characters in the
  131. group. Each group consists of two digits to be typed by the user and
  132. a colon to be filled in by Paradox.
  133. Also use the grouping braces {} when you want to repeat a single
  134. number, as in
  135. *3{5}# ; equivalent to 555# (three fives followed by any other digit)
  136. Without the braces, Paradox would think you wanted *35#, 35
  137. repetitions of "#".
  138. Omitting the number after the *, tells Paradox to accept zero or more
  139. repetitions of the character or group. You might use this variation
  140. when you want the user to type at least a certain number of
  141. characters, but perhaps more. For example, this picture in a State field
  142. &&*&
  143. requires at least the two-letter state abbreviation, but would also
  144. accept a state name spelled out in full.
  145. To use the * as a literal character in a picture, precede it with a
  146. semicolon (;). For example,
  147. ;*###;* ; equivalent to *###*
  148. Optional elements
  149. You can make part of a value optional by enclosing the
  150. corresponding part of the picture within brackets [ ]. This means that
  151. the user can enter data for that part of the value, but is not required
  152. to do so. The user can accept the optional part by typing a character
  153. that fits it or by pressing Space if the character is a literal.
  154. Note: When the user reaches an optional part of a value, any matching
  155. character accepts the entire optional part. For example,
  156. [###l ###-####
  157. doesn't make the area code optional. Suppose the user tries to skip the
  158. area code and types the first digit of the phone number. Since this
  159. matches the first optional character, Paradox assumes it is the area
  160. code and requires all 10 digits.
  161. Similarly, the following picture won't work to specify a number with
  162. either two or three digits:
  163. [#]##
  164. since the first digit typed is always understood to be the [#]. To
  165. specify an optional number of digits, place the optional portion after
  166. the required portion:
  167. ##[#]
  168. Here, the first two digits typed will match the mandatory #
  169. characters, and the third digit may or may not be added. Remember
  170. that pictures are always scanned left to right, so the optional portion
  171. of a repeating element should always come at the end.
  172. Example 5-2 demonstrates the correct way to create a picture for a
  173. telephone number with an optional area code.
  174. Example 5-2 Options in pictures
  175. The following picture accepts a 7-digit telephone number with an optional,
  176. parenthesized 3-digit area code:
  177. [(###)] ### - ####
  178. The user can fill in this field in two ways:
  179. a) If the first character typed is the left parenthesis or Space,
  180. it matches the optional part of the picture and Paradox will look for a
  181. 3-digit area code before the 7-digit number.
  182. b) If the first character typed is a digit, Paradox ignores the option and
  183. skips to the required digits. The right parenthesis (if used) and hyphen
  184. are filled in automatically.
  185. Literal characters at the beginning of an optional part of a value are
  186. never filled in automatically. For example, in the picture
  187. #[ABC]#
  188. the characters "ABC" are not automatically filled in after the user
  189. types the first digit. They are filled in if the user types "A" or "a" or
  190. presses Space. The automatic fill-in occurs only when the filled-in
  191. characters are mandatory, or when the user explicitly elects the
  192. option by typing the first character or pressing Space.
  193. Optional elements can be nested, as in the following picture:
  194. #[[#[a]]
  195. Because the characters [ and ] are used to specify options, they must
  196. be preceded by a semicolon (;) if you want to use them literally in a
  197. picture.
  198. Alternative choices
  199. Many applications require the user to type one of several possible
  200. choices as part or all of a data value. A part number, for example,
  201. might consist of a three-digit number, followed by a color code of
  202. RED, GRE, YEL, or BLU, followed by another three-digit number.
  203. You specify a set of alternatives in a picture as a comma-separated list
  204. of alternatives. For example, you could specify the color-coded part
  205. numbers like this:
  206. ###RED###, ###G RE###, ###YEL###, ###BLU###
  207. or, more succinctly,
  208. ###{RED,GRE,YEL,BLU}###
  209. Both of these pictures have the same effect. In the second, the braces
  210. have been used to group the alternatives.
  211. As with bracketed options, literal characters at the beginning of an
  212. alternative are not filled in automatically. For example, if the user
  213. types 345 in the preceding example, the characters RED are not then
  214. filled in. But if the user then presses Spacebar or types r, the ED is
  215. filled in. Similarly, if the user types g, the RE is filled in, and so on.
  216. Paradox always fills in the first matching alternative it finds; thafs
  217. why RED is filled in when the user presses Space. To get one of the
  218. other options, the user must type its first letter.
  219. Example 5-3 Alternatives in a date picture
  220. The following example lets you restrict input in a date field to dates falling
  221. within the first week of a month:
  222. #[#]/{1.2,3,4.5,6,7}/##[#][#]
  223. Note the use of optional digits to permit months to have either one or two
  224. digits and years to have two, three, or four. Again, since pictures are scanned
  225. from left to right, the optional elements always come at the end of that part of
  226. the picture.
  227. The different alternatives need not be composed of literal characters;
  228. they can be picture specifications of any kind (Example 5-3). For
  229. example, here's another way of specifying a two- or three-digit
  230. number:
  231. ###,##
  232. Again, the picture ##,### wouldn't do the job, because once the first
  233. two digits are typed, the first alternative will be selected and the
  234. picture will be fully satisfied. If the user then types a third digit, a
  235. beep sounds.
  236. The following picture specifies that an alphanumeric value can either
  237. be True or False:
  238. True,False
  239. Using this picture or variations on it, you can easily obtain the effect
  240. of a logical value or create a field of type logical in a Paradox table.
  241. As with other match characters, if you want to use a comma (,) as a
  242. literal character in a picture, you must precede it with a semicolon (;).
  243. Inhibiting automatic fill-in
  244. Some users find automatic fill-in of literal characters annoying
  245. particularly if they seldom look at the screen as they type. To inhibit
  246. it, simply enclose the literal characters you don't want filled in within
  247. braces I }. For example, this picture inhibits the fill-in of hyphens in
  248. Social Security numbers:
  249. ###{-}##{-}####
  250. When the user types the first three digits, the hyphen (-) is not filled
  251. in. To enter it, the user can press - or Space.
  252. Sometimes you must inhibit fill-in to get the effect you want. In the
  253. color-coded part numbers in the previous section, suppose we had
  254. the color code BRO in addition to RED, GRE, YEL, and BLU. Adding
  255. BRO to the preceding picture gives
  256. ###{RED,GRE,YEL,BLU,BRO}###
  257. Now suppose the user types three digits and then a b. Since BLU is
  258. the first possible match (left to right), Paradox would fill in the LU
  259. automatically. This could be wrong, since the user may have had
  260. BRO in mind rather than BLU. To solve this problem, use either of
  261. these pictures to inhibit automatic fill-in of the L:
  262. ###{RED,GRE,YEL,B{L}U,BRO}###
  263. ###{RED,GRE,YEL,B{LU,RO}}###
  264. The second picture, in effect, factors the letter B out of both BLU and
  265. BRO. This forces the user to type two characters to specify the blue or
  266. brown color code. The (LU, RO} is a set of alternative choices that has
  267. been nested within the larger set of choices.
  268. Going a step further, here's how you could inhibit all of the fill-in:
  269. ###(R{E}{D},G{R}{E},Y{E}{L},B{L}{U},B{R}{0}}###
  270. Picture examples
  271. By using PAL's regular and special match characters, you can create
  272. an almost endless variety of picturesin effect, new data typesfor
  273. your applications. Here are just a few examples:
  274. (*#.##),*#.## ; currency amounts, using parentheses for
  275. ; negative quantities
  276. #[#][#]*{;,###} ; positive integers with commas separating
  277. ; groups of three digits
  278. {20,40,60,75,100}W ; light bulbs in different wattages
  279. {A,B,C.D,E,F,G,H}[R]##-## ; tire sizes
  280. &*? ; initial capitalization of a single word
  281. &. &. &*? ; two initials followed by a capitalized name
  282. ; of any length
  283. *[&[*?][@][ ]] ; any number of capitalized words or initials
  284. {##}:{##}:{##} ; for time