关于每个编码器
我正在开发一个程序,在该程序中,我需要从列表框中选择一些项,然后单击按钮,将所选项以及项的比率保存在访问数据库中,同时将它们加载到文本文件中以进行打印。一切工作正常,只是项目的对齐方式不正确。
The Investigations and rate are not properly aligned
我编写的代码为:
Static total As Integer
Dim query As String
Dim l_index As Integer
If ListBox2.Items.Count > 15 Then
MsgBox("Maximum 15 Investigations can be selected.", vbInformation, "New receipt...")
ListBox2.Items.Clear()
Exit Sub ElseIf txtopd.Text.Trim = "" Or txtname.Text.Trim = "" Or ListBox2.Items.Count = 0 Then
MsgBox("Please fill all the fields", vbInformation, "New Receipt...")
txtopd.Focus()
Exit Sub
Else
'--------------------
Dim file As System.IO.StreamWriter
file = My.Computer.FileSystem.OpenTextFileWriter("text.txt", False)
file.Write("Date" & vbTab & vbTab & vbTab)
file.Write(lbldate.Text)
file.WriteLine()
file.Write("Time" & vbTab & vbTab & vbTab)
file.Write(lbltime.Text)
file.WriteLine()
file.Write("Receipt#" & vbTab & vbTab & vbTab)
file.Write(txtreceiptno.Text)
file.WriteLine()
file.Write("OPD#" & vbTab & vbTab & vbTab)
file.Write(txtopd.Text)
file.WriteLine()
file.Write("Name" & vbTab & vbTab & vbTab)
file.Write(txtname.Text)
file.WriteLine()
file.Write("______________________________________")
file.WriteLine()
Con.Open()
For l_index = 0 To ListBox2.Items.Count - 1
query = ("select Investigation.rate " & _
"from Investigation WHERE (((Investigation.Investigation) = '" & ListBox2.Items(l_index) & "'));")
Dim cmd2 As New OleDbCommand(query, Con)
'Con.Open()
Dim reader As OleDbDataReader = cmd2.ExecuteReader
reader.Read()
'file.WriteLine(reader(0))
txtrate.Text = reader.GetString(0)
total = total + txtrate.Text
'reader.Close()
'Con.Close()
' Con.Close()
'End If
Dim SqlString As String = "Insert Into patients (Receipt_No, OPD_MRD,Patientname,Investigation,Receipt_date,Receipt_time,rate) Values (?,?,?,?,?,?,?)"
Dim cmd As OleDbCommand = New OleDbCommand(SqlString, Con)
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("Receipt_No", txtreceiptno.Text.Trim())
cmd.Parameters.AddWithValue("OPD_MRD", txtopd.Text.Trim())
cmd.Parameters.AddWithValue("Patientname", txtname.Text.Trim())
cmd.Parameters.AddWithValue("Investigation", CStr(ListBox2.Items(l_index)).ToString())
cmd.Parameters.AddWithValue("Receipt_date", lbldate.Text)
cmd.Parameters.AddWithValue("Receipt_time", lbltime.Text)
cmd.Parameters.AddWithValue("rate", txtrate.Text.Trim())
'Con.Open()
cmd.ExecuteNonQuery() file.Write(ListBox2.Items(l_index).ToString().PadRight(50))
file.Write(txtrate.Text)
file.WriteLine()
Next
Con.Close()
file.Write("______________________________________")
file.WriteLine()
file.Write("Total Amount =" & vbTab & vbTab)
file.Write(total)
file.Close()
End If
'printing starts here
'-----------------------------------
Dim p As New Process
Dim info As New ProcessStartInfo
info.FileName = "text.txt"
info.Verb = "print"
p.StartInfo = info
p.Start()
'-----------------------------
我们将非常感谢您的答复。 谢谢