我目前只学了存储后结果数据添加的方法,我想了解怎样一个字段内一行一行地添加完成记录问题。
还有怎样一个字段内数据输入操作完成后,又让可以其字段的内容后面又反复添加操作呢 如
155
424
846
255
382
491
5
6 这是一个字段内三次添加的结果,14823456添加完成后,又添加524589,又添加546521,需要添加时用这种方法添加。
这个方式怎么做呢
还有怎样一个字段内数据输入操作完成后,又让可以其字段的内容后面又反复添加操作呢 如
155
424
846
255
382
491
5
6 这是一个字段内三次添加的结果,14823456添加完成后,又添加524589,又添加546521,需要添加时用这种方法添加。
这个方式怎么做呢
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim i As Integer
Dim intCount As Integer
Dim intEndRow As Integer
Dim intStart As Integer cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\mydb.mdb;Persist Security Info=False"
rs.Open "select * from mytable", cn, adOpenStatic, adLockOptimistic
If rs.RecordCount > 0 Then
While Not rs.EOF
For i = rs.Fields.Count - 1 To 0 Step -1
If Len(rs.Fields(1)) > intCount Then
intCount = Len(rs.Fields(1))
End If
Next i
rs.MoveNext
Wend
rs.MoveFirst
End If
' intCount = intCount + 1
With MSFlexGrid1
.Col = Text2.Text 'Text2指定要填入的列
For i = .Rows - 1 To 1 Step -1
.Row = i
If Trim(.Text) <> "" Then
intEndRow = i
Exit For
End If
Next i
If intEndRow > 0 Then
intStart = fun_get_location(Text2.Text, 1, intEndRow)
While intStart > 0
For m = intStart To intEndRow
.Row = m
If rs.EOF Then
rs.AddNew
rs.Fields(0) = m - intStart + 1
rs.Fields(1) = Space(intCount) & .Text
rs.Update
Else
rs.Fields(1) = rs.Fields(1) & Space(intCount - Len(rs.Fields(1))) & .Text
rs.Update
End If
rs.MoveNext
Next m
rs.MoveFirst
intCount = intCount + 1
intStart = fun_get_location(Text2.Text, intStart, intEndRow)
Wend
End If
End With
rs.Close
cn.Close
Set rs = Nothing
Set cn = NothingEnd SubPrivate Function fun_get_location(ByVal intCol As Integer, ByVal intStart As Integer, ByVal intEnd As Integer) As Integer
Dim i As Integer
Dim strTemp As String
For i = intStart To intEnd
strTemp = strTemp & MSFlexGrid1.TextMatrix(i, intCol)
Next i
If InStr(1, strTemp, Text1.Text) > 0 Then
fun_get_location = intStart + InStr(1, strTemp, Text1.Text) + Len(Text1.Text) - 1
Else
fun_get_location = 0
End If
End FunctionPrivate Sub Form_Load()
Dim TextLine
Dim strFileName As String
Dim a() As String
Dim i As Integer
Dim j As Integer
With MSFlexGrid1
.Rows = 20
.Cols = 6 strFileName = App.Path & "\testdata2.txt" Open strFileName For Input As #1 ' 打开文件。 Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。
i = i + 1
.Row = i
For j = 1 To Len(TextLine)
.Col = j
.Text = Mid(TextLine, j, 1)
Next j Loop Close #1 ' 关闭文件。
End WithEnd Sub