Action()
{
When defining an array, be sure to specify that the size
variable definition must be placed before all operations, and placed at the front of the script
int num;//Define the numeric variable
int numy[5];//Define the integer array
char *str1, *str2,*str3;//Define string variable
char stry[10],filename[5],data[10];//Define string array
//Assign
num=10 to the value;
correct output method
lr_output_message("%d",num);
Error output method
// lr_output_message(num);
1. Variable assignment
str1="hello world1";
str2="hello world2";
lr_output_message(str1);
concatenated string
// str3=str1+str2;//incorrect writing have illegal types `pointer to char' and ` pointer to char'
// sprintf(str3,"%s.%s",str1,str2);//Invalid spelling Invalid parameter detected in function
sprintf(stry,"%s+%s",str1,str2);
// strcpy(str1,"Copy the string to the variable +hello world");//This way of writing is wrong.
lr_output_message(stry);
//String array assignment
strcpy(stry,"Assign string to array variable +Hello World");
lr_output_message(stry);
2. Parameter assignment
//The left side is assigned to the right parameter
lr_save_string("Hello hourh","paraStr1");
lr_output_message(lr_eval_string("{paraStr1}"));
//变量的值赋值给参数
lr_save_string(stry,"paraStr2");
lr_output_message(lr_eval_string("{paraStr2}"));
//数值赋值给参数
lr_save_int(123,"paraNum1");
lr_output_message(lr_eval_string("{paraNum1}"));
变量中的数值赋值给参数--???有疑问,去掉以下这句输出语句,则按"-371720758"一串数字计算,加上就按正常数值计算啦 奇怪的很
或者把变量值初始化放在这里也可以按10进行运算,因此以后用到的时候再对数值初始吧,以免出
lr_output_message("%d",num);
lr_save_int(num*2,"paraNum2");
lr_output_message("%d",num);
lr_output_message(lr_eval_string("{paraNum2}"));
3、参数取值
lr_eval_string("{paraStr2}");
lr_eval_string("{paraNum2}");
4、参数转换为变量
strcpy(stry,lr_eval_string("{paraStr1}"));
lr_output_message("%s",stry);
num=atoi(lr_eval_string("{paraNum1}"));
lr_output_message("%d",num);
5、将参数格式化输出到变量
lr_save_string("log","hzm");
sprintf(filename,"filename_201607%d.%s",rand()0,lr_eval_string("{hzm}"));
lr_output_message("文件名是:%s",filename);
sprintf(data, "%d/%d/%d", 1+rand(), 1+rand()(, 2009+rand()%6);
lr_output_message("文件名是:%s",data);
参数赋值给参数
lr_save_string(lr_eval_string("{paraNum2}"),"paraNum1");
lr_output_message(lr_eval_string("{paraNum1}"));
return 0;
}
1、变量的赋值
//将字符串赋值给变量 char strTemp[30]; strcpy(strTemp, "Hello World!!"); //错误的字符串赋值方式 strTemp = "Hello World!!"; /* 注: * 在LR中若直接将字符串赋值给变量,编译时将会报错 * 报错信息:operands of = have illegal types `char' and `pointer to char' */ //将数值赋值给变量 int x = 10; /* 注: * 在LR中,变量的声明一定要放在脚本的最前面,且声明的语句中不要有其他的脚本代码 * 若将以上申明放置在脚本中部,将会产生如下形式的报错信息 * illegal statement termination * skipping 'int' * undeclared identifier 'x' */
2、参数的赋值
//将字符串赋值给参数 lr_save_string("Hello World!!","paraStr"); //将变量中的值赋值给参数 char strTemp[30]; strcpy(strTemp, "Hello World") ; lr_save_string(strTemp, "paraStr"); //将数值直接赋值给参数 lr_save_int(123, "paraNum"); //将变量中的数值赋值给参数 int num = 10; lr_save_int(num*2, "paraNum");
3、参数的取值
//从参数中进行取值,不管参数是字符串还是数值 lr_eval_string("{paraStr}"); lr_eval_string("{paraNum}"); //取出的值均为字符串类型,因此输出时格式需为"%s" lr_output_message("%s", lr_eval_string("{paraNum}"));
4、参数=>变量
//将参数转换为字符串变量,参数paraStr中的值为"Hello World!!" char strTemp[30]; strcpy(strTemp, lr_eval_string("{paraStr}")); lr_output_message("%s", strTemp); //将参数转换为数值变量,参数paraNum中的值为"246" int num; num = atoi(lr_eval_string("{paraNum}")); //将字符串转换为数值 lr_output_message("%d", num); //将参数格式化输出到变量 SeatPrefListCount = atoi( lr_eval_string("{SeatPrefList_count}") ); sprintf(varRandomSeatPref, "{SeatPrefList_%d}", 1+rand()%SeatPrefListCount); //将格式化的随机日期写入变量varRandomDepartDate sprintf(varRandomDepartDate, "%d/%d/%d", 1+rand()%12, 1+rand()%28, 2009+rand()%6);
5、参数=>参数
//参数的复制:将参数paraStr_1的值复制到参数paraStr_2 lr_save_string(lr_eval_string("{paraStr_1}"),"paraStr_2");