首页/文章/ 详情

HyperWork 2024 -二次开发-Tcl语言-括号与引号(7/12)

3月前浏览1236

Braces, quotes, and square brackets control when variables and commands are processed. They are also used to group parameters.

The example below illustrates that HyperWorks Desktop will not recognize arguments if they are not distinguished somehow:

set var1 HyperWorks uses Tcl and Tk;

In order to distinguish the arguments in a command string, you must use quotes or braces as shown in these examples:

set var1 "HyperWorks uses Tcl and Tk";
set var1 {HyperWorks uses Tcl and Tk};

Variables contained within quotes are always evaluated.

set var1 HyperWorks;
puts "$var1 uses Tcl and Tk";
HyperWorks uses Tcl and Tk

Since quotes do not have a right and a left, it is not possible to embed quotes within quotes directly. In the example below, HyperWorks Desktop interprets the quotes between "uses" and "tcl" as being the end quotes:

set var1 HyperWorks;
puts "$ HyperWorks uses "Tcl and Tk"";
extra characters after close-quote

Variables contained within braces are not evaluated.

set var1 HyperWorks;
puts {$var1 uses Tcl and Tk};
$var1 uses Tcl and Tk

Braces are very handy for program control. For example, you define a Tcl/Tk button that calls the command puts $var1 to return the most recent value of var1 when the button is pressed. The parameter for the button command will be {puts $var1} because you don’t want Tcl to evaluate $var1 when the button is defined, but instead when the button is pressed.

Square brackets run the commands contained within them.

set var1 HyperWorks;
set var2 [set var1];
puts $var2;
HyperWorks


来源:TodayCAEer
ACT二次开发UM
著作权归作者所有,欢迎分享,未经许可,不得转载
首次发布时间:2024-08-14
最近编辑:3月前
TodayCAEer
本科 签名征集中
获赞 18粉丝 28文章 243课程 0
点赞
收藏
作者推荐

HyperWork 2024 -二次开发-Tcl语言-注释与转义 (8/12)

The#characterisusedtoskiplinesandinsertcomments.ThiscanbeusedbothfromwithintkconaswellasfromwithinaTclscript.#Thesetwolinesarecommentsandarenotexecuted.#puts$x_expression;Manytimesyouneedtoincludequotes,braces,andsquarebracketsinvariables.Normally,TclattemptstoprocessthesevariablesasTclsyntax.However,youcan"escape"thesevariablesbyplacingabackslash\immediatelyprecedingthem:setx_expression"p1w1c1.x[0:10:0.1]";invalidcommandname"0:10:0.1"setx_expression"p1w1c1.x\[0:10:0.1\]";puts$x_expression;p1w1x1.x[0:10:0.01]来源:TodayCAEer

未登录
还没有评论
课程
培训
服务
行家
VIP会员 学习 福利任务 兑换礼品
下载APP
联系我们
帮助与反馈