+ All Categories
Home > Documents > Um String Code 2 0 e

Um String Code 2 0 e

Date post: 19-Nov-2015
Category:
Upload: hydrasearch
View: 77 times
Download: 16 times
Share this document with a friend
Description:
user manual fro mitoyo
46
Stringcoding Manual with Examples v2.0
Transcript
  • Stringcoding

    Manual with Examples v2.0

  • Contents

    2 v2.0 11.12.08

    1 Contents 1 Contents ............................................................................ 22 Definition and Options ..................................................... 43 Syntax ................................................................................ 6

    3.1 Keywords ..................................................................................... 63.1.1 Access Time Data ............................................................................... 63.1.2 Access Variables ................................................................................. 63.1.3 Functions of string coding ................................................................... 73.1.4 Access Part Programs Information ..................................................... 83.1.5 Access Sublot ..................................................................................... 93.1.6 Access Head Data .............................................................................. 93.1.7 Access Path Data ................................................................................ 9

    3.2 Formatting Options ..................................................................... 93.3 Example: Input of an Output File Name ................................... 113.4 Data Access to Numerical Variable as well as Time Access . 133.5 Example: Extended Text Analysis Functionality .................... 143.6 Example: Element Name Automatic Incrementing ................. 153.7 Example: Read in Nominal Values (Fixed Format) ................. 16

    3.7.1 Read in File ....................................................................................... 163.7.2 Read Out Values ............................................................................... 173.7.3 Filter Section ..................................................................................... 173.7.4 In the Formula Calculation ................................................................ 173.7.5 Section of the Part Program .............................................................. 18

    3.8 Example: Read in Nominal Values (Free Format, CSV) .......... 193.8.1 ASCII Files with several Lines ........................................................... 193.8.2 Read in File ....................................................................................... 193.8.3 Read Out Values ............................................................................... 203.8.4 Variable into Loop Instruction and Buffer .......................................... 203.8.5 Filter a Section .................................................................................. 213.8.6 Abridge First Part .............................................................................. 223.8.7 Variable as Position .......................................................................... 23

    3.9 Example: Dimensional Control via External ASCII File .......... 243.9.1 Repeat Mode not with all Elements ................................................... 243.9.2 Load Control File ............................................................................... 25

    3.10 Example: Format Descriptions or Formula Collections ......... 283.10.1 Read in Contents as Result .............................................................. 283.10.2 Set in Result Then Analysis ........................................................... 28

    4 History ............................................................................. 295 Examples of Numeric & String Variables ..................... 30

    5.1 Differentiation between Numeric & String Variables .............. 305.1.1 E.g. 1 ................................................................................................. 305.1.2 E.g. 2 ................................................................................................. 305.1.3 E.g. 3 ................................................................................................. 315.1.4 E.g. 4 ................................................................................................. 31

    5.2 External Input of Numeric & String Variables ......................... 325.2.1 E.g. 5 ................................................................................................. 325.2.2 E.g. 6 ................................................................................................. 33

  • Contents

    11.12.08 v2.0 3

    5.2.3 E.g. 7 ................................................................................................. 335.2.4 E.g. 8 ................................................................................................. 345.2.5 E.g. 9 ................................................................................................. 34

    5.3 When to use Parentheses and Brackets ................................. 365.4 Formatting of Numeric Variables ............................................. 37

    5.4.1 E.g. 10 ............................................................................................... 375.4.2 E.g. 11 ............................................................................................... 375.4.3 E.g. 12 ............................................................................................... 38

    5.5 Worked Example Program Using Numeric Variables ............. 385.6 Handling String Variables ......................................................... 40

    5.6.1 E.g. 13 ............................................................................................... 405.6.2 E.g. 14 ............................................................................................... 405.6.3 E.g. 15 ............................................................................................... 405.6.4 E.g. 16 ............................................................................................... 415.6.5 E.g. 17 ............................................................................................... 425.6.6 E.g. 18 ............................................................................................... 425.6.7 E.g. 19 ............................................................................................... 42

    5.7 Potential Uses ........................................................................... 46

  • Definition and Options

    4 v2.0 11.12.08

    2 Definition and Options In GEOPAK, you can insert different information of a part program in a text line.

    To do so, use the @-symbol followed by the special symbol. It is also possible to issue the value of a variable or the content of a

    text variable

    Furthermore, there are some formatting instructions, such as e.g. the

    determination of the total length the number of decimal digits after the comma, the left justification output or The output with leading zeros.

    You can use the text analysis for most of the text inputs, such as e.g.

    file identifications, element names, formula calculation, text output, proposals for input in UDL-Dialogs (since v2.1R1)

    The text analysis in a formula calculation is realized before the actual calculation. Example:

    In the formula calculation, you find ...

    Var1 = @StrLen(Text)+1

    First, the text analysis is executed Var1 = 4+1

    last, the calculation is performed Var1 = 5

  • Definition and Options

    11.12.08 v2.0 5

    Hint It can be helpful to open or to keep open one or several commentary-dialogues while learning string variables in command to have a look at the values of the string variables (see picture below).

    In addition since the v2.1.R1 stands in the command "Define Text Variable" a complete list "Stringcoding" at disposal.

  • Syntax

    6 v2.0 11.12.08

    3 Syntax 3.1 Keywords Keywords are not case sensitive (since v 1.5).

    Since v3.1 the string coding allows white space (blank characters) between function identifier, braces and function parameter e.g.:

    Old style New additional style

    @ElementName[PT,1] @ElementName [PT, 1]

    @ElementName [ PT , 1 ]

    etc.

    @StrGetNum("x;y;Z",";","1") @StrGetNum ("x;y;Z", ";", "1")

    @StrGetNum ( "x;y;Z" , ";" , "1" )

    etc.

    3.1.1 Access Time Data @Time:#:#:# Actual time in the defined system format

    @Date:#:#:# Actual date in the defined system short format

    @Hour:#:z Actual hour

    @Minute:#:z Actual minute

    @Second:#:z Actual seconds

    @MilliSecond:#:z Actual milliseconds

    @Year:#:z Actual year

    @Month:#:z Actual month

    @Week:#:z Actual week

    @DayOfYear:#:z Actual day of the year

    @DayOfWeek:#:z Actual day of the week

    @Day:#:z Actual day

    @TimeCode:#:#:# Creates act. time coded string with 6 characters

    @SecToTime(xxx) :#:#:# Convert sec. value xxx in the defined system format

    3.1.2 Access Variables @(VarName):#:#:z

    @(VarName:#:#:z) Value of a variable

    @[TxtVarName]:#:#:#

    @[TxtVarName:#:#:#] Result from text variable

    @Formula(x):#:#:z

    @Formula(x):#:#:z Calculation as the Formula-Calculation function in GEOPAK

  • Syntax

    11.12.08 v2.0 7

    @ResVarExist("VarNam") Controlled if a variable exist.

    Return 1 if the variable exist, otherwise 0.

    @StrVarExist("VarNam") Controlled if a string variable exist.

    Return 1 if the string variable exist, otherwise 0.

    3.1.3 Functions of string coding @StrLen(Text):#:z

    @StrLen(Text):#:z Get the length of the Text in the parenthesis

    @StrPos(Text,Such-Text):#:z

    @StrPos(Text,Such-Text):#:z

    Get the position of the Search Text in the Text or 0

    @StrLeft("Text","Pos") Returns left Side of a string (Text) up to a position (Pos) E.g.: Str1 = @StrLeft("Hello","3") = He

    @StrRight("Text","Pos") Returns right Side of a string (Text) up from a position (pos) E.g.: Str1 = @StrLeft("Hello","3") = lo

    @SubStr("xxx","no1","no2") Substitute and return a string from a position no1 to a position no2 from string xxx. e.g. @SubStr("Hallo","2","4") = all

    @StrChg("Text","from","to") Change the first found string (from) in a string (Text) to a new string (to) E.g.: Str1 = @StrChg("Hello","l","f") = Heflo

    @StrChgAll("Text","from","to") Change all found string (from) in a string (Text) to a new string (to) E.g.: Str1 = @StrChgAll("Hello","l","f") = Heffo

    @StrGetStr("Text","sep","num")

    Separate and returns a string from a CSV string (comma separated value).

    E.g.:

    Str1 = @StrGetStr("Thomas;Peter;Frank",";","1") = Thomas Str2 = @StrGetStr("Thomas;Peter;Frank",";","2") = Peter Str3 = @StrGetStr("Thomas;Peter;Frank",";","3") = Frank

    @StrGetNum("Text","sep","num")

    Separate and returns a number string from a CSV string.

    E.g.:

    Str1 = @StrGetNum("0.123;4.567;8.900",";","1") = 0.123

    Str1 = @StrGetNum("0.123;4.567;8.900",";","2") = 4.567

    Str1 = @StrGetNum("0.123;4.567;8.900",";","3") = 8.900

  • Syntax

    8 v2.0 11.12.08

    @FileExist("FileName")

    Test if a file, specified by FileName, exists or not. Returns 1 in case of existing and 0 in case of not existing.

    E.g.:

    Str1 = @FileExist("C.\Cosmos\Temp\Variable.Res")

    @StrCmp("xxx","yyy")

    Compares two strings (case sensitive). The return value for each of these functions indicates the lexicographic relation of xxx to yyy.

    Return < 0 => xxx less than yyy

    Return 0 => xxx identical to yyy

    Return > 0 => xxx greater than yyy

    @StrICmp("xxx","yyy")

    Compares two strings (not case sensitive). The return value for each of these functions indicates the lexicographic relation of xxx to yyy.

    Return < 0 => xxx less than yyy

    Return 0 => xxx identical to yyy

    Return > 0 => xxx greater than yyy

    3.1.4 Access Part Programs Information @Partname:#:#:# Name of actual part

    @PartProgname:#:#:# Name of actual part program

    @Revision:#:z The actual revision number

    @Operator:#:#:# Name of actual user (operator)

    @OperatorLevel:#:z The actual user (operator) right level

    @RC:#:z Repeat counter

    @LC:#:z Loop counter

    @NoOfLC:#:z The maximum number of executions of the actual loop

    @LoadedVars Number of variables or string variables loaded at last

    @ErrNoText[x]:#:#:# Gives back the error text which belongs to "x". "x" can be determined e.g. by the command "Sys.Err" from the formula calculation.

    @ElementName[type,x]:#:#:#

    Returns the name of an element. The requested type must be defined by type and the number by x. The type can be: Point "PT"; Line "LN", Circle "CR", Ellipse "EL", Plane "PL", Cone "CO", Sphere SP", Cylinder "CY", Angle "ANG", Distance "DI", Contour "CONT", Surface "SURF", Rectangle "RE", Square "SQ", Triangle "TR", Trapeze "TZ", Hexagon "HX", Slot "SL" and Drop "DR".

  • Syntax

    11.12.08 v2.0 9

    @OutText[x]:#:#:# Returns the text which is created by the Output text function. The number x represents the number of creation.

    3.1.5 Access Sublot @SubLot:#:#:# Sublot

    @SubLotF*:#:#:# Sublot field where * is the field no (e.g. SublotF5)

    3.1.6 Access Head Data @HeadDataF*:#:#:# Head data field where * is the field no.

    @HeadData[*]:#:#:# User defined head data, where * is the user defined head data field type

    3.1.7 Access Path Data @PartDrive:#:#:# Drive of part program, e.g. C:

    @PartDirectory:#:#:# Directory of part program, e.g. \DATA\CUSTOMER\

    @PartPath:#:#:# Path of part program and directory name of part program, e.g. C:\DATA\CUSTOMER\

    @PartSubDirectory Sub directory for the actual part, e.g. PV123456\

    @CosmosDrive:#:#:# Drive of the COSMOS programs, e.g. C:

    @CosmosDirectory:#:#:# Directory the COSMOS programs, e.g. \COSMOS\

    @CosmosPath:#:#:# Path of the COSMOS programs; e.g. C:\COSMOS\

    @CosmosTempPath:#:#:# COSMOS temporary file path

    @CosmosAudioPath:#:#:# COSMOS Audio-Path

    @CosmosPicturePath:#:#:# COSMOS Picture-Path

    @CosmosProbePath:#:#:# COSMOS Probe- Path

    @CosmosProbeArchivPath:#:#:# COSMOS Probe- Archive- Path

    @CosmosCoordPath:#:#:# COSMOS Co-ordinate-System- Path

    @CosmosCoordArchivPath:#:#:# COSMOS Co-ordinate-System - Archive- Path

    @CosmosLayoutPath:#:#:# COSMOS Layout- File- Path

    @CosmosTransferPath:#:#:# COSMOS File- Transfer- Path

    3.2 Formatting Options

  • Syntax

    10 v2.0 11.12.08

    :#:z :# min. total length (neg. for left bounded possible)

    :z leading zero are possible

    :#:#:z :# number of decimal places

    :#:# 1.# min. total length 2.# number of decimal places

    :z leading zero are possible:

    :#:#:# :# min. total length

    :# number of characters

    :# pos. of first character:

  • Syntax

    11.12.08 v2.0 11

    3.3 Example: Input of an Output File Name In the following you can see an example for the real application of a text variable.

    The user has the task to enter the name of an output file. This can be done when starting the part program.

    In the Input String Variable function, you define e.g. the FileName string variable.

    As a proposal, we take here the name of the part program. This can be achieved via the @PartProgName key word that

    returns the name of the part program.

    The function call could be as follows:

    After that, follows a display for input:

    To continue the run of the part program, the defined string variable FileName can be used in the File Format Specification function.

  • Syntax

    12 v2.0 11.12.08

    This way, the C:\COSMOS\TEMP\NEUES PROGRAMM.ASC file is opened and the task is finished.

    Then, the cut-out of the part program looks as follows:

  • Syntax

    11.12.08 v2.0 13

    3.4 Data Access to Numerical Variable as well as Time Access

    Instructions:

  • Syntax

    14 v2.0 11.12.08

    Result:

    3.5 Example: Extended Text Analysis Functionality Instructions: @[str1]#:#:# :# minimum total length

    :# number of signs

    :# position of the first sign

  • Syntax

    11.12.08 v2.0 15

    Result:

    3.6 Example: Element Name Automatic Incrementing Here, the name of circle elements should be continually generated in a self-acting way for example Kr001, Kr002, Kr003 etc..

    What do we have at our disposal?

    The formula calculation keyword CR.MaxNo returns the highest number of the element circle.

    The text keyword @FORMULA( ) realizes a calculation as in the formula calculation.

    The formatting instructions, such as :3:0:z when applied with @FORMULA( ) means: A minimum of three signs without digits after the comma and leading zeros.

    The element name input would be as follows:

    Kr@Formula(CR.MaxNo+1):3:0:z

    And when inserted:

  • Syntax

    16 v2.0 11.12.08

    3.7 Example: Read in Nominal Values (Fixed Format) In this example, suppose that we read in an ASCII-file with three lines containing per line three values for one measurement point, namely X, Y and Z. The three measurement points are supposed to be measured.

    The fixed format is as follows (also refer to help line below):

    01. to 10. sign contains the X-value

    11. to 20. sign contains the Y-value

    21. to 30. sign contains the Z-value

    The ASCII file that must be read in could be as follows:

    10.01 11.02 0.03

    20.01 12.02 0.03

    30.01 13.02 0.03

    123456789012345678901234567890

  • Syntax

    11.12.08 v2.0 17

    3.7.2 Read Out Values Now, the single values are read from within the string variables. Because several lines must be evaluated, the best would be to use a loop.

    Terms like @FORMULA(@LC-1):0 would have in the first loop flow a return 0, in the second 1 and in the third 2. Access to a name-incremental string variable should therefore look as follows: @[ReadData@FORMULA(@LC-1):0]

    Since the version v2.3.R1 you can use the command "@StrGetStr("Text","sep","num")".

    3.7.3 Filter Section Now, we know the contents of the read in string variable and we only must filter a specific section:

    @[ReadData0]:0:10:1 for the first value

    @[ReadData0]:0:10:11 for the second value

    @[ReadData0]:0:10:21 for the third value

    The resulting terms would be as follows:

    @[ReadData@FORMULA(@LC-1):0]:0:10:1

    @[ReadData@FORMULA(@LC-1):0]:0:10:11

    @[ReadData@FORMULA(@LC-1):0]:0:10:21

    3.7.4 In the Formula Calculation

  • Syntax

    18 v2.0 11.12.08

    Now, you can use these variables as usual for the position in a measurement as well as

    you can complete the loop (see dialogue below):

    3.7.5 Section of the Part Program

  • Syntax

    11.12.08 v2.0 19

    3.8 Example: Read in Nominal Values (Free Format, CSV)

    3.8.1 ASCII Files with several Lines In this example, an ASCII file with several lines must be read in containing three values per line for one measurement point, namely X, Y and Z. The three values are separated from one another by a separation sign.

    The format is as follows and has a semicolon as a separation sign:

    X-value; Y-value; Z-value

    The ASCII file that must be read in could be as follows: 10.01;11.02;0.03 20.1;12.2;0.3

    30.01;13.02;0.03

    40.1;14.2;0.3

    50.01;15.02;0.03

    3.8.2 Read in File First, the file with the Load String Variables function must be read in. The string variable name is specified with ReadData (also see chapter 1.3.6):

    The following string variables result: ReadData0=10.01;11.02;0.03

    ReadData1=20.01;12.02;0.03

    ReadData2=30.01;13.02;0.03

    ReadData3=40.01;14.02;0.03

    ReadData4=50.01;15.02;0.03

  • Syntax

    20 v2.0 11.12.08

    3.8.3 Read Out Values Now, the single values within the string variables are read. Because several lines must be evaluated, the best would be to use a loop.

    Because the number of the lines already read in has not been specified, this is determined through the @LOADEDVARS keyword:

    3.8.4 Variable into Loop Instruction and Buffer

    To get a clear overview, the line, which was read in is buffered. Terms like @FORMULA(@LC-1):0 would occasion the return 0 in the first loop flow, in the second 1 and in the third 2 etc.. Access to a name-incremental string variable should therefore look as follows: @[ReadData@FORMULA(@LC-1):0]

    Since the version v2.3.R1 you can use the command "@StrGetStr("Text","sep","num")".

  • Syntax

    11.12.08 v2.0 21

    3.8.5 Filter a Section Now, we have the total contents of the string variable, which was read in, and only another specified section must be filtered. To achieve this, we must locate the positions of the first separation sign:

    @STRPOS(@[Dummy],;)

    Now, the first value can be filtered. Direct inserting of the CutPos string variable would certainly provide one sign too much: @[Dummy:0:@[CutPos]] -> 10.01;

    So, one sign must be subtracted:

    @FORMULA(@[CutPos]-1) -> 5

    What results as: @[Dummy:0:@FORMULA(@[CutPos]-1):0] -> 10.01

  • Syntax

    22 v2.0 11.12.08

    3.8.6 Abridge First Part Now, we must abridge the first part of the string variable that was read in. The formatting part must cut the rest of the term beginning from the separation sign plus one: :0:@STRLEN(@[Dummy]):@FORMULA(@[CutPos]+1):0 -> :0:16:7

    And inserted: @[Dummy:0:@STRLEN(@[Dummy]):@FORMULA(@[CutPos]+1):0]

    Now, the same procedure is realized, as above, extract and cut once again:

    It is possible to directly assign the last value:

  • Syntax

    11.12.08 v2.0 23

    3.8.7 Variable as Position Now , these variables can be used, as usual, as a position in a measurement:

    Then, the cut-out of the part program looks as follows:

  • Syntax

    24 v2.0 11.12.08

    3.9 Example: Dimensional Control via External ASCII File

    3.9.1 Repeat Mode not with all Elements In a fully automatic operation, a part program must be repeated. However, not all elements in the part program must be measured. This must be decided via a central server. The server writes a single-line file for each repetition. In the file, identifiers such as A, B, C and D determine what must be measured.

    The ASCII file that must be read in could be as follows:

    ABCD or

    BCD or

    ACD or

    ABC etc.

    First, a part program is learned that can look like below:

  • Syntax

    11.12.08 v2.0 25

    3.9.2 Load Control File The rest is only done in the editor. Because the control file contains the single-line information, what is to be measured, it is loaded at the beginning of the part program with the command

    Load String Variables as well as the options

    Wait for File and

    Delete File.

    The result is e.g. the following string variable:

    Cx0=ABD

    In an IF branch, it is possible to access this string variable via the @STRPOS()-functionality. This means: If e.g. in the string variables, the character A exists, @STRPOS() will return a >0 value. @STRPOS(@[Cx0],A) -> e.g.: 1

  • Syntax

    26 v2.0 11.12.08

    @STRPOS(@[Cx0],B) -> e.g.: 2

    @STRPOS(@[Cx0],C) -> e.g.: 0

    @STRPOS(@[Cx0],D) -> e.g.: 3

  • Syntax

    11.12.08 v2.0 27

    Then, the cut-out of the part program looks as follows:

  • Syntax

    28 v2.0 11.12.08

    3.10 Example: Format Descriptions or Formula Collections

    3.10.1 Read in Contents as Result The Load String Variable function is suitable for format descriptions, formula collections or similar. This is due to the read in particularity. The read in contents are not directly analysed, but rather is taken as a result.

    If e.g. the following is read in: String=@(Value):8:3:z

    Here, String is the Variable and @(Value):8:3:z the content.

    Later, this variable is set in a function: Output Text Function: @[String]

    3.10.2 Set in Result Then Analysis First of all, and not visible for the user, the result is inserted. In this case: Output Text function: =@(Value):8:3:z

    Only then, analysis continues (e.g. value = 0.01): Output Text Function: =0000.010

    Knowing this, material collections, formula collections or format descriptions are assembled now.

    E.g. for correction data:

    XvalStr=@(CalcX):8:3:z YvalStr=@(CalcY):8:3:z

    ZvalStr=@(CalcZ):8:3:z

    EOutPut=E-@PartProgName:-20 X@[XvalStr] Y@[YvalStr] Z@[ZvalStr]

    Here, you must specify that the correction data are calculated in CalcX, CalcY and CalcZ in the part program.

  • History

    11.12.08 v2.0 29

    4 History Report What? Version V 2.0 - Add new features of the v3.1 GEOPAK v3.1.R1

    V 1.9 Chapter. 2 @ElementName[et,x], @OutText[x]

    GEOPAK v3.0.R1

    V 1.8 Chapter. 2 @StrCmp("xxx","yyy"), @StrICmp("xxx","yyy"), @SubStr("xxx","no1","no2")

    GEOPAK v2.4.R1

    V 1.8 Chapter. 2 @FileExist("FileName") GEOPAK v2.4.R1

    V 1.70 Chapter. 2 @StrLeft("Text","Pos"), @StrRight("Text","Pos"), @StrChg("Text","from","to"), @StrChgAll("Text","from","to"), @StrGetStr("Text","sep","num"), @StrGetNum("Text","sep","num")

    GEOPAK v2.3.R1

    V 1.60 Chapter. 2 @Week, @DayOfYear, @ErrNoText[No]

    GEOPAK v2.1.R1

    V 1.50 Chapter 3 Chapter changed

    V 1.50 Chapter 2 @PartSubDirectory, @LoadedVars

    GEOPAK v1.5.R1

    V 1.10 Chapter 2 @StrLen(x) , @StrPos(x,y), @Formula(x), @Formula(x), @SecToTime(x), @PartDrive, @PartDirectory, @PartPath, @CosmosDrive, @CosmosDirectory, @CosmosPath, @CosmosAudioPath, @CosmosPicturePath, @CosmosProbePath, @CosmosProbeArchivPath, @CosmosCoordPath, @CosmosCoordArchivPath, @CosmosLayoutPath, @CosmosTransferPath, @CosmosTempPath

    GEOPAK v1.5.B2

    V 1.04 Chapter 2 @StrLen(x), @StrPos(x,y) GEOPAK v1.5.A17

    V 1.03 Chapter 2 Extract out of a text variable GEOPAK v1.5.A16

    V 1.02 Chapter 2 @Hour, @Minute, @Second, @MilliSecond, @Year, @Month, @DayOfWeek, @Day

    GEOPAK v1.5.A13

    V 1.01 Chapter 2 @PartProgName, @Operator, @[String], @HeadDataF#, @HeadData[#]

    GEOPAK v1.5.A2

    V 1.00 Chapter 2 @Time, @Date, @TimeCode, @PartName, @RC, @LC, @SubLot, @SubLotF, @(Result)

    GEOPAK v1.5.A14

  • Examples of Numeric & String Variables

    30 v2.0 11.12.08

    5 Examples of Numeric & String Variables

    5.1 Differentiation between Numeric & String Variables

    Numeric Variables are handled by Parentheses ( ) String Variables are handled with Brackets [ ] If you want to include a variable in something you precede it by the

    commercial at @

    5.1.1 E.g. 1 Assume a numeric variable called Number containing the value of 0.12345

    Assume a string variable called Word containing Hello

    @(Number) displays 0.12345

    @[Word] displays Hello

    Numeric variables can only contain values String variables can contain any character, with the exception of a colon : or

    the equals sign = or the comma , because they are used for processing variables.

    A numeric variable can be changed to a string variable A string variable can be changed to a numeric variable, so long as it contains

    a value

    5.1.2 E.g. 2 Assume a numeric variable called Number containing the value of 1.000

    We want to change it to a string variable called Word

    Select the function and give the following information...

    Name of variable = Word

    Contents of variable = @(Number)

    The command @[Word] displays 1.000

    Similarly, to now transfer the contents of the string variable Word to a numeric variable Count

    Select the function and give the following information...

    Name of variable = Count

    Formula = @[Word]

    The command @(Count) now displays 1.000

    However, if we have a string variable called Word containing Hello and we attempt to change it to a numeric variable called Number, then the formula Number = @[Word] will produce an error, because Hello does not contain a numeric value and so, cannot be contained within a numeric variable.

  • Examples of Numeric & String Variables

    11.12.08 v2.0 31

    Why, therefore, is it useful to be able to convert numeric variables into string variables, or reverse the procedure and convert numeric variables into string variables?

    5.1.3 E.g. 3 Assume that we need to deal with a component serial number of the following format...

    000123456 Trying to handle this as a numeric variable would remove the leading zeros, so that the sequence:

    Name of variable = Number

    Formula = 000123456

    @(Number) now displays 123456

    5.1.4 E.g. 4 Assume we received a string variable, from an external source, containing the statement

    Run the loop 8 times Although it is possible to extract the character 8 from the entire statement (described later), as a variable called How Many this character was received as a string variable and so, could not be used to run the loop unless it were converted to a numeric variable first.

  • Examples of Numeric & String Variables

    32 v2.0 11.12.08

    5.2 External Input of Numeric & String Variables Variables can be obtained from external sources by reading them into Geo-

    Win from a file. The mechanism employed for reading in string variables is basically identical

    to that for reading in numeric variables. Care should be taken to ensure that the format of the file contents is well

    defined, prior to using this form of input. Care should be taken to ensure that the variables are read in as the correct

    type (string or numeric). All of the files contents are taken in during the read operation, partial input is

    not possible. A file can only be read in as all string or all numeric, the types of input

    cannot be mixed within one file. The variables names may be assigned within the file, determined

    automatically by Geo-Win, or sequentially assigned during the read in operation.

    Geo-Win assumes the following extensions for variable files, but will accept any filename and extension

    Numeric Variables RES String Variables STR

    5.2.1 E.g. 5 Assume a file of the following path and filename C:\Data\MyData.ASC Assume the contents of the file are as follows 1111 02222 3333 4444 ABCD The sequence will prompt for the file to be used for input. Simple entry of C:\Data\MyData.ASC as the path and filename will automatically read in the file contents as numeric variables of the following names RES0 = 1111.000 RES1 = 2222.000 RES2 = 3333.000 RES3 = 4444.000 The operation will conclude with a variable not defined error. Notice the following points;

    1. The name RES has been automatically assigned 2. The name RES has been automatically appended with a sequential

    number 3. The sequential numbering always starts from zero 4. The leading zero has been dropped from RES1 to make a valid number 5. All values are displayed to the set number of decimal places 6. The variable not defined error occurred due to the fifth piece of data in

    the file ABCD, which was not numeric and therefore failed to be assigned to RES4

  • Examples of Numeric & String Variables

    11.12.08 v2.0 33

    5.2.2 E.g. 6 Assume the same path and filename C:\Data\MyData.ASC Assume the same file contents 1111 02222 3333 4444 ABCD The sequence will again prompt for the file to be used for input. Simple entry of C:\Data\MyData.ASC as the path and filename will automatically read in the file contents as String variables of the following names STR0 = 1111 STR1 = 02222 STR2 = 3333 STR3 = 4444 STR4 = ABCD Notice the following points;

    1. The same data file was used for both types of input, but achieved different results

    2. No error was reported at conclusion of the operation 3. The name STR has been automatically assigned 4. The name STR has been automatically appended with a sequential

    number 5. The sequential numbering always starts from zero 6. All data has been taken in, exactly as contained in the file 7. Decimal places have not been appended, because the data is not

    numeric

    5.2.3 E.g. 7 Assume the same path and filename C:\Data\MyData.ASC Assume the same file contents 1111 02222 3333 4444 ABCD The sequence will prompt for the file to be used for input. Entry of C:\Data\MyData.ASC as the path and filename followed by selection of , with an entry of Figure will automatically read in the file contents as numeric variables of the following names Figure0 = 1111.000 Figure1 = 2222.000 Figure2 = 3333.000 Figure3 = 4444.000 The operation will again conclude with a variable not defined error due to the fifth piece of data not being numeric. Repetition of the preceding sequence, with substitution of Figure7 for Figure will modify the resultant data as follows

  • Examples of Numeric & String Variables

    34 v2.0 11.12.08

    Figure70 = 1111.000 Figure71 = 2222.000 Figure72 = 3333.000 Figure73 = 4444.000 Notice the following points;

    1. The default name assigned to variables can be overridden by assigning a name within the Load Filter

    2. The sequential numbering still always starts from zero 3. Appending a number to the Load Filter name allows definition of the

    point from which sequential numbering starts 4. The same mechanism of assigning a Load Filter name is also applicable

    to string variables

    5.2.4 E.g. 8 Assume the same path and filename C:\Data\MyData.ASC Assume the file contents are Feature1 = 1111 Feature2 = 02222 TestOut Size = 3333 Weight = 4444 Name = ABCD EFGH The sequence will again prompt for the file to be used for input. Simple entry of C:\Data\MyData.ASC as the path and filename will automatically read in the file contents as String variables of the following names Feature1 = 1111 Feature2 = 02222 STR2 = TestOut Size = 3333 Weight = 4444 Name = ABCD STR6 = EFGH Notice the following points;

    1. The variables name may be assigned within the file, using the = symbol 2. Numbering may also be attached to the name 3. Variable names may be mixed within one file 4. Although not recommended, it is possible to have some of the variables

    named within a file and others not. In this case, those named have the name assigned within the file, those not named within the file are assigned the default name (STR for strings or RES for numerics) with a count appended equal to its position within the file (starting from position zero)

    5. The same mechanism, of applying the variables name within the file, is also applicable to numeric variables

    5.2.5 E.g. 9 Assume the same path and filename C:\Data\MyData.ASC Assume the file contents are in serial format as follows a) Feature1 = 1111; Feature2 = 02222; Size = 3333; Weight = 4444; Name =

    ABCD or

  • Examples of Numeric & String Variables

    11.12.08 v2.0 35

    b) 1111;02222;3333;4444;ABCD Attempting to read in the files contents as numeric data will result in a Syntax Error being reported. However, the contents may be read in as string variable data. In this case, the resultant variables would be

    a) Feature1 = 1111; Feature2 = 02222; Size = 3333; Weight = 4444; Name = ABCD

    a string variable called Feature1 containing the data 1111;Feature2=02222;Size=3333;Weight= 4444;Name=ABCD or

    b) STR0 = 1111;02222;3333;4444;ABCD a string variable called STR0, by default, containing the data 1111;02222;3333;4444;ABCD

  • Examples of Numeric & String Variables

    36 v2.0 11.12.08

    5.3 When to use Parentheses and Brackets In simple terms, Geo-Win requires the use of parentheses ( ) and brackets [ ],

    when a variable is being used within a function, to let Geo-Win know whether it is being asked to deal with a numeric ( ) or a string [ ] variable. Broadly speaking, Geo-Win tends to assume numeric variables, unless told otherwise and therefore, if usage of a numeric variable is already clear to Geo-Win, parentheses ( ) may not be required whereas brackets [ ] denoting a string variable invariably are required.

    The user may correctly deduce from the preceding statement that, although not recommended as good programming practice, it is entirely possible to have a numeric variable and a string variable assigned the same name. In this event, it is simply the correct use of parentheses ( ) and brackets [ ] that allows Geo-Win to correctly determine which is being used at any one time.

    As a broad rule-of-thumb the majority of system variables and user-defined numeric variables are generally accessible without the use of parentheses ( ) and brackets [ ], whereas the use of string variables, conversion of one variable type to another, or formatting of variables (discussed later) tends to predetermine that parentheses ( ) and brackets [ ] will be required.

    The use of numeric variables within a numeric function (position, size, calculation etc.) invariably determines that parentheses ( ) will not be required, unless to determine execution order of a formula, whereas the use of numeric or string variable within a non-numeric function (text output etc.) will require the correct application of parentheses ( ) or brackets [ ].

    Almost without exception, the usage of either numeric or string variables within most functions requires that the variable name, and the parentheses ( ) or brackets [ ] if applicable, must be preceded by the commercial at symbol @, to let Geo-Win know that what follows is the name of a variable and not just a simple text entry.

  • Examples of Numeric & String Variables

    11.12.08 v2.0 37

    5.4 Formatting of Numeric Variables By default, a numeric variable will be presented, transferred or output using

    the prevailing numerical format that is currently set within Geo-Win, i.e. No leading zeroes, number of decimal places set, etc.

    The output of the presentation format may be modified, for that variable at that point in time, via the use of formatting options

    These options consist of one or two numerical values and a possible control character that succeed the name of the numeric variable

    5.4.1 E.g. 10 Assume a numeric variable, called Number containing the value of 0.12345 and the system is set for resolution to three decimal places. Giving the commands - and entering the X value as Number will show that it has moved the machine 0.123. Similarly, giving the command and entering the text as I moved @(Number) Displays I moved 0.123 on the screen. Formatting the numeric variable by succeeding the name, in parentheses ( ), with a colon : and a value # overrides the number of decimal places the variable is displayed at as per the following table Text to Screen Input Displayed Text I moved @(Number):0 no decimal places I moved 0 I moved @(Number):1 1 decimal place I moved 0.1 I moved @(Number):3 3 decimal places I moved 0.123 I moved @(Number):5 5 decimal places I moved 0.12345 I moved @(Number):11 11 decimal places I moved 0.12345000000 The formatting option is not accepted within a numeric field input (e.g. Move

    Machine) as the number of decimal places is governed by system resolution. Placing the value # inside the parentheses ( ) will give the same effect, i.e.

    I moved @( Number:11) 11 decimal places I moved 0.12345000000 Placing a second colon : and value # within the parentheses ( ) allows the text

    output to be formatted with leading spaces prior to the display of the value and number of decimal places

    5.4.2 E.g. 11 Text to Screen Input Displayed Text I moved @(Number:7:5) I moved 0.12345 use 7 spaces to 5 decimal places I moved @(Number:8:5) I moved 0.12345 use 8 spaces to 5 decimal places I moved @(Number:20:5) I moved 0.12345 use 20 spaces to 5 decimal places

  • Examples of Numeric & String Variables

    38 v2.0 11.12.08

    Adding a further formatting option, colon : and character z to our output requests that any leading spaces are used to display leading zeroes, as follows

    5.4.3 E.g. 12 Text to Screen Input Displayed Text I moved @(Number:9:6:z) I moved 00.123450 9 spaces 6 decimal places use leading zeroes I moved @(Number:8:5:z) I moved 00.12345 8 spaces 5 decimal places use leading zeroes I moved @(Number:11:5:z) I moved 00000.12345 11 spaces 5 decimal places & leading zeroes Notice the following points;

    1. A colon and one value :# denotes number of decimal places 2. In the case of 2 values, separated by colons :#:#, the first value denotes

    how many character spaces to use for the total length of the displayed figure, the second value then becomes how many decimal places to display the figure to

    3. Appending a colon and the character z to the end, :#:#:z, informs the system to use up any remaining character spaces with leading zeroes

    4. In the first instance of example 12 (above) the variable was closed up to the text. In the second instance, one character space was used between the text and the specification of the variable. This ensured that any leading zeroes did not close up to the end of the text, for a more readable output

    5. For a numeric variable the statements @(Number:11:5:z) and @(Number):11:5:z formatting within or without the parentheses, are treated identically

    6. The above techniques of formatting numeric variables can be usefully employed if text or file output of numeric data needs to be carefully controlled for either transmission to an external system, that requires a constant number of characters, or to pre-define exact character spacing for the generation of result output, layout files, spread-sheet formats etc.

    5.5 Worked Example Program Using Numeric Variables

    Following is an example Generic Hole program using only numeric variables. The program has no in-built coding that pre-determines how many holes are to be measured, their size or position, it is all determined from the contents of a data file that is provided for the holes to be measured. This file could be one of a set, residing on the system, or externally provided from a network or serial connection on an automated system. Each hole is automatically named within the program and, as such, is provided as a set of embedded examples of numeric variable usage that the reader may employ individually. The program lines have been numbered, within the following listing, to hopefully assist in clarification of the provided explanations. For further reference of available system variables, reference should be made to existing documentation within Geo-Win help (Programming Tools) and the User Manual for Geopak-Win String Coding (English) Strcod_e.pdf dated 14.03.2001.

    Listing (with explanations) of Generic Hole Program

  • Examples of Numeric & String Variables

    11.12.08 v2.0 39

    File Contents: An example file called C:\COSMOS\TEMP\MEASURE.RES contains data in the format of X position hole 1 Y position hole 1

    Z position hole 1 Diameter hole 1

    X position hole 2 etc. The contents could be 16 sets of data, for 4 holes, as follows . -10.000

    -10.000 -1.000 14.000 -10.000 10.000 -2.000 20.000 10.000 10.000 -3.000 25.400 10.000 -10.000 -4.000 34.925

    Part - Program: 1. Change Probe 1

    Load or use any suitable probe. 2. Load Coordinate System n

    Where n equals any suitable coordinate system, possibly location fixturing. 3. Load Variables from file C:\COSMOS\TEMP\MEASURE.RES

    The path and filename are totally user defined however, it is good practice to use the dot RES extension for numeric variable files. A Load Filter was set to Feature so that the contents are automatically named as Feature0, Feature1 Feature8 etc. as they are read into Geo-Win.

    4. CNC on/off ON CNC machine operation is used/simulated, but also applicable to manual.

    5. Clearance Height Clearance height ON Z axis = 10.000

    An example arbitrary clearance height has been set, to eliminate intermediate points and reduce program size. 6. Formula Calculation Count = @LoadedVars/4

    The @LoadedVars is a system variable that automatically keeps count of how many variables have been read in from the file. Knowing that there are 4 entries in the file for each hole, dividing this figure by 4 means that the variable Count can be used to determine how many holes have to be measured.

    7. Loop Start No. of executions = Count Start the loop, to run the same number of times as there are holes.

    8. Formula Calculation PosX = @(Feature@Formula(@LC*4-4):0) The variable PosX is calculated as follows; @LC is the system variable of how many times the loop has run. Multiply this by 4 gives which group of 4 variables belong to the current hole, however, we have to allow that the loop starts from 1, whereas the variables are numbered from zero, hence saying LC*4-4 is the same as saying LC*0 (you cant actually multiply something by zero). Preceding this by the @Formula statement is a way of building a calculation within the statement. It effectively says work this bit out first. So @Formula(@LC*4-4) gives the result 0.000 We want to add this as a numeric part of a name but decimal places are not allowed in names (or decimal points) so, appending the statement :0 says No decimal places. This turns the result into 0. Feature was the load filter applied when we read the data in from the file so, appending our previous result (0) onto the end of @Feature gives us the statement @Feature0. Therefore, our Formula Calculation equates to PosX = Feature0 The name of the first variable read in from the file.

    9. Formula Calculation PosY = @(Feature@Formula(@LC*4-3):0) Variable PosY was the second piece of data in each group of 4 variable sets. Therefore, the only difference is the statement @LC*4-3 (one less) which therefore gives us the answer 1.000 The remainder of the statement is as explained above, so that our formula is PosY = Feature1 The second variable.

    10. Formula Calculation PosZ = @(Feature@Formula(@LC*4-2):0) If you have followed the above, you will see that in the first run of the loop the statement gives . PosZ = Feature2 The third variable. When the loop runs the second time LC = 2, so @LC*4-2 comes out as 2 times 4 equals 8, minus 2 equals 6 so the statement gives PosZ = Feature6 the seventh variable and Z position for the second hole.

    11. Formula Calculation Diam = @(Feature@Formula(@LC*4-1):0) Same technique as above, but for the diameters. First loop run gives Feature3, second gives Feature7, fourth gives Feature15 to extract the diameters.

    12. Drive to Clearance Height This line saves intermediate points between holes, for a smaller program.

    13. Circle Hole@Formula(CR.MaxNo+1):3:0:z (1) Mean CR.MaxNo is always the number of the last circle measured. +1 adds 1 to it each time. @Formula says Work this bit out first, but it ends up with decimal places. :3 says Use three character spaces. :0 says No decimal places. :z says Put in leading zeroes Append all this to the name Hole and we end up with Hole001, Hole002, . Hole043 etc. Note: This has no input from the file, it is calculated real time so could be used to auto-name any feature.

    14. Autom. Element measurement No.of Pts. = 8 Projection / meas. Plane = XY plane Circle X = PosX, Y = PosY, Z = PosZ, Diameter = Diam The normal automatic measurement line of a program, it just has the variables inserted that were derived from the data file.

    15. Element Finished End of the measurement.

    16. Loop End End of the loop.

    17. Move Machine CMM in home position It is always good practice to park the CMM safely when finished.

    18. CNC on/off OFF It is recommended, by CTL-G, to remember to switch OFF CNC at the end of every part program.

  • Examples of Numeric & String Variables

    40 v2.0 11.12.08

    5.6 Handling String Variables We are already aware that we can read in, or display string variables, in a similar manner to numeric variables. It is also possible to concatenate string variables (concatenation simply means join together).

    5.6.1 E.g. 13 Assume a string variable called Str0 Assume the contents of Str0 to be World Hello@[Str0] shows Hello World (no space between words) Hello @[Str0] shows Hello World (correctly spaced)

    5.6.2 E.g. 14 Assume a string variable called Str0 containing Fred Assume a string variable called Str1 containing rick Assume a string variable called Str2 containing son @[Str0]@[Str1]@[Str2] shows Fredrickson (concatenated) Similarly, the statement Str4 = @[Str0]@[Str1]@[Str2] sets Str4 to permanently equal Fredrickson Concatenating strings within a text output format joins the strings together

    temporarily Concatenating strings as the definition of another string variable creates a

    new, longer string Spaces, left in between the concatenated strings, will be automatically

    included within the new string The keyword @StrLen returns a numeric variable that allows the user to find

    the length of a string variable

    5.6.3 E.g. 15 Assume a string variable called Str4 containing Fredrickson Name of numeric variable = Length Formula = @StrLen(@[Str4]) Puts the result 11 into the numeric variable Length, which is the number of characters in the name Fredrickson Notice the following points;

    1. The variable Str4 is within square brackets [ ] denoting a string. 2. It is preceded by the @ symbol and encased within parentheses ( )

    because it must return a numeric variable. 3. The parentheses are preceded by @StrLen to state how the value is

    derived. It is also possible to find the position of one, or more sequential characters within a string variable, by using the @StrPos keyword. In its simplest form, the statement @StrPos(ABCDE,C) will return the value 3

    (the first position of C within the string). The statement @StrPos(ABCDEC,C) will still return the value of 3, the first

    position of C found, any subsequent occurrences are ignored.

  • Examples of Numeric & String Variables

    11.12.08 v2.0 41

    The statement @StrPos(ABCDE,F) will return the value 0 (the character F does not occur within the string).

    It is often useful to search for a sequence of more than one character, where possible, to help eliminate possible errors from the critical character occurring more than once. Ie. @StrPos(Succeed,c) will return the value 3, the first c @StrPos(Succeed,ceed) will return the value 4, where ceed starts Whereas @StrPos(Succeed,cead) will return the value 0, because cead does not exist Also @StrPos(Succeed,C) will return the value 0, because strings are Case Sensitive

    Obviously, the string to be searched and the character, or characters, to be searched for could be replaced within the parentheses by declared string variables instead. For an example of this, lets rework the above examples

    5.6.4 E.g. 16 Str0 = Succeed Str1 = ceed Str2 = cead Str3 = C Str4 = c

    The position of @[Str1] within @[Str0] is @StrPos(@[Str0],@[Str1]) Displayed result is The position of ceed within Succeed is 4

    The position of @[Str2] within @[Str0] is @StrPos(@[Str0],@[Str2]) Displayed result is The position of cead within Succeed is 0

    The position of @[Str3] within @[Str0] is @StrPos(@[Str0],@[Str3]) Displayed result is The position of C within Succeed is 0

    The position of @[Str4] within @[Str0] is @StrPos(@[Str0],@[Str4]) Displayed result is The position of c within Succeed is 3

    The ability to use @StrPos to find the position of a character, or series of characters within a string means that the user can test for legality and spelling mistakes within messages, automatically assemble messages internally, test for completion of external messages and generate 2-way communication and control with external devices. Taking this concept a stage further, we can use a similar form of formatting on string variables.

  • Examples of Numeric & String Variables

    42 v2.0 11.12.08

    5.6.5 E.g. 17 Str0 = Succeed The portion is@[Str0:3:2:3] Displayed result is The portion is cc

    This has simply told Geo-Win to display the word Succeed (@[Str0]) using 3 character places (@[Str0:3]) and display just 2 of its characters (@[Str0:3:2]) starting from character number 3 (@[Str0:3:2:3]) so it has displayed the characters cc appended straight onto the end of The portion is but effectively leaving one space, because it was told to use 3 character spaces. If the statement had been @[Str0:2:2:3] it would have displayed The portion iscc, closed up without spaces, alternatively if the statement read @[Str0:8:2:3] the corresponding display would have used 8 character spaces for the string portion displayed thus The portion is cc leaving 5 blank spaces in between. Going back to the original statement @[Str0:3:2:3], if it is modified at the second formatting value thus @[Str0:3:1:3] the resultant display would append only the character c, whereas changing the statement to @[Str0:3:4:3] would append the characters ccee. Finally, from the original statement @[Str0:3:2:3], if the last formatting value is modified so the statement reads @[Str0:3:2:1] it would append the characters Su, whereas altering the statement to @[Str0:3:2:6] would append the characters ed. Explanation has already been given of string concatenation and now string formatting. The formatting functions are, as with numeric variables, useful for generating output in given text or file formats. The basic understandings of formatting options are however much more useful if applied to extracting sub-strings from a parent string variable.

    5.6.6 E.g. 18 Let Str0 = Fredrickson Then the statement Str1 = @[Str0:0:1:4] gives d Similarly Str2 = @[Str0:0:3:6] gives ick Therefore, using the above sub-string extraction technique along with concatenation The statement Str3 = @[Str0:0:1:4]@[Str0:0:3:6] gives dick

    Whilst the above may be considered agreeable options, merely of interest for output, it should be realised that they provide the user with a very powerful set of tools that expand on the capability of just using numeric variables manifold.

    5.6.7 E.g. 19 Lets reconsider the serial file format of example 9. The contents of the file were as follows;

    1111;02222;3333;4444;ABCD

  • Examples of Numeric & String Variables

    11.12.08 v2.0 43

    Attempting to read in as a numeric variable would fail. Reading in as a string variable returns the result Str0 = 1111;02222;3333;4444;ABCD Now consider the following process . Pointer = @StrPos(@[Str0],;) (Equals 5, the position of the first colon ;) Res0 = @[Str0:0:@Formula(@[Pointer]-1):0] (extracts the first value 1111) Str0 = @[Str0:0:@StrLen(@[Str0]):@Formula(@[Pointer]+1):0]

    This has reduced string to Str0 = 02222;3333;4444;ABCD so we can repeat the process to extract the next value, as follows;

    Pointer = @StrPos(@[Str0],;) (Equals 6, the position of the next colon ;) Res1 = @[Str0:0:@Formula(@[Pointer]-1):0] (Extracts the next value 02222 and drops leading zero to give 2222)

    Str0 = @[Str0:0:@StrLen(@[Str0]):@Formula(@[Pointer]+1):0] This has reduced string to Str0 = 3333;4444;ABCD so we repeat the process to extract the next value;

    Pointer = @StrPos(@[Str0],;) (Equals 5, the position of the next colon ;) Res2 = @[Str0:0:@Formula(@[Pointer]-1):0] (extracts the next value 3333) Str0 = @[Str0:0:@StrLen(@[Str0]):@Formula(@[Pointer]+1):0] This has reduced string to Str0 = 4444;ABCD so we repeat the process to extract the next value;

    Pointer = @StrPos(@[Str0],;) (Again equals 5, the position of the last colon ;) Res3 = @[Str0:0:@Formula(@[Pointer]-1):0] (extracts the next value 4444) Str0 = @[Str0:0:@StrLen(@[Str0]):@Formula(@[Pointer]+1):0] This has reduced string to Str0 = ABCD which can now be directly assigned as follows; Name = @[Str0]

    Lets explain the statements:

    Str0 starts off containing 1111;02222;3333;4444;ABCD It is not known how many characters are in each embedded portion, but it

    is known that they are separated by a colon ;

  • Examples of Numeric & String Variables

    44 v2.0 11.12.08

    A string variable Pointer is used to locate the position of the first colon in the string. A string, rather than a numeric variable, is used because we need to embed the result within a formatting statement and such statements are not numeric, so would cause a failure.

    Pointer = @StrPos(@[Str0],;) simply says Find the position of the colon within Str0 and assign that value, as a string, to Pointer.

    Res0 = @[Str0:0 says Assign a portion of string Str0 to numeric Res0, as a numeric variable with no decimal places.

    We next need to know how many characters it consists of. We have the position of the colon in the string variable Pointer so the

    number of characters must be one less than this value. (@[Pointer]) converts the string to a numeric so that we can subtract one

    from it, with the statement (@[Pointer]-1). This statement however is a numeric calculation that must take place

    within a string, so we precede it with the keyword @Formula to allow this to happen, making the statement Res0 = @[Str0:0:@Formula(@[Pointer]-1).

    Knowing how many characters to collect is fine but, we need to know where to start to collect them from.

    As its from the start of the string, appending the statement :0 says Start from position zero and the closing ] is needed because it is a string we are evaluating.

    So, the whole statement is Res0 = @[Str0:0:@Formula(@[Pointer]-1):0].

    Substituting the values for the first portion we are extracting would show the statement as Res0 = @[1111;02222;3333;4444;ABCD:0:4:0] = 1111. The statement, in this exact format, would not work. It is presented in this manner to aid clarification of meaning only.

    The preceding operation has not removed 1111 from Str0, it has simply made a copy of that portion. As searching the string only comes up with the first occurrence of what is being searched for, we need to remove the first portion of the original string up to, and including the first colon, so that it will successfully find the next.

    The statement Str0 = @[Str0] would say Modify Str0 to contain what is in Str0, a pointless statement in itself, because it changes nothing. However, if we were to say Modify Str0 to contain what is in Str0 less some portion of it the effect would be to reduce its contents. This is what we want to do but, which portion and how to do it?

    Remember, strings are not numeric so you can not add them, or take them away from each other, you can only concatenate (join them), or extract sub-strings (cut them). We need to extract a sub-string that is equal to what is left after the first colon. We already know the position of the colon (Pointer), so lets see how we do it.

    The statement Str0 = @[Str0:0:@StrLen(@[Str0]):@Formula(@[Pointer]+1):0] does just that job.

    Str0 = @[Str0:0 says some portion of Str0 with a minimum of zero spaces (use what space is needed).

    How many characters? The full length of Str0 (:@StrLen(@[Str0])). Starting from which character? One after the colon (@[Pointer]+1), but

    this needs to be calculated within the formatting statement, so precede it with @Formula and put it in parentheses to make it numeric (:@Formula(@[Pointer]+1)).

  • Examples of Numeric & String Variables

    11.12.08 v2.0 45

    Why the last :0 ? Because :@Formula(@[Pointer]+1) has worked out a numeric variable to the default number of decimal places and, before we convert it to a string, we need to tell it No decimal places, hence the last :0.

    Finally, we need to include the closing bracket ] because the whole is a string statement we are evaluating.

    Note the following points;

    1. We used numeric and string variables to automatically locate the separator, between individual bits of data within a string variable, and used this information to extract the required sub-string.

    2. We have converted strings to numerics and numerics to strings, including evaluating calculations within a string first.

    3. The statements, for determining each of the variables used, were identical at each usage so could be included once, within a loop.

    4. We can now see how to take in data, from a file, in serial format. This data, although originally accessed as one string for each line, can have the relevant string and numeric components extracted.

  • Examples of Numeric & String Variables

    46 v2.0 11.12.08

    5.7 Potential Uses Following are some obvious, and some less obvious, application uses. It is up to the individual, with reference to the guidance documentation mentioned earlier, to put it to practical use. a) A program could be generated, consisting of a subroutine for each element or

    operation. A string could be sent, at the start of the program, which could be evaluated and tested for which feature (part derivative to measure). I.e. String 1 says measure A B C F G String 2 says measure C G H

    b) The earlier example generic hole program which used only numeric variables, could be modified to take the data in serial format. Now, each line could contain the data for the complete hole (including name, tolerances etc.). One line per feature would eliminate the need to calculate the number of features for the loop, it would correspond to the number of lines within the file.

    c) Control and communication with external devices is easily realised, with message test capabilities embedded within the part program.

    d) It should now be possible, with some time and effort invested, to produce a generic virtual part program. Create sub-routines for each CMM operation or command Create a data file that includes, on each single line, not only the relevant

    data but the type of CMM command to be used (IP, CR, TO, CP, IH etc.) Create a virtual part program that reads each line of the file, as a string Extract the type of command from the start of the string Extract the relevant components for that command, call the sub-routine

    and apply them (you may never have to program again!) Note: Although it must be stressed that the author has had no opportunity to

    attempt the following suggestion, it is quite probable that the format of simple CAD files could be successfully directly processed, within a Geo-Win part program, by absorbing and processing as string variables.


Recommended