|
|
|
|||||
| The term "string", when used to describe a component of a computer program, refers to a series of characters that are grouped together and act as a single item. Strings can be useful when needing to send a line of text to a hardware device such as a serial device, a printer or a LCD Display. | |||||||||
| An example of how strings are used would be a line in a program that sends the word "Hello" to a printer. (Ptr.VString = "Hello") What is actually happening when this line gets executed, is that a series of 5 separate data transfers are being made, one for each character in the word. Where as the statement X = 5 will assign a numeric value of 5 to the variable X, a statement like X.VString = "Hello" will assign 5 values to the variable X. Each of the 5 values represent one of the characters in the string "Hello" starting with the leftmost character. This is done by assigning the ASCII value of the first character (H) to X, then the ASCII value of the second character (e), and so on until each character in the string has been assigned. The property VString is much like the property Value except that it is a string data type that will allow assignments from other string data types. Typically when the VString property is read, it will return a single ASCII character representing the Value property. However some objects, such as the oBuffer, have a more VString property that return a series of characters as one value. A statement like X.VString = Z.VString (where Z is a buffer object) will do an assignment for each value in the buffer in the manner described above. |
|||||||||
| When a string is being assigned to the oSerialH or the oSerialPort Object, each character that is assigned is sent serially out as serial data. In the following example, the string "Hello World" is sent to a hardware device, such as a PC, connected to the ooPIC's serial I/O lines. When a string is being read from an oSerial or oSerialPort Object, a single character is returned that represents the next byte received over the serial I/O line. |
|||||||||
| When a string is being assigned to the oDataStrobe Object, each character that is assigned is sent to the Object that the Output pointer is pointing to. In the following example, the string "Hello World" is sent to an Printer that is connected to I/O Group 3. Reading the VString property of an oDataStrobe Object will always return ASCII character 0. |
|||||||||
| When a string is being assigned to an oBuffer Object, each character that is assigned will fill one location in the oBuffer Object's array. In the following example, the string "Hello World" fills the all of the oBuffer Object's array space except the last byte.
Reading the VString property of an oBuffer Object will return the entire array. In the above example, reading the VString property would return "Hello World" plus an ASCII character of whatever was in the last byte of the oBuffer Object's 12 byte array. The oBuffer also has a RTCString property that works much like the VString property except that it inserts colons between every pair of numbers so that it will be formatted like a clock. IE. "12:59:00" |
|||||||||
| When a string is being assigned to an oSP0256 Object, each character that is assigned will be sent to the oSP0256 Object after the busy line is checked. In the following example the string "ABC" is sent to the oSP0256.
Reading the VString property of an oSP0256 Object will always return ASCII character 0. |
|||||||||
| The Chr$ and Str functions are used to convert numbers to strings. The Str$ function returns a right justified, leading zeros retained value commensurate with the size of the expression (bit, word, byte) that is used as an argument. In the following example a string is set to "00123".
When a Chr$ function is encountered during the program's execution, it takes the {expression} element which is expressed as a decimal ASCII number and calculates and then returns the single string character represented by the decimal ASCII argument. In the following example a string is set to "A".
|
|||||||||
| In the Ver 5 compiler, the way to write a string to an object was to use a property called "String" as in; A.String = "Hello". In the Ver 6 compiler, the key word "String" has been reserved for future use and therefore each occurrence of properties with this name have been renamed to "VString". It should be noted that backwards compatibility has been maintained and that if the "String" property is encountered in code, it will internally convert to the "VString" property. This exception does not exists for creating a new property named "String" as it is now considered a keyword. |
|||||||||