--------------------
网页上Table的字段长度的估计:
DataSet中的每一张表都会在网页上生成一些Table,这些Tables的外在形式应该是相同的。即Tables的相同的Cell应有同样的长度。函数子程序SetCellSize计算DataTable的每一字段平均字符数,和字段名的字符数,并取其大者,若字段的某一纪录或字段名都是ASCII字符,则其字符数减半。用此数据便可估计网页上的Table的相应字段的显示长度。
下面是SetCellSize的程序,容易理解。
Function SetCellSize(myTable as DataTable)
dim myRow as DataRow
dim i,j,k,m as integer
dim aa() as integer
dim myBool as Boolean
m=myTable.columns.count-1
redim aa(m)
for i=0 to m
aa(i)=0
next
for each myRow in myTable.rows '计算每一字段的平均字符长度
for i=0 to myTable.columns.count-1
dim mystr as string
mystr=myRow(myTable.columns(i)).tostring
j=len(mystr)
if j>0 then
myBool=true
for k=1 to j '判断dataTable中的每一项是否包括汉字
dim str1 as char=mid(mystr,k,1)
if ascw(str1)>255 then '有非ASCII字符
myBool=false
exit for
end if
next
if myBool then j=(j/2+0.5) '都是ASCII字符,字符串长度减半
aa(i)+=j
end if
next
next myRow
k=myTable.rows.count
for i=0 to m
aa(i)=aa(i)/k 'DataTable的每一列的平均长度
next
for i=0 to myTable.columns.count-1 '对每一字
网页上Table的字段长度的估计:
DataSet中的每一张表都会在网页上生成一些Table,这些Tables的外在形式应该是相同的。即Tables的相同的Cell应有同样的长度。函数子程序SetCellSize计算DataTable的每一字段平均字符数,和字段名的字符数,并取其大者,若字段的某一纪录或字段名都是ASCII字符,则其字符数减半。用此数据便可估计网页上的Table的相应字段的显示长度。
下面是SetCellSize的程序,容易理解。
Function SetCellSize(myTable as DataTable)
dim myRow as DataRow
dim i,j,k,m as integer
dim aa() as integer
dim myBool as Boolean
m=myTable.columns.count-1
redim aa(m)
for i=0 to m
aa(i)=0
next
for each myRow in myTable.rows '计算每一字段的平均字符长度
for i=0 to myTable.columns.count-1
dim mystr as string
mystr=myRow(myTable.columns(i)).tostring
j=len(mystr)
if j>0 then
myBool=true
for k=1 to j '判断dataTable中的每一项是否包括汉字
dim str1 as char=mid(mystr,k,1)
if ascw(str1)>255 then '有非ASCII字符
myBool=false
exit for
end if
next
if myBool then j=(j/2+0.5) '都是ASCII字符,字符串长度减半
aa(i)+=j
end if
next
next myRow
k=myTable.rows.count
for i=0 to m
aa(i)=aa(i)/k 'DataTable的每一列的平均长度
next
for i=0 to myTable.columns.count-1 '对每一字
| 对此文章发表了评论 |

