vb说是对象变量或with块变量未设置
'更改租赁模式时更新费用金额Private Sub cob_Mode_Click()
'需要先选择车牌和客户信息
If sCarNo = "" Or sCustId = "" Then
MsgBox ("请先选择车辆和客户信息")
Exit Sub
End If
nCnt = Val(txtWorkDays)
nECnt = Val(txtWeekEndCount)
'设置部分控件可用
txtWorkDays.Enabled = True
Label13.Enabled = True
Label14.Enabled = True
'如果租赁模式为按日租赁,则工作日和周末个数可用
If Trim(cob_Mode.Text) = "日" Then
Label13.Caption = "工作日"
Label19.Enabled = True
Label20.Enabled = True
txtWeekEndCount.Enabled = True
'总费用=工作日租赁价格*工作日个数+周末租金*周末个数
lCost = Val(AdoPrice.Recordset.Fields(1)) * nCnt + Val(AdoPrice.Recordset.Fields(2)) * nECnt
'以日为单位将 工作日+周末个数*2=天数 添加到租赁日期而计算返回时间
txtReturnTime = Trim(DateAdd("d", nCnt + nECnt * 2, CDate(txtLeaseTime)))
ElseIf Trim(cob_Mode.Text) = "周" Then
Label13.Caption = "周数"
Label19.Enabled = False
Label20.Enabled = False
txtWeekEndCount.Enabled = False
'总费用=周租金*周数
lCost = Val(AdoPrice.Recordset.Fields(3)) * nCnt
'以日为单位将 周个数*7=天数 添加到租赁日期而计算返回时间
txtReturnTime = Trim(DateAdd("d", nCnt * 7, CDate(txtLeaseTime)))
ElseIf Trim(cob_Mode.Text) = "月" Then
Label13.Caption = "月份数"
Label19.Enabled = False
Label20.Enabled = False
txtWeekEndCount.Enabled = False
'总费用=月租金*月个数
lCost = Val(AdoPrice.Recordset.Fields(4)) * nCnt
'以月为单位将月个数添加到租赁日期而计算返回时间
txtReturnTime = Trim(DateAdd("m", nCnt, CDate(txtLeaseTime)))
End If
'总体消费金额还要乘以折扣,不是会员只能乘以1
txtCost = lCost * Val(AdoCustomer.Recordset.Fields(5))
End Sub
调试后光标指向红色地方 --------------------编程问答-------------------- Val(AdoPrice.Recordset.Fields(4).value) ??? --------------------编程问答-------------------- lCost = Val(AdoPrice.Recordset.Fields(4)) * nCnt
改成:lCost = AdoPrice(4) * nCnt
我不明白了,为什么要把代码写复杂化。本来很简单的,要写这么长,好看吗? --------------------编程问答--------------------
AdoPrice应该是adodc控件 --------------------编程问答-------------------- 估计LZ的AdoPrice 控件没有指定recordsource ,没有使用refesh加载数据
再说,这样写代码真是蛋疼:
Private Sub cob_Mode_Click()
'需要先选择车牌和客户信息
If sCarNo = "" Or sCustId = "" Then
MsgBox ("请先选择车辆和客户信息")
Exit Sub
End If
'先判断是否有合适可用的数据
if adoprice.recordset is nothing then
msgbox "真是蛋疼"
exit sub
end if
nCnt = Val(txtWorkDays)
nECnt = Val(txtWeekEndCount)
'设置部分控件可用
txtWorkDays.Enabled = True
Label13.Enabled = True
Label14.Enabled = True
'如果租赁模式为按日租赁,则工作日和周末个数可用
dim sMode as string
smode=Trim(cob_Mode.Text)
select case smode
case "日" ' If Trim(cob_Mode.Text) = "日" Then
Label13.Caption = "工作日"
Label19.Enabled = True
Label20.Enabled = True
txtWeekEndCount.Enabled = True
'总费用=工作日租赁价格*工作日个数+周末租金*周末个数
lCost = Val(AdoPrice.Recordset.Fields(1)) * nCnt + Val(AdoPrice.Recordset.Fields(2)) * nECnt
'以日为单位将 工作日+周末个数*2=天数 添加到租赁日期而计算返回时间
txtReturnTime = Trim(DateAdd("d", nCnt + nECnt * 2, CDate(txtLeaseTime)))
case "周" ' ElseIf Trim(cob_Mode.Text) = "周" Then
Label13.Caption = "周数"
Label19.Enabled = False
Label20.Enabled = False
txtWeekEndCount.Enabled = False
'总费用=周租金*周数
lCost = Val(AdoPrice.Recordset.Fields(3)) * nCnt
'以日为单位将 周个数*7=天数 添加到租赁日期而计算返回时间
txtReturnTime = Trim(DateAdd("d", nCnt * 7, CDate(txtLeaseTime)))
case "月" 'ElseIf Trim(cob_Mode.Text) = "月" Then
Label13.Caption = "月份数"
Label19.Enabled = False
Label20.Enabled = False
txtWeekEndCount.Enabled = False
'总费用=月租金*月个数
lCost = Val(AdoPrice.Recordset.Fields(4)) * nCnt
'以月为单位将月个数添加到租赁日期而计算返回时间
txtReturnTime = Trim(DateAdd("m", nCnt, CDate(txtLeaseTime)))
end select ' End If
'总体消费金额还要乘以折扣,不是会员只能乘以1
txtCost = lCost * Val(AdoCustomer.Recordset.Fields(5))
End Sub
补充:VB , 数据库(包含打印,安装,报表)