以下是引用hejfen在2009-5-18 11:20:00的发言:
还有个小问题,原来有的房号不用生成的的问题, if T <> n1 AndAlso T <> n2 Then,只是最大和最小两个房号不重复,如果我有其它房号,还是会重复的,另外层号 n1 = tb2.Compute("min(房)",Tj), n2 = tb2.Compute("max(房)",Tj),如果有房号1101,即11层01房,会被识别是最小值。高手还有更简单的代码吗?
可想而知:你没看26楼代码.另如你一开始就清楚明白说出要求,问题早就解决了,何需如此时日!
Dim Row,n,n1,n2,i,max,min As Integer
Dim Zy,T As String
Dim tb1,tb2 As Table
Dim r,r1,r2 as row
tb1 = Tables("表A")
tb2 = Tables("表A.表B")
tb1.Filter = "路名 is not null"
With DataTables("表B").DataCols
If .Contains("层") = False AndAlso .Contains("房号") = False Then
.Add("层", GetType(Integer),"SubString([房],1,Len([房])-2)")
.Add("房号", GetType(Integer),"SubString([房],Len([房])-1,2)")
End If
for Row = 0 to tb1.Rows.count-1
tb1.Select(row,0)
r = tb1.Rows(Row)
for each r1 in tb2.rows
zy =zy & "|" & r1("房")
Next
n1 = tb2.Compute("min(层)")
n2 = tb2.Compute("max(层)")
min = tb2.Compute("min(房号)")
max = tb2.Compute("max(房号)")
if n2 > n1 AndAlso n1 > 0 then
tb2.Redraw = False
For n = n1 to n2
For i = min to max
T = n & format(i,"00")
if Zy.IndexOf(T) = -1 then
r2 = tb2.addnew
r2("房") = T
r2("状态") ="虚拟"
end if
Next
Next
tb2.Redraw = true
end if
Next
.Delete("房号")
.Delete("层")
End with
[此贴子已经被作者于2009-5-18 14:11:51编辑过]