for irow:=1 to sgbak.RowCount-1 do
if sgbak.Cells[3,irow]<>'' then if (formatdatetime('yyyy-mm-dd',strtodate(sgbak.Cells[3,irow])) >= FormatDateTime('yyyy-mm-dd',datechkfrom.Date)) and
(formatdatetime('yyyy-mm-dd',strtodate(Sgbak.Cells[3,irow])) <= formatdatetime('yyyy-mm-dd',datechkto.date)) then
querylist.Add(inttostr(irow));sgbak.Cells[3,irow] 储存日期值的,这列中,有时内容不是合法的日期比如;空,2006-4,2006,等无法转换成合法日期的值。在遇到这些值时,如何跳过该值(行),不显示异常,继续往下循环?谢谢。
if sgbak.Cells[3,irow]<>'' then if (formatdatetime('yyyy-mm-dd',strtodate(sgbak.Cells[3,irow])) >= FormatDateTime('yyyy-mm-dd',datechkfrom.Date)) and
(formatdatetime('yyyy-mm-dd',strtodate(Sgbak.Cells[3,irow])) <= formatdatetime('yyyy-mm-dd',datechkto.date)) then
querylist.Add(inttostr(irow));sgbak.Cells[3,irow] 储存日期值的,这列中,有时内容不是合法的日期比如;空,2006-4,2006,等无法转换成合法日期的值。在遇到这些值时,如何跳过该值(行),不显示异常,继续往下循环?谢谢。
begin
try
if sgbak.Cells[3,irow]<>'' then if (formatdatetime('yyyy-mm-dd',strtodate(sgbak.Cells[3,irow])) >= FormatDateTime('yyyy-mm-dd',datechkfrom.Date)) and
(formatdatetime('yyyy-mm-dd',strtodate(Sgbak.Cells[3,irow])) <= formatdatetime('yyyy-mm-dd',datechkto.date)) then
querylist.Add(inttostr(irow));
except end;
begin
try
//有可能發生異常的代碼
except
end;
end;
加了
try
except
好像还是有异常提示。
比如
sgbak.Cells[3,irow]=‘2006’
程序运行时,还是有提示。顺便问一下,如何判断一个字符串能否转换成相应合法的日期值?
试试on error resume next
这里不是VB VBA,如果是VB VBA我就会处理了。
begin
// if sgbak.Cells[3,irow]<>'' then
try
if (formatdatetime('yyyy-mm-dd',strtodate(sgbak.Cells[3,irow])) >= FormatDateTime('yyyy-mm-dd',datechkfrom.Date)) and
(formatdatetime('yyyy-mm-dd',strtodate(Sgbak.Cells[3,irow])) <= formatdatetime('yyyy-mm-dd',datechkto.date)) then
querylist.Add(inttostr(irow));
except end;
end;---------------------------
Debugger Exception Notification
---------------------------
Project textProject1.exe raised exception class EConvertError with message ''2006' is not a valid date'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
究竟是什么原因呢?
except
continue
end
for irow:=1 to sgbak.RowCount-1 do
begin
try
if sgbak.Cells[3,irow]<>'' then if (formatdatetime('yyyy-mm-dd',strtodate(sgbak.Cells[3,irow])) >= FormatDateTime('yyyy-mm-dd',datechkfrom.Date)) and
(formatdatetime('yyyy-mm-dd',strtodate(Sgbak.Cells[3,irow])) <= formatdatetime('yyyy-mm-dd',datechkto.date)) then
listdate.Add(inttostr(irow));
except
Continue;
end;
end;---------------------------
Debugger Exception Notification
---------------------------
Project textProject1.exe raised exception class EConvertError with message ''2006' is not a valid date'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------2006-9-28,10:23:09,2006,广盈有限公司,1000.00,备用金,,财务部
第一条记录,sgbak.Cells[3,irow]=2006 ,就通不过。刚学D7,遇到异常,或者复杂一点的,我就不行了。
for i:=0 to XXX do
begin
try
except
end;
end;你所说的仍报错,估计是你的DEBUG环境下测试的结果。
你直接运行你的EXE文件就应当不会有报错窗体出现了。