select chapter

laiye rpa developer guide d1-和记娱乐怡情博娱

throughout this guide, we assume that you have some basic knowledge of computer programming, including data types, variables, and conditionals. if you have no prior experience, this chapter serves as a crash course to programming basics. laiye rpa demands very little programming knowledge, and all the necessary concepts should be easy to understand. so don’t worry! take your time with this chapter, and you will be all set.

if you already have prior experiences in programming, feel free to skip this appendix. let us take a look at this excel table. the content in this table is completely arbitrary, but we will use it to explain some important concepts.


figure 82: example excel table

the main job of rpa is usually to process various types of data. what exactly is data? imagine that you have an excel table, and its cells are already filled with various entries. these entries are all data. data is the information exchanged between computers and humans.

data can be classified into structured and unstructured data. the data nicely lined up in the gridded system of this excel table is clearly structured, and most of the data we will have to deal with is all structured. therefore, we will simply use this table to explain our concepts. on the other hand, images, audios, videos, and webpages are mostly unstructured data, so we will not go into details here.

generally speaking, in programming languages, data can be of many different types. common data types in laiye rpa include numeric types, string types, boolean types, null type, and compound types. we will leave the compound types for the intermediate level guide.

a numeric type is just a number. it could be an integer or a number with a decimal point (known as a floating-point number, or simply a float). in the example excel table, this could be the numbers under the amount column or the sales column.

a string type is usually a string of characters enclosed with a pair of double quotes ("example") or a pair of single quotes ('example') to indicate that this is a string. special characters in a string are indicated using backslashes. for example \t represents a tab character, \n represents a new line, \' represents a single quote, \" represents a double quote, and \\ represents a backslash. you can also use three single quotes ('''example''') to enclose a long string. in a long string, you can directly enter new lines, write single quotation marks, and write double quotation marks, instead of using the backslash substitutes \n, \', or \".

a boolean type can have one of two values: true or false. this often corresponds colloquially to yes and no, and the meaning is the same.

a null type always has the value null (case-insensitive), representing an empty value.

how do we distinguish between the various data types? in general, we can add, subtract, multiply, and divide numeric values. boolean values only support logical operations like and, or, and not. for example, the customer name column in the example table makes clearly does not support these arithmetic or logical operations, and therefore it must be a string. its values must be enclosed by quotation marks, like "john".

the values in the order number column are numbers and can technically support arithmetic operations. however, adding or subtracting order numbers makes no sense, so we can either process them as numbers or as strings, and it’s up to the process developer to make this decision.

in the example excel table, each data point is stored in a cell, and excel has given a name for each cell. for example, the cell that has value 261.54 is called d2. the data in this cell could change, but the name of this cell remains the same: d2. as long as we read from cell d2, we will always get the latest value.

a variable is a common concept in programming. it is like a cell in an excel table, capable of storing data. a variable has a name, and through this name we can access the data stored in the variable or assign some new data to store in the variable.

the cells in an excel table are all named in the format “letter number”, but variable naming in programming languages are much more flexible. a legal variable name consists of english letters, numbers (except for the first character of a name), and underscores. some programming languages, like laiye rpa’s bot script, also support characters from other languages (like chinese). we recommend you give variables self-explanatory names that describe what they represent, instead of mysterious codes like d2. this helps us and others understand what the code is doing, though it has no bearing on how the program actually runs. laiye rpa's variable names are case-insensitive.

laiye rpa's variables are dynamically typed. this means that you do not need to declare the type of a variable when creating it, and the value and type of a variable can change during the runtime of a process. this is the same as other scripting languages like python, lua, and javascript.

the syntax for defining a variable is dim variable name. you can optionally assign an initial value to a variable by using the syntax dim variable name = initial value. you can also declare multiple variables with syntaxes like dim variable name 1 = value 1, variable name 2 or dim variable name 1 = value 1, variable name 2 = value 2. likewise, you can define constants (which are just variables whose values cannot change throughout the runtime of a process) with the syntax const name 1 = value 1, name 2 = value 2.

you can create calculations involving multiple variables and fixed data, and this calculation is called an expression. since the value of a variable can change over time, the value of an expression can also change. after writing an expression, its values are only computed when the process reaches the line of code where the expression is located, and the computation uses the values of the variable when the process reaches the line of code.

for example, x 2 is an expression. we cannot calculate the value of this expression if we do not know the value of x. if the process reaches x 2 and finds that the value of x is 3, then x 2 evaluates to 5.

of course, some expressions have meaningless calculations. for example, dividing a string is meaningless, but when we are writing the expression, it is unclear what the value of each variable is, so we cannot immediately determine that this expression is problematic. we can only realize this mistake during runtime, and so laiye rpa will throw runtime exceptions and exit from its process.

when writing a program, we usually write one line of code after another, expecting the program to run each line one after another, from top to bottom. however, this is often not flexible enough. for example, we might want to determine whether a certain condition is true during runtime and then decide whether to execute a certain statement based on this condition. this is a conditional statement.

conditionals are written differently in different programming languages, but the general form is the same

if then
    statement1
    statement2
end conditional


when the program reaches the if line, it evaluates the expression, which should yield a boolean value. if the expression evaluates to a non-boolean, it is often converted to a boolean value. based on the condition’s value, the program decides whether to run the statements between the if line and the end conditional line. in this example, this includes statement1 and statement2. only if the value evaluates to true will the program execute the statements. otherwise, it will skip through them.

we often encounter conditionals when writing programs. take the following example:

send email
if the email is not sent successfully, then
    report the failure to users
end conditional


the conditional expression should evaluate to true when the email is not sent successfully, and it would cause our program to report the error. oftentimes, when a conditional is behaving incorrectly, it is because the conditional expression is not evaluated correctly. in this example, the command to send an email would typically assign to a variable whether the email is sent successfully, and we can simply use this variable as the conditional expression.

the syntax of a loop is similar to that of a conditional.

loop when 
    statement 1
    statement 2
end loop


similar to a conditional, a loop first evaluates the expression when the program reaches the line loop when . if the expression evaluates to false, then the program will skip to end loop without executing the lines in between. if the expression evaluates to true, then it will first execute the enclosed lines (statement 1 and statement 2 in this example) and loop back to the line loop when <expression>, repeating this process. 

this allows us to use a loop to instruct our computer to complete repetitive tasks. for example,

send email
loop when the email is not sent successfully
    try to send email again
end loop


tries to resend the email indefinitely until the email is sent successfully. similar to a conditional, the most important part of a loop is setting up its expression. if we make a mistake and cause the condition to always evaluate to true, then this results in an infinite loop that the program cannot get out of. you must manually interrupt the program in this case.

网站地图