第1个回答 2008-03-08
1. 在 包含 type 字段的表中建立 ID 字段, 类型为 自动编号
2. 用 datagrid 和 adodc 关联数据库以及表
3. 在 form 上画出 command1 , text1 和 DTPicker1 控件
4. 在command1 中添加代码
dim i as integer'定义一个全局变量,就是放到程序的最前面,不要放到sub块里面
Private Sub Command1_Click()
i=DateDiff("ww", "2007-1-1", DTPicker1.Value) + 1
'判断长度
'如果长度为1,补2个0
if len(i)=1 then
text1.Text="00"& i
else '否则补1个0,因为最大52个星期。2位数,所以补1个0
text1.Text="0"& i
end if
Datediff日期计算
"ww"表示周(星期)
用DTPicker1.Value-2007-1-1默认为0,所以+1
第2个回答 2008-03-07
方法一:
你的数据库该表应该有个自动递增ID,每增加记录的时候可以先读出当前数据库表中递增ID号的最大数,然后在你的第三个XXX那里加上1即可
方法二:加个控件记录你当前已经最大ID号,然后在你的xxx那里+1即可
第3个回答 2008-03-07
1. 在 包含 type 字段的表中建立 ID 字段, 类型为 自动编号
2. 用 datagrid 和 adodc 关联数据库以及表
3. 在 form 上画出 command1 , text1 和 DTPicker1 控件
4. 在command1 中添加代码
Dim iniDate As Date
iniDate = "2007-01-01"
Text1.Text = Adodc1.Recordset("type") & "-" & Format(Int((DTPicker1.value - iniDate) / 7), "000") & "-" & Format(Adodc1.Recordset("ID"), "000")
注: 楼主说明中需要取的是2007-01-01至dtpicker1的周数,但例子中给出的却是2007-01-01至dtpicker1的月数,如果是月数,则用以下代码
Dim iniDate As Date
iniDate = "2007-01-01"
Text1.Text = Adodc1.Recordset("type") & "-" & Format((Year(DTPicker1.Value) - 2007) * 12 + Month(DTPicker1.Value), "000") & "-" & Format(Adodc1.Recordset("ID"), "000")
使用: 在 datagrid 中选择一条记录,单击 command1, text1即生成编号
第4个回答 2008-03-07
dim i as integer
i=DateDiff("ww", "2007-1-1", DTPicker1.Value) + 1
'判断长度
'如果长度为1,补2个0
if len(i)=1 then
text1.Text="00"& i
else '否则补1个0,因为最大52个星期。2位数,所以补1个0
text1.Text="0"& i
end if
Datediff日期计算
"ww"表示周(星期)
用DTPicker1.Value-2007-1-1默认为0,所以+1