📄 confirm.hlp
字号:
{smcl}
{* 21feb2005}{...}
{cmd:help confirm}
{hline}
{title:Title}
{p2colset 5 20 22 2}{...}
{p2col :{hi:[P] confirm} {hline 2}}Argument verification{p_end}
{p2colreset}{...}
{title:Syntax}
{p 8 25 2}{cmdab:conf:irm} {cmdab:e:xistence} {it:string}
{p 8 25 2}{cmdab:conf:irm} [{cmd:new}] {cmdab:f:ile} {it:filename}
{p 8 25 2}{cmdab:conf:irm} {cmdab:name:s} {it:names}
{p 8 25 2}{cmdab:conf:irm} [{cmd:integer}] {cmdab:n:umber} {it:string}
{p 8 25 2}{cmdab:conf:irm} {cmdab:mat:rix} {it:string}
{p 8 25 2}{cmdab:conf:irm} {cmdab:sca:lar} {it:string}
{p 8 25 2}{cmdab:conf:irm} [ {cmd:new} | {cmd:numeric} | {cmdab:str:ing} |
{it:type} ] {cmdab:v:ariable} {it:varlist} [{cmd:,} {opt ex:act}]
{p 4 25 2}where {it:type} is {c -(} {cmd:byte} | {cmd:int} | {cmd:long} |
{cmd:float} | {cmd:double} | {cmd:str}{it:#} {c )-}
{title:Description}
{pstd}
{cmd:confirm} verifies that the arguments following {cmd:confirm ...} are of
the claimed type and issues the appropriate error message and nonzero return
code if they are not.
{pstd}
{cmd:confirm} is useful in do-files and programs when you do not want to bother issuing your own error message. {cmd:confirm} can also be combined with
{cmd:capture} to detect and handle error conditions before they arise; see
{helpb capture}.
{pstd}
See {hi:[P] confirm} for a complete description of this command.
{title:Option}
{phang}
{opt exact} specifies that a match be declared only if the names specified in
{varlist} match exactly; names that are abbreviations of variables are not
considered to be a match.
{title:Examples}
{pstd}{cmd:. confirm file `"c:\data\mydata.dta"'}
{pstd}{cmd:. confirm numeric variable price trunk rep78}
{pstd}You are writing a command that performs some action on each of the
variables in the local macro {it:varlist}. The action should be different
for string and numeric variables. The {cmd:confirm} command can be used
here in combination with the {helpb capture} command to switch between the
different actions:
{cmd:foreach v of local {it:varlist} {c -(}}
{cmd:capture confirm string variable `v'}
{cmd:if !_rc {c -(}}
{it:action for string variables}
{cmd:{c )-}}
{cmd:else {c -(}}
{it:action for numeric variables}
{cmd:{c )-}}
{cmd:{c )-}}
{pstd}An alternative solution using inline expansion of the extended macro
function {cmd::type} (see {help local}) reads
{cmd:foreach v of local varlist {c -(}}
{cmd:if substr("`:type `v''",1,3) == "str" {c -(}}
{it:action for string variables}
{cmd:{c )-}}
{cmd:else {c -(}}
{it:action for numeric variables}
{cmd:{c )-}}
{cmd:{c )-}}
{title:Also see}
{psee}
Manual: {bf:[P] confirm}
{psee}
Online: {helpb capture}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -