vb leer todos los archivos a list1 archivo random

Hola soy ordo
El programa que tengo hecho me guarda cada nombre por archivo y me lee el cliente por nombre y lo hace perfecto, pero a la hora de poner todos los nombres en el list1 no lo hace, no se que hago mal.
ahora pongo el programa que tengo, gracias
 

Adjuntos

  • facejemplo1.rar
    3 KB · Visitas: 5
Yo te ayudo si subís el código en visual 2010 (o alguno compatible) o si subís el código acá usando los tag PHP o Code.
 
A ver si esto te sirve, carga en un ComboBox (Localidad) las "Localidades", y no las repite.

Código:
    RS.MoveFirst
    Do While RS.EOF = False
        Localidad = RS.Fields("Localidad")
        With Combo_Localidad
            Agregar = True
            For Item = 0 To .TopIndex
                    If .List(Item) = Localidad Then
                        Agregar = False
                    Else
                        Agregar = True
                    End If
            Next Item
            If Agregar = True Then
                .AddItem Localidad
            End If
        End With
        RS.MoveNext
    Loop
 
Hola soy ordo
vb 6.0
el problema del programa es que cada nombre es un archivo , quisiera cargar todos los nombres de archivo en el list1, gracias

Código:
Option Explicit
Private Type Registro
nombre As String * 30
direccion As String * 25
poblacion As String * 30
telefono As String * 20
nif As String * 20
correo As String * 40
End Type
Dim forma As Registro

Private Type Type_Indices
    Codigo_clientes As Integer
End Type

Const Prefix_Clientes = "Cliente"  'Asignamos un prefijo a las facturas para cuandos se guarden
Private numeros As Type_Indices





Private Sub Command1_Click()
'Nuevo Cliente





Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text2.SetFocus
 Dim intFile As Integer
intFile = FreeFile

 
    numeros.Codigo_clientes = numeros.Codigo_clientes + 1
    Label1.Caption = numeros.Codigo_clientes
    'GUARDAMOS EL CODIGO DE LA NUEVA FACTURA
   Open App.Path & "\clientes\tabla.txt" For Random As intFile
    Put #intFile, , numeros
    Close #intFile
    Label2.Caption = Space(10) & "Cliente:"
    
End Sub

Private Sub Command2_Click()
'Guardar Cliente
Open App.Path & "\clientes\" & Text2.Text For Random As #1 Len = Len(forma)
forma.nombre = Text2.Text
forma.direccion = Text3.Text
forma.poblacion = Text4.Text
forma.telefono = Text5.Text
forma.nif = Text6.Text
forma.correo = Text7.Text
Put #1, LOF(1) / Len(forma) + 1, forma
List1.AddItem forma.nombre
Close #1
End Sub

Private Sub Command3_Click()
Dim n As Integer
Dim fencontrada As Boolean
Dim gh As String
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
List1.Clear
gh = App.Path & "\clientes" & "\" & Text1.Text
Open gh For Random As #1 Len = Len(forma)
For n = 1 To LOF(1) / Len(forma)
Get #1, n, forma
 fencontrada = True
 List1.AddItem forma.nombre
 Text2.Text = forma.nombre
 Text3.Text = forma.poblacion
 Text4.Text = forma.direccion
 Text5.Text = forma.telefono
 Text6.Text = forma.nif
 Text7.Text = forma.correo
Next n
Close #1

If Not fencontrada Then
    MsgBox "El Cliente no existe.", vbCritical, "ERROR."
    Kill gh
End If
End Sub

Private Sub Command6_Click()
'salir del programa
End
End Sub

Private Sub Form_Load()
Dim n As Integer
Dim gh As String
If Dir(App.Path & "\clientes", vbDirectory) = "" Then
If MsgBox("OK Directorio ¡Clientes! Creado.", vbOKCancel) = vbOK Then
MkDir (App.Path & "\clientes")
Else
MsgBox " Directorio ¡Clientes! no Creado."
Exit Sub
End If
End If
Dim intFile As Integer
intFile = FreeFile

Open App.Path & "\clientes\tabla.txt" For Random As intFile
    Get #intFile, , numeros
    Close #intFile
 Label1.Caption = numeros.Codigo_clientes
 List1.Clear
' aqui es donde no me lee todos los archivos de golpe en el list1
gh = App.Path & "\clientes\" & ".txt"
Open gh For Random As #1 Len = Len(forma)
While Not EOF(1)
Get #1, , forma
 List1.AddItem forma.nombre
Wend
Close #1

 
 

End Sub
 
No sé si esto en vb6 funcionará, en .net funciona bien:

PHP:
Private Sub ListarNombreArchivos()
        Dim indice As Integer
        For Each foundFile As String In My.Computer.FileSystem.GetFiles("C:\\Lista")

            indice = foundFile.IndexOf("\")
            While indice > 0
                foundFile = foundFile.Substring(indice + 1, foundFile.Length - (indice + 1))
                indice = foundFile.IndexOf("\")
            End While

            indice = foundFile.IndexOf(".")
            foundFile = foundFile.Substring(0, indice)

            Me.ListBoxPrueba.Items.Add(foundFile)
        Next
    End Sub

Paso a paso:

PHP:
For Each foundFile As String In My.Computer.FileSystem.GetFiles("C:\\Lista")

Busca todos los archivos que se encuentran en la carpeta "c:\Lista" y cada path de cada archivo lo almacena en el string "foundFile".

PHP:
indice = foundFile.IndexOf("\")
While indice > 0
  foundFile = foundFile.Substring(indice + 1, foundFile.Length - (indice + 1))
  indice = foundFile.IndexOf("\")
End While

Quita el excedente del path, es decir si tengo "C:\Lista\Pepito.txt" => se queda con "Pepito.txt".

PHP:
indice = foundFile.IndexOf(".")
foundFile = foundFile.Substring(0, indice)

Remueve la extensión, es decir queda como "Pepito".

PHP:
Me.ListBoxPrueba.Items.Add(foundFile)

Agrega el nombre obtenido en una ListBox.

Tal vez haya una forma más simple de obtener directamente el nombre del archivo sin extensión, y evitar usar tanto substring, pero funciona.
 
Hola soy ordo
Gracias por responder
el codigo que has puesto funciona con .net
me puedes pasar el codigo vb 6.0
gracias



Hola soy ordo
tema solucionado
dejo el codigo por si alguien le interesa, gracias

Código:
Dim Ruta As String
Dim Archivo As String
 

Ruta = App.Path & "\clientes\" & "*."
Archivo = Dir(Ruta, vbArchive)
While Archivo <> ""
List1.AddItem Archivo
Archivo = Dir
Wend
 
Última edición:
Atrás
Arriba