函式:Row和Rows的用法區別?
阿新 • • 發佈:2018-12-18
前提
剛剛敲程式碼時,出現了30009的錯誤,後來找出問題竟然發現只是少了一個S
溫習知識
Row:返回單元格或者區域所在的行號; Rows:返回區域的行數,即高度,有幾行。 前者常用於陣列公式,用來返回1234…常量,進行列舉運算
出現問題
解決方法
Private Sub cmdquery_Click() Dim txtsql, msgtext As String Dim mrc As ADODB.Recordset
If Not testtxt(Trim(txtcardno.Text)) Then MsgBox “請輸入卡號!”, 0 + 48, “提示” txtcardno.SetFocus Exit Sub End If
If Not IsNumeric(Trim(txtcardno.Text)) Then MsgBox "請輸入數字", 0 + 48, "提示" txtcardno.Text = "" txtcardno.SetFocus Exit Sub End If txtsql = "select * from line_info where cardno = '" & Trim(txtcardno.Text) & "'" Set mrc = ExecuteSQL(txtsql, msgtext) If mrc.EOF = True Then MsgBox "卡號不存在,請重新輸入", 0 + 48, "提示" txtcardno.Text = "" txtcardno.SetFocus Exit Sub End If With myFlexGrid1 .Rows = 1 *'把Row改成Rows就行了* .CellAlignment = 4 .TextMatrix(0, 0) = "卡號" .TextMatrix(0, 1) = "姓名" .TextMatrix(0, 2) = "上機日期" .TextMatrix(0, 3) = "上機時間" .TextMatrix(0, 4) = "下機日期" .TextMatrix(0, 5) = "下機時間" .TextMatrix(0, 6) = "消費金額" .TextMatrix(0, 7) = "餘額" .TextMatrix(0, 8) = "備註" Do While Not mrc.EOF .Rows = .Rows + 1 .CellAlignment = 4 .TextMatrix(.Rows - 1, 0) = mrc.Fields(1) .TextMatrix(.Rows - 1, 1) = mrc.Fields(3) .TextMatrix(.Rows - 1, 2) = mrc.Fields(6) .TextMatrix(.Rows - 1, 3) = mrc.Fields(7) .TextMatrix(.Rows - 1, 4) = mrc.Fields(8) & "" .TextMatrix(.Rows - 1, 5) = mrc.Fields(9) & "" .TextMatrix(.Rows - 1, 6) = mrc.Fields(11) & "" .TextMatrix(.Rows - 1, 7) = mrc.Fields(12) & "" .TextMatrix(.Rows - 1, 8) = mrc.Fields(13) & "" '移動到下一條記錄 mrc.MoveNext Loop End With mrc.Close End Sub