BASE DATOS

02- Base de Datos Multiple con Bloc de Notas en VB.NET
 
Se trata de una pequeña aplicacion para crear y mantener multiples  Bases de Datos,  con el Bloc de Notas. Sirve como inicio para crear , con pequeñas modificaciones de codigo, unas Bases de Datos mucho mas completas, sin necesidad de recurrir a aplicaciones externas. Si teneis alguna duda dejad un comentario. 
 
CODIGO:
 
FORM1
 
Imports Microsoft.VisualBasic.FileIO
Public Class Form1
  
    Dim LONGITUD As Integer
    Dim DIRECTORIO As String = Application.StartupPath & "\CARPETA BASES DE DATOS\"
    Dim SUBCARPETAS As String
    Dim DATOS As String
    Public Sub ORDENAR_DATO1()
        SUBCARPETAS = DIRECTORIO & Label7.Text
        DATOS = SUBCARPETAS & "\" & Label7.Text & ".txt"
        ' LIMPIAMOS EL LISTBOX
        ListBox1.Items.Clear()
        ' RECORREMOS EL FICHERO CONTACTOS.txt PARA LLENAR EL LISTBOX
        Dim filename As String = DATOS
        Dim fields As String()
        Dim delimiter As String = "$"
        Using parser As New TextFieldParser(filename)
            parser.SetDelimiters(delimiter)
            While Not parser.EndOfData
                ' Read in the fields for the current line
                fields = parser.ReadFields()
                ' Add code here to use data in fields variable.
                If fields(7) = "ACTIVO" Then
                    ListBox1.Items.Add(fields(1).PadRight(LONGITUD - fields(1).Length) & fields(2).PadRight(LONGITUD - fields(2).Length) &
                                         fields(3).PadRight(LONGITUD - fields(3).Length) & fields(4).PadRight(LONGITUD - fields(4).Length) &
                                         fields(5).PadRight(LONGITUD - fields(5).Length) & fields(6).PadRight(LONGITUD - fields(6).Length))
                End If
            End While
        End Using
        'ORDENAMOS ALFABETICAMENTE EL LISTBOX
        ListBox1.Sorted = True
    End Sub
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        If TextBox7.Text = "" Or TextBox8.Text = "" Or TextBox9.Text = "" Or TextBox10.Text = "" Or TextBox11.Text = "" Or TextBox12.Text = "" Then
            MsgBox("NO HAS RELLENADO TODOS LOS CAMPOS Y NO PUEDO SABER QUE ORDEN QUIERES")
        Else
            ORDENAR_DATOS()
        End If
    End Sub
    Public Sub ORDENAR_DATOS()
        SUBCARPETAS = DIRECTORIO & Label7.Text
        DATOS = SUBCARPETAS & "\" & Label7.Text & ".txt"
        ' LIMPIAMOS EL LISTBOX
        ListBox1.Items.Clear()
        ' RECORREMOS EL FICHERO CONTACTOS.txt PARA LLENAR EL LISTBOX
        Dim filename As String = DATOS
        Dim fields As String()
        Dim delimiter As String = "$"
        Using parser As New TextFieldParser(filename)
            parser.SetDelimiters(delimiter)
            While Not parser.EndOfData
                ' Read in the fields for the current line
                fields = parser.ReadFields()
                ' Add code here to use data in fields variable.
                If fields(7) = "ACTIVO" Then
                    ListBox1.Items.Add(fields(TextBox7.Text).PadRight(LONGITUD - fields(TextBox7.Text).Length) & fields(TextBox8.Text).PadRight(LONGITUD - fields(TextBox8.Text).Length) & fields(TextBox9.Text).PadRight(LONGITUD - fields(TextBox9.Text).Length) & fields(TextBox10.Text).PadRight(LONGITUD - fields(TextBox10.Text).Length) &
                                   fields(TextBox11.Text).PadRight(LONGITUD - fields(TextBox11.Text).Length) & fields(TextBox12.Text).PadRight(LONGITUD - fields(TextBox12.Text).Length))
                End If
            End While
        End Using
        'ORDENAMOS ALFABETICAMENTE EL LISTBOX
        ListBox1.Sorted = True
    End Sub
    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        If ListBox1.SelectedIndex <> -1 Then
            Dim RESPUESTA As MsgBoxResult
            RESPUESTA = MsgBox("ESTA ACCION ELIMINARA PERMANENTEMENTE LA FILA SELECCIONADA, DESEA CONTINUAR", MsgBoxStyle.YesNo)
            If RESPUESTA = MsgBoxResult.Yes Then

                'CREAMOS UN FICHERO TEXTO INTERMEDIO
                Dim INTERMEDIO As String = SUBCARPETAS & "\" & "INTERMEDIO.txt"
                Dim NUEVO_REGISTRO As String
                ' RECORREMOS EL FICHERO CONTACTOS.txt PARA LLENAR EL LISTBOX
                Dim filename As String = DATOS
                Dim fields As String()
                Dim delimiter As String = "$"
                Using parser As New TextFieldParser(filename)
                    parser.SetDelimiters(delimiter)
                    While Not parser.EndOfData
                        ' Read in the fields for the current line
                        fields = parser.ReadFields()
                        ' Add code here to use data in fields variable.
                        If fields(7) = "ACTIVO" Then
                            If ListBox1.SelectedItem = fields(TextBox7.Text).PadRight(LONGITUD - fields(TextBox7.Text).Length) & fields(TextBox8.Text).PadRight(LONGITUD - fields(TextBox8.Text).Length) & fields(TextBox9.Text).PadRight(LONGITUD - fields(TextBox9.Text).Length) & fields(TextBox10.Text).PadRight(LONGITUD - fields(TextBox10.Text).Length) &
                                       fields(TextBox11.Text).PadRight(LONGITUD - fields(TextBox11.Text).Length) & fields(TextBox12.Text).PadRight(LONGITUD - fields(TextBox12.Text).Length) Then
                                fields(7) = "ELIMINADO"
                            End If
                            NUEVO_REGISTRO = "$" & fields(1) & "$" & fields(2) & "$" & fields(3) & "$" & fields(4) & "$" & fields(5) & "$" & fields(6) & "$" & fields(7) & "$" & fields(8) & "$" & fields(9) & "$" & fields(10) & vbCrLf
                            My.Computer.FileSystem.WriteAllText(INTERMEDIO, NUEVO_REGISTRO, True)
                        End If
                    End While
                End Using
                My.Computer.FileSystem.DeleteFile(DATOS)
                My.Computer.FileSystem.RenameFile(INTERMEDIO, Label7.Text & ".txt")
                ORDENAR_DATOS()
                MsgBox("LA FILA HA SIDO ELIMINADA")
            ElseIf RESPUESTA = MsgBoxResult.No Then
                MsgBox("ACCION CANCELADA")
            End If
        Else
            MsgBox("SELECCIONE UNA LINEA")
        End If
    End Sub
    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        If ListBox1.SelectedIndex <> -1 Then

            ' RECORREMOS EL FICHERO CONTACTOS.txt PARA LLENAR EL LISTBOX
            Dim filename As String = DATOS
            Dim fields As String()
            Dim delimiter As String = "$"
            Using parser As New TextFieldParser(filename)
                parser.SetDelimiters(delimiter)
                While Not parser.EndOfData
                    ' Read in the fields for the current line
                    fields = parser.ReadFields()
                    ' Add code here to use data in fields variable.
                    If fields(7) = "ACTIVO" Then

                        If ListBox1.SelectedItem = fields(TextBox7.Text).PadRight(LONGITUD - fields(TextBox7.Text).Length) & fields(TextBox8.Text).PadRight(LONGITUD - fields(TextBox8.Text).Length) & fields(TextBox9.Text).PadRight(LONGITUD - fields(TextBox9.Text).Length) & fields(TextBox10.Text).PadRight(LONGITUD - fields(TextBox10.Text).Length) &
                                   fields(TextBox11.Text).PadRight(LONGITUD - fields(TextBox11.Text).Length) & fields(TextBox12.Text).PadRight(LONGITUD - fields(TextBox12.Text).Length) Then
                            VER.Label1.Text = fields(1)
                            VER.Label2.Text = fields(2)
                            VER.Label3.Text = fields(3)
                            VER.Label4.Text = fields(4)
                            VER.Label5.Text = fields(5)
                            VER.Label6.Text = fields(6)
                            VER.TextBox7.Text = fields(9)
                            If fields(8) <> "NOIMAGEN" Then
                                VER.PictureBox1.Image = System.Drawing.Bitmap.FromFile(SUBCARPETAS & "\IMAGENES\" & fields(8))
                            Else
                                VER.PictureBox1.Image = System.Drawing.Bitmap.FromFile(Application.StartupPath & "\NODISPONIBLE.JPG")
                            End If
                            If fields(10) <> "NOVIDEO" Then
                                VER.Label14.Visible = False
                                VER.AxWindowsMediaPlayer1.settings.autoStart = False
                                VER.AxWindowsMediaPlayer1.URL = SUBCARPETAS & "\VIDEOS\" & fields(10)
                                VER.AxWindowsMediaPlayer1.Visible = True
                            Else
                                VER.AxWindowsMediaPlayer1.Visible = False
                                VER.Label14.Visible = True
                            End If

                            VER.Show()
                            Exit While
                        End If

                    End If
                End While
            End Using
        Else
            MsgBox("SELECCIONE UNA LINEA")
        End If
    End Sub
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        LONGITUD = CInt(ListBox1.Width / 24)
        LISTA_DE_DB.Show()
    End Sub

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        ENTRADA.Label1.Text = Label1.Text
        ENTRADA.Label2.Text = Label2.Text
        ENTRADA.Label3.Text = Label3.Text
        ENTRADA.Label4.Text = Label4.Text
        ENTRADA.Label5.Text = Label5.Text
        ENTRADA.Label6.Text = Label6.Text
        ENTRADA.Label7.Text = Label7.Text
        ENTRADA.Show()
        Me.Hide()
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        LISTA_DE_DB.Show()
    End Sub
End Class
ENTRADA

Imports Microsoft.VisualBasic.FileIO
Public Class ENTRADA
    Dim DATOS As String
    Dim CONTADOR_IMAGENES As Integer = 10000
    Dim CONTADOR_VIDEOS As Integer = 10000
    Dim REGISTRO As String
    Dim IMAGEN As String
    Dim VIDEO As String
    Dim DIRECTORIO As String = Application.StartupPath & "\CARPETA BASES DE DATOS\"
    Dim SUBCARPETAS As String
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        OpenFileDialog1.ShowDialog()
        PictureBox1.Image = System.Drawing.Bitmap.FromFile(OpenFileDialog1.FileName)
    End Sub
    Public Sub LIMPIAR_ENTRADA()
        'VACIAR TEXTBOXES DE ENTRADA DE DATOS
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        TextBox7.Text = " "
    End Sub
    Private Sub ENTRADA_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       
        TextBox7.Text = " "
        TextBox1.Focus()
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
       
        Form1.ORDENAR_DATO1()
        Form1.Show()
        Close()
    End Sub
    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        LIMPIAR_ENTRADA()
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Or TextBox6.Text = "" Then
            MsgBox("NO HAS RELLENADO TODOS LOS CAMPOS")
        Else
            SUBCARPETAS = Application.StartupPath & "\CARPETA BASES DE DATOS\" & Label7.Text

            IMAGEN = OpenFileDialog1.FileName
            VIDEO = OpenFileDialog2.FileName

            If IMAGEN <> "OpenFileDialog1" Then
                If My.Computer.FileSystem.DirectoryExists(SUBCARPETAS & "\IMAGENES\") = False Then
                    My.Computer.FileSystem.CreateDirectory(SUBCARPETAS & "\IMAGENES\")
                    My.Computer.FileSystem.WriteAllText(SUBCARPETAS & "\IMAGENES\CONTADOR IMAGENES.txt", CONTADOR_IMAGENES, False)
                End If

                CONTADOR_IMAGENES = My.Computer.FileSystem.ReadAllText(SUBCARPETAS & "\IMAGENES\CONTADOR IMAGENES.txt")
                Dim INDICE As Integer
                INDICE = IMAGEN.LastIndexOf(".")
                IMAGEN = CONTADOR_IMAGENES & IMAGEN.Substring(INDICE)
                If PictureBox1.Image IsNot Nothing Then
                    Try
                        My.Computer.FileSystem.CopyFile(OpenFileDialog1.FileName, SUBCARPETAS & "\IMAGENES\" & IMAGEN)
                        CONTADOR_IMAGENES = CONTADOR_IMAGENES + 1
                        My.Computer.FileSystem.WriteAllText(SUBCARPETAS & "\IMAGENES\CONTADOR IMAGENES.txt", CONTADOR_IMAGENES, False)
                    Catch ex As Exception
                        MsgBox(ex.Message)
                    End Try
                End If
            Else
                IMAGEN = "NOIMAGEN"
            End If
            If VIDEO <> "OpenFileDialog2" Then
                If My.Computer.FileSystem.DirectoryExists(SUBCARPETAS & "\VIDEOS\") = False Then
                    My.Computer.FileSystem.CreateDirectory(SUBCARPETAS & "\VIDEOS\")
                    My.Computer.FileSystem.WriteAllText(SUBCARPETAS & "\VIDEOS\CONTADOR VIDEOS.txt", CONTADOR_VIDEOS, False)
                End If
                CONTADOR_VIDEOS = My.Computer.FileSystem.ReadAllText(SUBCARPETAS & "\VIDEOS\CONTADOR VIDEOS.txt")
                Dim INDICE2 As Integer
                INDICE2 = VIDEO.LastIndexOf(".")
                VIDEO = CONTADOR_VIDEOS & VIDEO.Substring(INDICE2)
                If AxWindowsMediaPlayer1.URL IsNot Nothing Then
                    Try
                        My.Computer.FileSystem.CopyFile(OpenFileDialog2.FileName, SUBCARPETAS & "\VIDEOS\" & VIDEO)
                        CONTADOR_VIDEOS = CONTADOR_VIDEOS + 1
                        My.Computer.FileSystem.WriteAllText(SUBCARPETAS & "\VIDEOS\CONTADOR VIDEOS.txt", CONTADOR_VIDEOS, False)
                    Catch ex As Exception
                        MsgBox(ex.Message)
                    End Try
                End If
            Else
                VIDEO = "NOVIDEO"
            End If
            DATOS = SUBCARPETAS & "\" & Label7.Text & ".txt"

            REGISTRO = "$" & TextBox1.Text & "$" & TextBox2.Text & "$" & TextBox3.Text & "$" & TextBox4.Text & "$" & TextBox5.Text & "$" & TextBox6.Text & "$" & "ACTIVO" & "$" & IMAGEN & "$" & TextBox7.Text & "$" & VIDEO & vbCrLf
            My.Computer.FileSystem.WriteAllText(DATOS, REGISTRO, True)
            LIMPIAR_ENTRADA()
            TextBox1.Focus()
            PictureBox1.Image = Nothing
            OpenFileDialog1.FileName = "OpenFileDialog1"
            AxWindowsMediaPlayer1.URL = Nothing
            OpenFileDialog2.FileName = "OpenFileDialog2"


            MsgBox("ENTRADA GUARDADA")
        End If
    End Sub
    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        OpenFileDialog2.ShowDialog()
        AxWindowsMediaPlayer1.settings.autoStart = False
        AxWindowsMediaPlayer1.URL = OpenFileDialog2.FileName
    End Sub
   
End Class

LISTA BASE DATOS

Imports Microsoft.VisualBasic.FileIO

Public Class LISTA_DE_DB
    Dim DIRECTORIO As String = Application.StartupPath & "\CARPETA BASES DE DATOS\"
    Dim SUBCARPETAS As String
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click


        'CREA UNA NUEVA BASE DE DATOS Y ACTUALIZA EL FICHERO BASES DE DATOS.txt Y EL LISTBOX
        If TextBox7.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Or TextBox6.Text = "" Then
            MsgBox("NO HAS RELLENADO TODOS LOS CAMPOS")
        Else


            My.Computer.FileSystem.CreateDirectory(DIRECTORIO)

            My.Computer.FileSystem.WriteAllText(DIRECTORIO & "BASES DE DATOS.txt", "$" & TextBox1.Text & vbCrLf, True)
            SUBCARPETAS = DIRECTORIO & TextBox1.Text & "\"

            My.Computer.FileSystem.CreateDirectory(SUBCARPETAS)

            My.Computer.FileSystem.WriteAllText(SUBCARPETAS & "CAMPOS.txt", "$" & TextBox2.Text & "$" & TextBox3.Text & "$" & TextBox4.Text & "$" & TextBox5.Text &
                                                "$" & TextBox6.Text & "$" & TextBox7.Text & vbCrLf, False)

            ACTUALIZAR_DB()
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
            TextBox4.Text = ""
            TextBox5.Text = ""
            TextBox6.Text = ""
            TextBox7.Text = ""
            MsgBox("SE HA CREADO UNA NUEVA BASE DE DATOS")
        End If
    End Sub

    Private Sub LISTA_DE_DB_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'AL CARGAR LLENA EL LISTBOX
        ACTUALIZAR_DB()

    End Sub
    Public Sub ACTUALIZAR_DB()

        ' VACIAMOS EL LISTBOX
        ListBox1.Items.Clear()

        ' RECORREMOS EL FICHERO BASES DE DATOS.txt PARA LLENAR EL LISTBOX
        Dim filename As String = DIRECTORIO & "BASES DE DATOS.txt"
        Dim fields As String()
        Dim delimiter As String = "$"
        Using parser As New TextFieldParser(filename)
            parser.SetDelimiters(delimiter)
            While Not parser.EndOfData
                ' Read in the fields for the current line
                fields = parser.ReadFields()
                ' Add code here to use data in fields variable.

                ListBox1.Items.Add(fields(1))
            End While
        End Using
        'ORDENAMOS ALFABETICAMENTE EL LISTBOX
        ListBox1.Sorted = True
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        Dim SELECCION As String
        ' RECORREMOS EL FICHERO BASES DE DATOS.txt PARA BUSCAR LA SUBCARPETA QUE SE LLAMA IGUAL QUE EL ITEM SELECCIONADO
        Dim filename As String = DIRECTORIO & "BASES DE DATOS.txt"
        Dim fields As String()
        Dim delimiter As String = "$"
        Using parser As New TextFieldParser(filename)
            parser.SetDelimiters(delimiter)
            While Not parser.EndOfData
                ' Read in the fields for the current line
                fields = parser.ReadFields()
                ' Add code here to use data in fields variable.

                If fields(1) = ListBox1.SelectedItem Then
                    SELECCION = fields(1)
                    Form1.Label7.Text = SELECCION
                End If

            End While
        End Using
        ' RECORREMOS EL FICHERO CAMPOS PARA NOMBRAR LOS CAMPOS EN EL FORM1
        Dim filename2 As String = DIRECTORIO & SELECCION & "\CAMPOS.txt"
        Dim fields2 As String()
        Dim delimiter2 As String = "$"
        Using parser As New TextFieldParser(filename2)
            parser.SetDelimiters(delimiter2)
            While Not parser.EndOfData
                ' Read in the fields for the current line
                fields2 = parser.ReadFields()
                ' Add code here to use data in fields variable.

                Form1.Label1.Text = fields2(1)
                Form1.Label2.Text = fields2(2)
                Form1.Label3.Text = fields2(3)
                Form1.Label4.Text = fields2(4)
                Form1.Label5.Text = fields2(5)
                Form1.Label6.Text = fields2(6)

            End While
        End Using
        Form1.ORDENAR_DATO1()
        Close()
    End Sub
End Class


VER
 
Public Class VER
    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        Close()
    End Sub
    Private Sub VER_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label7.Text = Form1.Label1.Text
        Label8.Text = Form1.Label2.Text
        Label9.Text = Form1.Label3.Text
        Label10.Text = Form1.Label4.Text
        Label11.Text = Form1.Label5.Text
        Label12.Text = Form1.Label6.Text
        Label15.Text = Form1.Label7.Text
    End Sub
End Class


 
 
 
01- Base de Datos con Bloc de Notas en Visual Basic VB.NET
 
Se trata de una pequeña aplicacion para crear y mantener una Base de Datos, autogenerada, con el Bloc de Notas. Sirve como inicio para crear , con pequeñas modificaciones de codigo, una Base de Datos mucho mas completa sin necesidad de recurrir a aplicaciones externas
 
CODIGO:
 
FORM1
 
Imports System.IO
Imports Microsoft.VisualBasic.FileIO

Public Class Form1
    Public BASEDATOS1 As String = Application.StartupPath & "\BASEDATOS1.txt"
    Public BASEDATOSULTIMO As String = Application.StartupPath & "\BASEDATOSULTIMO.txt"
    Public INTERMEDIA As String = Application.StartupPath & "\INTERMEDIA.txt"
    Dim PRIMERO As String
    Dim SEGUNDO As String
    Dim TERCERO As String
    Dim ULTIMO As String

    Private Sub GUARDAR_Click(sender As Object, e As EventArgs) Handles GUARDAR.Click
        PRIMERO = TPRIMERO.Text.ToUpper + "#"
        SEGUNDO = TSEGUNDO.Text.ToUpper + "#"
        TERCERO = TTERCERO.Text.ToUpper + "#"
        ULTIMO = TULTIMO.Text.ToUpper + "#"
        My.Computer.FileSystem.WriteAllText(BASEDATOS1, PRIMERO & SEGUNDO & TERCERO & ULTIMO & vbCrLf, True)
        LIMPIARTEXTBOX()
    End Sub
    Private Sub LISTADO_Click(sender As Object, e As EventArgs) Handles LISTADO.Click
        LIMPIAR_BOTONES()
        LISTAR_PRIMER_DATO()
    End Sub
 
    Private Sub LISTARULTIMODATO_Click(sender As Object, e As EventArgs) Handles LISTARULTIMODATO.Click
        LIMPIAR_BOTONES()
        LISTAR_ULTIMO_DATO()
    End Sub
 
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
     
        Close()
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles CANCELAR.Click
        LIMPIARTEXTBOX()
    End Sub
    Public Sub LIMPIARTEXTBOX()
        TPRIMERO.Text = ""
        TSEGUNDO.Text = ""
        TTERCERO.Text = ""
        TULTIMO.Text = ""
    End Sub
    Public Sub LIMPIARLISTBOX()
        ListBox1.Items.Clear()
  
    End Sub
    Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
        ITEMSELECCIONADO.Label1.Text = ListBox1.SelectedItem
        ITEMSELECCIONADO.Show()
    End Sub
    Public Sub LISTAR_PRIMER_DATO()
        If My.Computer.FileSystem.FileExists(BASEDATOS1) = False Then
            MsgBox("FICHERO VACIO")
        Else
            LISTADO.BackColor = Color.Red
            LIMPIARLISTBOX()
            Dim readText() As String = File.ReadAllLines(BASEDATOS1)
            Dim s As String
            Array.Sort(readText)
            For Each s In readText
                s = s.Replace("#", " ")
                ListBox1.Items.Add(s)
            Next
        End If
       
    End Sub
    Public Sub LISTAR_ULTIMO_DATO()
        If My.Computer.FileSystem.FileExists(BASEDATOS1) = False Then
            MsgBox("FICHERO VACIO")
        Else
            LISTARULTIMODATO.BackColor = Color.Red
            LIMPIARLISTBOX()
            ' LEE DE BASEDATOS1 , ORDENA LAS LINEAS POR EL PRIMER CAMPO Y ESCRIBE EL RESULTADO EN INTERMEDIA
            Dim readText() As String = File.ReadAllLines(BASEDATOS1)
            Dim s As String
            Array.Sort(readText)
            For Each s In readText
                My.Computer.FileSystem.WriteAllText(INTERMEDIA, s & vbCrLf, True)
            Next
            ' LEE DE INTERMEDIA CAMBIA EL ORDEN DE LOS CAMPOS DE CADA LINEA( PONE EL ULTIMO COMO PRIMERO) Y ESCRIBE EL RESULTADO EN BASEDATOSULTIMO
            Dim fields As String()
            If My.Computer.FileSystem.FileExists(INTERMEDIA) = False Then
                My.Computer.FileSystem.WriteAllText(INTERMEDIA, "", False)
            End If
            Using parser As New TextFieldParser(INTERMEDIA)
                parser.SetDelimiters("#")
                While Not parser.EndOfData
                    fields = parser.ReadFields()
                    Dim I As Integer = 0
                    Dim RESULTADO As String
                    While I < fields.Length - 4
                        RESULTADO = fields(I + 3) & " " & fields(I) & " " & fields(I + 1) & " " & fields(I + 2) & " "
                        My.Computer.FileSystem.WriteAllText(BASEDATOSULTIMO, RESULTADO & vbCrLf, True)
                        I = I + 4
                    End While
                End While
            End Using
            My.Computer.FileSystem.DeleteFile(INTERMEDIA)
            ' LEE DE BASEDATOSULTIMO ORDENA POR EL PRIMER CAMPO Y ESCRIBE EL RESULTADO EN ULTIMA
            If My.Computer.FileSystem.FileExists(BASEDATOSULTIMO) = False Then
                My.Computer.FileSystem.WriteAllText(BASEDATOSULTIMO, "", False)
            End If
            Dim LEETEXTO() As String = File.ReadAllLines(BASEDATOSULTIMO)
            Dim LINEAS As String
            Array.Sort(LEETEXTO)
            For Each LINEAS In LEETEXTO
                ListBox1.Items.Add(LINEAS)
            Next
            My.Computer.FileSystem.DeleteFile(BASEDATOSULTIMO)
        End If
    End Sub
    Public Sub LIMPIAR_BOTONES()
        LISTADO.BackColor = Color.Black
        LISTARULTIMODATO.BackColor = Color.Black
    End Sub
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        MENU1.Show()
        Me.WindowState = FormWindowState.Minimized
    End Sub
    Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
        MENU1.Show()
        Me.WindowState = FormWindowState.Minimized
    End Sub
End Class
 
MENU
 
Public Class MENU1
   
  
    Private Sub ENTRARDATOS_Click(sender As Object, e As EventArgs) Handles ENTRARDATOS.Click
        Form1.Label1.Visible = True
        Form1.Label2.Visible = True
        Form1.Label3.Visible = True
        Form1.Label4.Visible = True
        Form1.TPRIMERO.Visible = True
        Form1.TSEGUNDO.Visible = True
        Form1.TTERCERO.Visible = True
        Form1.TULTIMO.Visible = True
        Form1.GUARDAR.Visible = True
        Form1.CANCELAR.Visible = True

        Form1.ListBox1.Visible = False
        Form1.LISTADO.Visible = False
        Form1.LISTARULTIMODATO.Visible = False
        Form1.WindowState = FormWindowState.Maximized
        Me.Close()
    End Sub
    Private Sub CONSULTAS_Click(sender As Object, e As EventArgs) Handles CONSULTAS.Click
        Form1.ListBox1.Visible = True
        Form1.LISTADO.Visible = True
        Form1.LISTARULTIMODATO.Visible = True
        Form1.Label1.Visible = False
        Form1.Label2.Visible = False
        Form1.Label3.Visible = False
        Form1.Label4.Visible = False
        Form1.TPRIMERO.Visible = False
        Form1.TSEGUNDO.Visible = False
        Form1.TTERCERO.Visible = False
        Form1.TULTIMO.Visible = False
        Form1.GUARDAR.Visible = False
        Form1.CANCELAR.Visible = False
        Form1.WindowState = FormWindowState.Maximized
        Me.Close()
    End Sub
End Class
 
 
ITEM SELECCIONADO
 
Imports Microsoft.VisualBasic.FileIO
Imports System.IO
Public Class ITEMSELECCIONADO
    Dim ELIMINADOS As String = Application.StartupPath & "\ELIMINADOS.txt"
    Private Sub ELIMINAR_Click(sender As Object, e As EventArgs) Handles ELIMINAR.Click
        If Form1.LISTADO.BackColor = Color.Red Then

            Dim fields As String()
            Using parser As New TextFieldParser(Form1.BASEDATOS1)
                parser.SetDelimiters("#")
                While Not parser.EndOfData
                    fields = parser.ReadFields()
                    Dim I As Integer = 0
                    Dim RESULTADO As String
                    While I < fields.Length - 4
                        RESULTADO = fields(I) & " " & fields(I + 1) & " " & fields(I + 2) & " " & fields(I + 3) & " "
                        If RESULTADO = Label1.Text Then
                            My.Computer.FileSystem.WriteAllText(ELIMINADOS, RESULTADO & vbCrLf, True)
                            MsgBox("EL ITEM  " & RESULTADO & "  HA SIDO ELIMINADO")
                        Else
                            My.Computer.FileSystem.WriteAllText(Form1.INTERMEDIA, fields(I) & "#" & fields(I + 1) & "#" & fields(I + 2) & "#" & fields(I + 3) & "#" & vbCrLf, True)
                        End If
                        I = I + 4
                    End While
                End While
            End Using
            If My.Computer.FileSystem.FileExists(Form1.INTERMEDIA) = False Then
                My.Computer.FileSystem.WriteAllText(Form1.INTERMEDIA, "", False)
            End If
            My.Computer.FileSystem.CopyFile(Form1.INTERMEDIA, Form1.BASEDATOS1, True)
            My.Computer.FileSystem.DeleteFile(Form1.INTERMEDIA)
            Form1.LISTAR_PRIMER_DATO()
        ElseIf Form1.LISTARULTIMODATO.BackColor = Color.Red Then
            Dim fields As String()
            Using parser As New TextFieldParser(Form1.BASEDATOS1)
                parser.SetDelimiters("#")
                While Not parser.EndOfData
                    fields = parser.ReadFields()
                    Dim I As Integer = 0
                    Dim RESULTADO As String
                    While I < fields.Length - 4
                        RESULTADO = fields(I + 3) & " " & fields(I) & " " & fields(I + 1) & " " & fields(I + 2) & " "
                        If RESULTADO = Label1.Text Then
                            My.Computer.FileSystem.WriteAllText(ELIMINADOS, RESULTADO & vbCrLf, True)
                            MsgBox("EL ITEM  " & RESULTADO & "  HA SIDO ELIMINADO")
                        Else
                            My.Computer.FileSystem.WriteAllText(Form1.INTERMEDIA, fields(I + 3) & "#" & fields(I) & "#" & fields(I + 1) & "#" & fields(I + 2) & "#" & vbCrLf, True)
                        End If
                        I = I + 4
                    End While
                End While
            End Using
            If My.Computer.FileSystem.FileExists(Form1.INTERMEDIA) = False Then
                My.Computer.FileSystem.WriteAllText(Form1.INTERMEDIA, "", False)
            End If
            My.Computer.FileSystem.CopyFile(Form1.INTERMEDIA, Form1.BASEDATOS1, True)
            My.Computer.FileSystem.DeleteFile(Form1.INTERMEDIA)
            Form1.LISTAR_ULTIMO_DATO()
        End If

        Me.Close()
    End Sub
End Class
 

4 comentarios:

  1. que tal manin oye quisiera descargar estos programitas como le hago?

    ResponderEliminar
    Respuestas
    1. Hola Antonio:

      La verdad es que tengo que organizar mejor el Blog.

      Puedes encontrar la descarga de los proyectos aquí:

      http://visualbasictutoriales.blogspot.com.es/2013/09/02-base-de-datos-multiple-con-bloc-de.html
      http://visualbasictutoriales.blogspot.com.es/2013/06/base-de-datos-con-bloc-de-notas-en.html

      Saludos.

      Eliminar
    2. hola buen dia felicidades por tus proyectos son geniales, descargue el programa de la base de datos multiple pero al ejecutarla me tira errores de carpeta no encontrada soy nuevo en esto de visual studio ojala y pudieras hacer un video tutorial paso a paso te agradezco tu esfuerzo

      Eliminar
    3. Hola Yop:
      La verdad es que hacer videotutoriales paso a paso de estos proyectos seria muy largo.
      Si me envias una captura del error que te da, igual puedo indicarte el problema.
      Mi mail es :
      vb.tutoriales.abc@gmail.com
      Saludos.

      Eliminar