Hola amigo quisiera si es posible me dieran una ayudita que no consigo como solucionar tengo un codigo para introducir datos a un listview que lo guarda automaticamente en un archivo .txt pero me salta un error este proyecto lo encontre en vb6 y lo e llevado a vs2008
Visual Studio 2008
Form1
Option Strict Off
Option Explicit On
Friend Class Form1
Inherits System.Windows.Forms.Form
Private Declare Function SetErrorMode Lib "kernel32" (ByVal wMode As Integer) As Integer
Private Declare Sub InitCommonControls Lib "Comctl32" ()
Public sName As String
Public sTel As String
Public sEmail As String
Public bAction As Boolean
Public Sub Exportar_ListView(ByRef ListView As System.Windows.Forms.ListView, ByRef PathArchivo As String, ByRef sChar As String)
On Error GoTo errsub
Dim Linea As String
Dim x, i As Short
FileOpen(1, PathArchivo, OpenMode.Output)
With ListView
For i = 1 To ListView.Items.Count
Linea = .Items.Item(i).Text & sChar
For x = 1 To ListView.Columns.Count - 1
Linea = Linea & .Items.Item(i).SubItems(x).Text & sChar
Next
PrintLine(1, Linea)
Next
FileClose()
End With
Exit Sub
errsub:
MsgBox(Err.Description, MsgBoxStyle.Critical)
FileClose()
End Sub
Public Sub Importar_ListView(ByRef ListView As System.Windows.Forms.ListView, ByRef PathArchivo As String, ByRef sChar As String)
On Error GoTo errsub
Dim Linea As String
Dim x, i As Short
Dim sStr() As String
Dim it As Integer
With ListView
.Items.Clear()
.View = System.Windows.Forms.View.Details
FileOpen(1, PathArchivo, OpenMode.Input)
While Not EOF(1)
Linea = LineInput(1)
sStr = Split(Linea, sChar)
.Items.Add(sStr(LBound(sStr)))
it = it + 1
For i = LBound(sStr) To UBound(sStr) - 1
.Items.Item(it).SubItems.Add(sStr(i + 1))
Next
End While
FileClose()
End With
Exit Sub
errsub:
MsgBox(Err.Description, MsgBoxStyle.Critical)
End Sub
Private Sub cmdRegs_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdRegs.Click
Dim Index As Short = cmdRegs.GetIndex(eventSender)
Dim xlvItem As System.Windows.Forms.ListViewItem
If Index <> 0 Then
If ListView1.FocusedItem Is Nothing Then
MsgBox("No hay item seleccionado", MsgBoxStyle.Exclamation)
Exit Sub
End If
End If
Select Case Index
Case 2
ListView1.Items.RemoveAt(ListView1.FocusedItem.Ind ex)
Call Exportar_ListView(ListView1, My.Application.Info.DirectoryPath & "\datos-ListView.txt", vbTab)
Exit Sub
Case 1
With frmAddRegs
.txtName.Text = ListView1.FocusedItem.Text
.txtTel.Text = ListView1.FocusedItem.SubItems(1).Text
.txtEmail.Text = ListView1.FocusedItem.SubItems(2).Text
End With
frmAddRegs.ShowDialog()
If bAction Then
xlvItem = ListView1.FocusedItem
xlvItem.Text = Me.sName
If xlvItem.SubItems.Count > 1 Then
xlvItem.SubItems(1).Text = Me.sTel
Else
xlvItem.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem( Nothing, Me.sTel))
End If
If xlvItem.SubItems.Count > 2 Then
xlvItem.SubItems(2).Text = Me.sEmail
Else
xlvItem.SubItems.Insert(2, New System.Windows.Forms.ListViewItem.ListViewSubItem( Nothing, Me.sEmail))
End If
Call Exportar_ListView(ListView1, My.Application.Info.DirectoryPath & "\datos-ListView.txt", vbTab)
End If
Case 0
frmAddRegs.ShowDialog()
If bAction Then
xlvItem = ListView1.Items.Add(Me.sName)
If xlvItem.SubItems.Count > 1 Then
xlvItem.SubItems(1).Text = Me.sTel
Else
xlvItem.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem( Nothing, Me.sTel))
End If
If xlvItem.SubItems.Count > 2 Then
xlvItem.SubItems(2).Text = Me.sEmail
Else
xlvItem.SubItems.Insert(2, New System.Windows.Forms.ListViewItem.ListViewSubItem( Nothing, Me.sEmail))
End If
Call Exportar_ListView(ListView1, My.Application.Info.DirectoryPath & "\datos-ListView.txt", vbTab)
End If
End Select
With Me
.bAction = False
.sName = ""
.sTel = ""
.sEmail = ""
End With
End Sub
Private Sub Form_Initialize_Renamed()
Call SetErrorMode(2)
Call InitCommonControls()
End Sub
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
With ListView1
.Columns.Add("", "Nombre y apellido", CInt(VB6.TwipsToPixelsX(3000)))
.Columns.Add("", "Teléfono", CInt(VB6.TwipsToPixelsX(1500)))
.Columns.Add("", "Email", CInt(VB6.TwipsToPixelsX(3000)))
End With
Call Importar_ListView(ListView1, My.Application.Info.DirectoryPath & "\datos-ListView.txt", vbTab)
End Sub
End Class
Form2
Option Strict Off
Option Explicit On
Friend Class frmAddRegs
Inherits System.Windows.Forms.Form
Enum eAction
eADD = 0
eMOD = 1
End Enum
Public bAction As eAction
Private Sub cmdCancel_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCancel.Click
Me.Close()
End Sub
Private Sub cmdOk_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdOk.Click
If Len(txtName.Text) = 0 Then
MsgBox("Falta el campo nombre", MsgBoxStyle.Exclamation)
Else
With Form1
.bAction = True
.sName = txtName.Text
.sEmail = txtEmail.Text
.sTel = txtTel.Text
End With
Me.Close()
End If
End Sub
End Class
Ahora el error que me da al intentar guardar algun dato :