Categoria: Programacion Tema: Visual Basic Titulo: Contador de palabras en visual basic
Fecha del Tema: 2012-06-17 00:07:26Esta es una pequeña aplicación de contador de palabras en visual basic que se encargara de contar: Consonantes Vocales Espacios Signos Tendremos que crear un formulario por ej. form1 <? //esto no va ïPublic Class Form1 Private Sub caja_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles caja.TextChanged vocal = 0 consonante = 0 espacio = 0 sig no = 0 longitud = Len(caja.Text) Try For index = 1 To longitud letra = LCase(Mid(caja.Text, index, 1)) If InStr("aeiouAEIOU", letra) <> 0 Then vocal = vocal + 1 ElseIf InStr("bcdfghjklmnñpqrstvwxyzABCDEFGHIJKLMNÃ?OPQRSTUVWXYZ", letra) <> 0 Then consonante = consonante + 1 ElseIf letra = " " Then espacio = espacio + 1 ElseIf InStr(".,:;/@()?Â*-[]{}Â^¨+!¡<>", letra) <> 0 Then signo = signo + 1 End If Next consonantes.Text = "Consonantes: " & consonante vocales.Text = "Vocales: " & vocal espacios.Text = "Espacios: " & espacio signos.Text = "Signos: " & signo Catch ex As Exception End Try End Sub Private Sub AbrirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AbrirToolStripMenuItem.Click OpenFileDialog1.ShowDialog() todo = "" Try FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input) Do Until EOF(1) LineaTexto = LineInput(1) todo &= LineaTexto & vbCrLf Loop Catch ex As Exception MsgBox("El fichero no existe") Finally FileClose(1) End Try caja.Text = todo End Sub Private Sub GuardarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GuardarToolStripMenuItem.Clic SaveFileDialog1.ShowDialog() Try If SaveFileDialog1.FileName <> "" Then FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output) PrintLine(1, caja.Text) FileClose() End If Catch ex As Exception MsgBox("El fichero no existe") End Try End Sub Private Sub SalirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SalirToolStripMenuItem.Click End End Sub Private Sub BorrarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BorrarToolStripMenuItem.Click caja.Text = "" todo = "" TextBox2.Text = "" TextBox1.Text = "" End Sub Private Sub buscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buscar.Click If CheckBox1.Checked Then palabra = "" igual = 0 total = 0 cnt = -1 longitud = (caja.Text.Length) palabra = TextBox1.Text For index = 0 To longitud total = caja.Text.IndexOf(palabra, index) If total <> cnt Then cnt = total If total <> -1 Then igual = igual + 1 End If End If Next TextBox2.Text = igual Else palabra = "" igual = 0 total = 0 cnt = -1 longitud = (caja.Text.Length) palabra = TextBox1.Text For index = 0 To longitud total = caja.Text.ToLower.IndexOf(palabra.ToLower, index) If total <> cnt Then cnt = total If total <> -1 Then igual = igual + 1 End If End If Next TextBox2.Text = igual End If End Sub End Class ?> //esto no va Ahora crearemos un modulo por ej. ??Module Module1 <?//esto no va Public texto As String Public letra As String Public vocal As Integer = 0 Public consonante As Integer = 0 Public espacio As Integer = 0 Public signo As Integer = 0 Public longitud As Integer Public LineaTexto As String Public todo As String Public palabra As String Public igual As Integer Public total As Integer Public cnt As Integer End Module ?>//esto no va La aplicación trata de cargar un fichero de texto y contar todo l anterior nombrado.
Esta es una pequeña aplicación de contador de palabras en visual basic que se encargara de contar: Consonantes Vocales Espacios Signos Tendremos que crear un formulario por ej. form1 <? //esto no va ïPublic Class Form1 Private Sub caja_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles caja.TextChanged vocal = 0 consonante = 0 espacio = 0 sig no = 0 longitud = Len(caja.Text) Try For index = 1 To longitud letra = LCase(Mid(caja.Text, index, 1)) If InStr("aeiouAEIOU", letra) <> 0 Then vocal = vocal + 1 ElseIf InStr("bcdfghjklmnñpqrstvwxyzABCDEFGHIJKLMNÃ?OPQRSTUVWXYZ", letra) <> 0 Then consonante = consonante + 1 ElseIf letra = " " Then espacio = espacio + 1 ElseIf InStr(".,:;/@()?Â*-[]{}Â^¨+!¡<>", letra) <> 0 Then signo = signo + 1 End If Next consonantes.Text = "Consonantes: " & consonante vocales.Text = "Vocales: " & vocal espacios.Text = "Espacios: " & espacio signos.Text = "Signos: " & signo Catch ex As Exception End Try End Sub Private Sub AbrirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AbrirToolStripMenuItem.Click OpenFileDialog1.ShowDialog() todo = "" Try FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input) Do Until EOF(1) LineaTexto = LineInput(1) todo &= LineaTexto & vbCrLf Loop Catch ex As Exception MsgBox("El fichero no existe") Finally FileClose(1) End Try caja.Text = todo End Sub Private Sub GuardarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GuardarToolStripMenuItem.Clic SaveFileDialog1.ShowDialog() Try If SaveFileDialog1.FileName <> "" Then FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output) PrintLine(1, caja.Text) FileClose() End If Catch ex As Exception MsgBox("El fichero no existe") End Try End Sub Private Sub SalirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SalirToolStripMenuItem.Click End End Sub Private Sub BorrarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BorrarToolStripMenuItem.Click caja.Text = "" todo = "" TextBox2.Text = "" TextBox1.Text = "" End Sub Private Sub buscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buscar.Click If CheckBox1.Checked Then palabra = "" igual = 0 total = 0 cnt = -1 longitud = (caja.Text.Length) palabra = TextBox1.Text For index = 0 To longitud total = caja.Text.IndexOf(palabra, index) If total <> cnt Then cnt = total If total <> -1 Then igual = igual + 1 End If End If Next TextBox2.Text = igual Else palabra = "" igual = 0 total = 0 cnt = -1 longitud = (caja.Text.Length) palabra = TextBox1.Text For index = 0 To longitud total = caja.Text.ToLower.IndexOf(palabra.ToLower, index) If total <> cnt Then cnt = total If total <> -1 Then igual = igual + 1 End If End If Next TextBox2.Text = igual End If End Sub End Class ?> //esto no va Ahora crearemos un modulo por ej. ??Module Module1 <?//esto no va Public texto As String Public letra As String Public vocal As Integer = 0 Public consonante As Integer = 0 Public espacio As Integer = 0 Public signo As Integer = 0 Public longitud As Integer Public LineaTexto As String Public todo As String Public palabra As String Public igual As Integer Public total As Integer Public cnt As Integer End Module ?>//esto no va La aplicación trata de cargar un fichero de texto y contar todo l anterior nombrado.