用户控件,属性值一直无易做图确传送?请求帮忙
'这个过程是对用户控件属性进行赋值的过程,可是赋值过后,总会还有一个用户控件数组的值,没有赋值到?比如目前有10行10列,最后一行cantai1(9).RoomName就会为空值。不知是怎么回事?Function RoomNameStatus(strRoomStyle As String, strStauts As String)
Dim strSql As String
Dim temp As New ADODB.Recordset
Dim intK As Integer
If strStauts = "全部" Then
strSql = "select rid,rname,rtstate from rooms where roomtype='" & Trim(strRoomStyle) & "'"
Else
strSql = "select rid,rname,rtstate from rooms where roomtype='" & Trim(strRoomStyle) & "'" & " And rtstate= " & " '" & Trim(strStauts) & "'"
End If
If temp.State = 1 Then temp.Close
temp.Open strSql, Con, adOpenDynamic, adLockReadOnly
temp.MoveFirst
intK = 0
Do While Not temp.EOF
With CanTai1(intK)
.RoomName = temp.Fields("rname").Value
.RoomNo = temp.Fields("rid").Value
.RoomBackColor = temp.Fields("rtstate").Value
End With
Debug.Print CanTai1(intK).RoomName
Debug.Print intK
intK = intK + 1
temp.MoveNext
Loop
temp.Close
End Function
上面程序是获取用户控件值的。
------------------------------------------------
下面是用户控件过程代码
Option Explicit
Private mstrRoomName As String
Private mstrRoomNo As String
Private mintRoomRenShu As Integer
Private mintRoomMoney As String
Private mstrRoomBackColor As String
Private mblnIsSelect As Boolean
'Private mstrLabStatus As String
Public Event Click()
'属性:是否选中
Public Property Let IsSelect(ByVal New_Value As Boolean)
mblnIsSelect = New_Value
ShaSelect.Visible = New_Value
End Property
Public Property Get IsSelect() As Boolean
IsSelect = mblnIsSelect
End Property
'属性:餐台编码
Public Property Get RoomNo() As String
RoomNo = mstrRoomNo
End Property
Public Property Let RoomNo(ByVal New_Value As String)
mstrRoomNo = New_Value
LabCanTaiNo.Caption = mstrRoomNo
PropertyChanged "RoomNo"
End Property
'属性:餐台名称
Public Property Get RoomName() As String
RoomName = mstrRoomName
End Property
Public Property Let RoomName(ByVal New_Value As String)
mstrRoomName = New_Value
LabCanTaiName.Caption = mstrRoomName
PropertyChanged "RoomNanme"
End Property
'属性:餐台状态值
Public Property Get RoomBackColor() As String
RoomBackColor = mstrRoomBackColor
End Property
Public Property Let RoomBackColor(ByVal New_Value As String)
mstrRoomBackColor = New_Value
Select Case New_Value
Case "空闲"
LabCanTaiStatus.Caption = "空闲"
Picture2.BackColor = strKeYongTaiBackColor
Case "占用"
LabCanTaiStatus.Caption = "占用"
Picture2.BackColor = strZhanYongTaiBackColor
Case "停用"
LabCanTaiStatus.Caption = "停用"
Picture2.BackColor = strTingYongTaiBackColor
Case "预定"
LabCanTaiStatus.Caption = "预定"
Picture2.BackColor = strYiDingTaiBackColor
Case "打扫"
LabCanTaiStatus.Caption = "打扫"
Picture2.BackColor = strDaSaoTaiBackColor
End Select
PropertyChanged "RoomBackColor"
End Property
'属性:餐台就餐人数
Public Property Get RoomRenShu() As Integer
RoomBackColor = mstrRoomBackColor
End Property
Public Property Let RoomRenShu(ByVal New_Value As Integer)
mintRoomRenShu = New_Value
LabRenShu.Caption = "人数:" & Str(mintRoomRenShu)
LabRenShu.Visible = True
PropertyChanged "RoomRenShu"
End Property
'属性:餐台就餐消费总金额
Public Property Get RoomMoney() As String
RoomMoney = mintRoomMoney
End Property
Public Property Let RoomMoney(ByVal New_Value As String)
RoomMoney = New_Value
LabMoney.Caption = "总额¥:" & Trim(RoomMoney)
LabMoney.Visible = True
PropertyChanged "RoomMoney"
End Property
Private Sub LabCanTaiName_Click()
strRoomNo = LabCanTaiNo.Caption
strRoomName = LabCanTaiName.Caption
RaiseEvent Click
End Sub
Private Sub LabCanTaiNo_Click()
strRoomNo = LabCanTaiNo.Caption
strRoomName = LabCanTaiName.Caption
RaiseEvent Click
End Sub
Private Sub LabCanTaiStatus_Click()
strRoomNo = LabCanTaiNo.Caption
strRoomName = LabCanTaiName.Caption
RaiseEvent Click
End Sub
Private Sub LabMoney_Click()
strRoomNo = LabCanTaiNo.Caption
strRoomName = LabCanTaiName.Caption
RaiseEvent Click
End Sub
Private Sub LabRenShu_Click()
strRoomNo = LabCanTaiNo.Caption
strRoomName = LabCanTaiName.Caption
RaiseEvent Click
End Sub
Private Sub Picture1_Click()
strRoomNo = LabCanTaiNo.Caption
strRoomName = LabCanTaiName.Caption
RaiseEvent Click
End Sub
Private Sub Picture2_Click()
strRoomNo = LabCanTaiNo.Caption
strRoomName = LabCanTaiName.Caption
RaiseEvent Click
End Sub
Private Sub UserControl_Initialize()
LabCanTaiName.Left = (Picture2.Width - LabCanTaiName.Width) / 2
End Sub
--------------------编程问答-------------------- PropertyChanged "RoomNanme" ?? PropertyChanged "RoomName" --------------------编程问答--------------------
这个不是必须的,如果在设计时的属性设置不需要保存,那么 PropertyChanged 是不需要的 --------------------编程问答-------------------- 你首选应该检查取得的记录集:
1)记录数是否不足10条?
2)rname 字段是否为空? --------------------编程问答-------------------- 谢谢楼上的解答
补充:VB , 数据库(包含打印,安装,报表)