怎样实现这种打印?

enjoynothing 2003-12-16 10:31:54
我想打印1-3班的所有学生ID
想在文本中显示如下:(每一行就是一个班级所有的学生ID,共3个班)
12 23 32 43 34 45 43
2 36 66 54 77 73 44
3 4 7 86 31 44 59

大概的代码如下:
Dim FileNumber As Integer
FileNumber = FreeFile
Open “c:\test.txt" For Input As #FileNumber

For i = 1 To 3
sql = "select studentID from studentTable where classID=" & i
Rstemp.CursorLocation = adUseClient
Rstemp.Open sql, Myconnection, adOpenStatic, adLockOptimistic
Rstemp.MoveFirst
’此处有问题,一个班的学生ID分成多行显示
While Not Rstemp.EOF
Print #FileNumber, Rstemp!studentID
Rstemp.MoveNext
Wend
Next i
Rstemp.Close
Close #FileNumber

请有心人帮忙改改此段代码,谢谢
...全文
42 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
shwen 2003-12-16
  • 打赏
  • 举报
回复
把这些修改为:
’此处有问题,一个班的学生ID分成多行显示
While Not Rstemp.EOF
Print #FileNumber, Rstemp!studentID
Rstemp.MoveNext
Wend


’此处有问题,一个班的学生ID分成多行显示
While Not Rstemp.EOF
Print #FileNumber, Rstemp!studentID; " ";
Rstemp.MoveNext
Wend
Print #FileNumber, ""

在 Print 后加分号,就不会另起一行了
SoHo_Andy 2003-12-16
  • 打赏
  • 举报
回复
试试
Dim FileNumber As Integer
Dim i As Integer
Dim strTemp As String

FileNumber = FreeFile
Open "c:\test.txt" For Output As #FileNumber
For i = 1 To 3
strTemp = ""
SQL = "select studentID from studentTable where classID=" & i
If rstemp.State = 1 Then
rsttemp.Close
End If
rstemp.CursorLocation = adUseClient
rstemp.Open SQL, Myconnection, adOpenStatic, adLockOptimistic
rstemp.MoveFirst
While Not rstemp.EOF
strTemp = strTemp & " " & rstemp!studentID
rstemp.MoveNext
Wend
Print #FileNumber, strTemp
Next i
rstemp.Close
Close #FileNumber
LanceJin 2003-12-16
  • 打赏
  • 举报
回复
先用个string变量存一个班的id不就行了
enjoynothing 2003-12-16
  • 打赏
  • 举报
回复
谢谢,可惜只给了20分

7,788

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧