The contact so they can help me with a problem that I have in a small form that I use with visual basic to read data.
I have a form with two fields: row and item number I need to save in the following way:
<table>
<th>fila</th>
<th>item</th>
<tbody>
<tr><td>f1</td><td>1</td></tr>
<tr><td>f1</td><td>2</td></tr>
<tr><td>f1</td><td>3</td></tr>
<tr><td>f1</td><td>4</td></tr>
</tbody>
</table>
The row (txtfila) is written first and when I press enter the item number (txtpalet) of that row can be entered, which can be many. When I finish inserting the item numbers for that row I press the save button and generate a .csv file on the computer.
This works, but I can only save the item number:
item
1
2
3
4
5
6
I can not save another column to that file that is the row ...
This is my code:
Imports System.IO
Imports System.Text
Public Class Form1
Dim _stringBuilder As StringBuilder
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtFila.Focus()
_stringBuilder = New StringBuilder()
End Sub
Private Sub txtPalet_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPalet.KeyPress
If e.KeyChar = ChrW(Keys.Enter) Then
_stringBuilder.Append(txtFila.Text)
_stringBuilder.Append(txtPalet.Text).AppendLine()
txtPalet.Text = ""
End If
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fecha As String
Dim hora As String
Dim archivo As String
fecha = Format(Now, "dd-mm-yyyy")
hora = Now.ToString("HHmm")
archivo = "bpt1" + "_" + fecha + "_" + hora + ".csv"
Dim writer = New StreamWriter(archivo, True)
writer.Write(_stringBuilder.ToString())
writer.Flush()
writer.Close()
MsgBox("Documento Guardado como : " + archivo)
End Sub
Private Sub txtFila_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtFila.KeyPress
Dim valorFila As String
If e.KeyChar = ChrW(Keys.Enter) Then
valorFila = txtFila.Text
If Len(valorFila) >= 2 Then
txtPalet.Focus()
txtFila.ReadOnly = True
Else
MsgBox("Ingrese una Fila Valida")
txtFila.Text = ""
txtFila.Focus()
End If
End If
End Sub
End Class
If you can give me the information on how to include the new column in the file, have:
column 1 (row) column 2 (item)
thanks.