ooPIC Logo

ooPIC Programmer's Guide

 Chapter 13 - Strings

Main Index
Prg Index
Previous
Next
Back to top of pageWhat are Strings?
 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.
Back to top of pageUsing Strings
 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.

Back to top of pageUsing Strings with the oSerialH, oSerialPort and oLCD Objects
 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.

Visual Basic & BASIC syntax C & Java Syntax
Dim A As New oSerial

Sub Main()
  A.Baud = cv9600
  A.Operate = cvTrue
  A.VString = "Hello World"
End Sub
oSerial A = New oSerial;

Void Main(Void){
  A.Baud = cv9600;
  A.Operate = cvTrue;
  A.VString = "Hello World";
}
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.
Back to top of pageUsing Strings with the oDataStrobe Object
 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.

Visual Basic & BASIC syntax C & Java Syntax
Dim Prt As New oDataStrobe
Dim LD As New oDIO8
Dim DS As New oDIO1

Sub Main()
  LD.IOGroup = 3
  LD.Direction = cvOutput
  DS.IOLine = 7
  DS.Direction = cvOutput
  Prt.Output.Link(LD)
  Prt.Strobe.Link(DS)
  Prt.Operate = cvTrue
  Prt.VString = "Hello World"
End Sub
oDataStrobe Prt = New oDataStrobe;
oDIO8 LD = New oDIO8;
oDIO1 DS = New oDIO1;

Void Main(Void){
  LD.IOGroup = 3;
  LD.Direction = cvOutput;
  DS.IOLine = 7;
  DS.Direction = cvOutput;
  Prt.Output.Link(LD);
  Prt.Strobe.Link(DS);
  Prt.Operate = cvTrue;
  Prt.VString = "Hello World";
}
Reading the VString property of an oDataStrobe Object will always return ASCII character 0.
Back to top of pageUsing Strings with the oBuffer Object
 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.

Visual Basic & BASIC syntax C & Java Syntax
Dim A As New oBuffer12

Sub Main()
  A.VString = "Hello World"
End Sub
oBuffer12 A = New oBuffer12;

Void Main(Void){
  A.VString = "Hello World";
} 

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"

Back to top of pageUsing Strings with the oSP0256 Object
 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.

Visual Basic & BASIC syntax C & Java Syntax
Dim A As New oSP0256

Sub Main()
  A.VString = "ABC"
End Sub
oSP0256 A = New oSP0256;

Void Main(Void){
  A.VString = "ABC";
}

Reading the VString property of an oSP0256 Object will always return ASCII character 0.

Back to top of pageChr$ and Str Function
 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".

Visual Basic & BASIC syntax C & Java Syntax
A.VString = Str$(123)
A.VString = Str$(123);

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".

Visual Basic & BASIC syntax C & Java Syntax
 A.VString = Chr$(65)
 A.VString = Chr$(65);
Back to top of pageHistory
 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.