以下是我的代码 :
Dim tb As Table = Tables("出库主表")
Dim r As Row = tb.current
If r("单据编号") = "CK-" Then
Dim d As Date = r("开单日期")
Dim y As Integer = d.Year
Dim m As Integer = d.Month
Dim Days As Integer = Date.DaysInMonth(y,m)
Dim fd As Date = New Date(y,m,1) '获得该月的第一天
Dim ld As Date = New Date(y,m,Days) '获得该月的最后一天
Dim bh As String = Format(d,"yyyyMM") '生成编号的前6位,4位年,2 位月.
If r("单据编号").StartsWith(bh) = False '如果编号的前6 位不符
Dim max As String
Dim idx As Integer
max = tb.DataTable.Compute("Max(单据编号)","开单日期 >= #" & fd & "# And 开单日期 <= #" & ld & "# And [记录顺序] <> " & r ("记录顺序")) '取得该月的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(7,6)) + 1 '获得最大编号的后三 位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
r("单据编号") ="CK-" & bh & "-" & Format (idx,"000000")
End If
End If
tb.save()
Tables("出库子表").save()
但运行后,出错 提示
.NET Framework 版本:2.0.50727.3053
Foxtable 版本:2015.12.22.1
错误所在事件:窗口,出库开单,保 存,Click
详细错误信息:
startIndex cannot be larger than length of string.
Parameter name: startIndex