字符转换转昏了!!它错在哪儿? (100分)

L

linzy98

Unregistered / Unconfirmed
GUEST, unregistred user!
var
i,j,k:integer;
s,s1,s2,s3:string;
if length(s)=10 then
begin
s1:=copy(s,3,2)+copy(s,6,2)+copy(s,9,2);
end
else if length(s)=8 then
begin
s1:=copy(s,3,2)+'0'+copy(s,6,1)+'0'+copy(s,8,1);
end
else
begin
if copy(s,7,1) = '-' then
s1:=copy(s,3,2)+'0'+copy(s,6,1)+copy(s,8,2)
else
s1:=copy(s,3,2)+copy(s,6,2)+'0'+copy(s,9,1);
end;
with Form1.table1 do
begin
last;
s2:=FieldbyName('sh').Asstring;
j:=strtoint(s2)+1;
end;
k:=strtoint(copy(s2,1,6));
if k<strtoint(s1) then
begin
Form2.Edit1.Text := s1+inttoStr(1);
Form2.Edit2.Text := s1+inttoStr(1);
end
else
if k=strtoint(s1) then
begin
Form6.Edit1.Text := inttostr(j);
Form6.Edit2.Text := inttostr(j);
end;

错误好像是:不是一个有效的整形值。is no a valid integer value.
 
出什么问题了?
你的 S1 没有初始化。
另外 strtoint(s1) 要转换成功不是无条件的,这里的S1必须是一串数字。
 
过程中变量一定要进行初始化赋值, 这是一个良好的编程习惯,
你多次使用到了 s1, 可是都没有赋值
过程变量未赋值时一般是个随机数, 虽然你检查它的内容时
经常发现系统好象已经自动为你赋值了, 可是, 千万别上当.
 
怎么不说出了什么问题的?
inttostr函数要求字符串必须都是数字字符的,而且不能为空!
你应当先判断一下,字符串是否为空,然后再进行转化!
 
if k<strtoint(s1) then
其中的s1不知道在什么地方赋值了???
 
var
i, j, k : integer;
s, s1, s2, s3: string;
begin
with Form1.table1 do
begin
last;
s2 := FieldbyName('sh').Asstring;
j := strtoint(s2) + 1; //这里,s2有可能为空
end;
k := strtoint(copy(s2, 1, 6)); //这里,s2的长度有可能不足6,也许为空

if k < strtoint(s1) then //这以下,s1没有赋值
begin
Edit1.Text := s1 + inttoStr(1);
Edit2.Text := s1 + inttoStr(1);
end
else
if k = strtoint(s1) then
begin
Form6.Edit1.Text := inttostr(j);
Form6.Edit2.Text := inttostr(j);
end;
end;
 
基本同意楼上(:svw0506)
补充一点,既然你FieldbyName('xx').AsString 都可以传成整型,为何不.AsInteger哪,这样为空的时候,就会认为是0,从而StrToInt不会出错
 
同意楼上:完颜康
 
用strtoint出錯的話,你就用trunc取整啊!
 
s1没有初始化,同意楼上的
 
应该就是S1 的问题了!
 
不好意思,S1是有赋值的,我把它加上了,错误好像是:不是一个有效的整形值。is no a valid integer value.
 
一定会给大家分的, 快快帮我看看这个问题吧
 
哈哈
我看你是想判断时间格式吧?好像用不着这么麻烦.你用decodedate函数就可以解决
你字符转换的问题了.
 
可以肯定是strtoint报的错,设置断点看看。应该问题会被马上解决的。
 
没有看程序
如果strtoint 出错,就用strtointdef.
 
谢谢大家了
 
顶部