Anuncios Google

Visual Basic 2008 Express

Tutoriales de Programaciones

Todos los tutoriales aqui expuestos estan dirigidos a la version 2008 Express.

4.615385
Tu voto: Ninguno Votos totales: 4.6 (13 votos)

Anuncios Google

Comentarios

Opciones de visualización de comentarios

Seleccione la forma que prefiera para mostrar los comentarios y haga clic en «Guardar las opciones» para activar los cambios.

ayuda con codigo en visual basic 2010

hola buenas noches aqui les dejo mi duda con este codigo.

bueno estoy haciendo un editor de codigo porcierto lla lo e echo pero el problema esta en la sintaxis del codigo que escribo por ejp hola algunas 50 vese y el programa se buel be requete lento aqui les dejo el codigo que e echo hasta el momento.

 

Option Explicit On
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Data
Imports System.Text
Imports System.Windows.Forms
Imports System.Text.RegularExpressions
Imports System.IO
Public Class Form1
    Dim Colores(2) As Color
    Public Sub New()
        InitializeComponent()
        'Label1.Font = New Font(RichTextBox1.Font.FontFamily, RichTextBox1.Font.Size + 1.019F)
    End Sub
 
    Private Sub updateNumberLabel()
        'we get index of first visible char and number of first visible line
        Dim pos As New Point(0, 0)
        Dim firstIndex As Integer = RichTextBox1.GetCharIndexFromPosition(pos)
        Dim firstLine As Integer = RichTextBox1.GetLineFromCharIndex(firstIndex)
        'now we get index of last visible char and number of last visible line
        pos.X = ClientRectangle.Width
        pos.Y = ClientRectangle.Height
        Dim lastIndex As Integer = RichTextBox1.GetCharIndexFromPosition(pos)
        Dim lastLine As Integer = RichTextBox1.GetLineFromCharIndex(lastIndex)
        'this is point position of last visible char, we'll use its Y value for calculating numberLabel size
        pos = RichTextBox1.GetPositionFromCharIndex(lastIndex)
        'finally, renumber label 
        Label1.Text = ""
        For i As Integer = firstLine To lastLine + 1
            Label1.Text += i + 1 & "" & vbLf & ""
        Next
    End Sub
    Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
        updateNumberLabel()
        Label1.Refresh()
        ' RichTextBox1.Refresh()
        RichTextBox1.Enabled = False
        Dim Pos As Long
        Dim reg As Regex
        Dim partes As MatchCollection
        Dim selStart As Integer = RichTextBox1.SelectionStart
        Dim selLength As Integer = RichTextBox1.SelectionLength
        With RichTextBox1
            Pos = .SelectionStart
            CambiaColores(RichTextBox1)
            .SelectionStart = Pos
            .Focus()
 
            ' Buscamos todas la palabras reservadas
            reg = New Regex("(while true do |char |for |if |end |then |else |System|system)")
            partes = reg.Matches(RichTextBox1.Text)
            For i As Integer = 0 To partes.Count - 1
                RichTextBox1.SelectionStart = partes(i).Index
                RichTextBox1.SelectionLength = partes(i).Length
                RichTextBox1.SelectionColor = Color.Blue
 
            Next
            ' Buscamos todas las cadenas
            reg = New Regex("[""][^""]*[""]")
            partes = reg.Matches(RichTextBox1.Text)
            For i As Integer = 0 To partes.Count - 1
                RichTextBox1.SelectionStart = partes(i).Index
                RichTextBox1.SelectionLength = partes(i).Length
                RichTextBox1.SelectionColor = Color.Gray
 
            Next
            ' Buscamos todas la palabras reservadas
            reg = New Regex("(1|2|3|4|5|6|7|8|9|0)")
            partes = reg.Matches(RichTextBox1.Text)
            For i As Integer = 0 To partes.Count - 1
                RichTextBox1.SelectionStart = partes(i).Index
                RichTextBox1.SelectionLength = partes(i).Length
                RichTextBox1.SelectionColor = Color.Orange
 
            Next
            ' Buscamos todas las cadenas
            reg = New Regex("[(]|[)]")
            partes = reg.Matches(RichTextBox1.Text)
            For i As Integer = 0 To partes.Count - 1
                RichTextBox1.SelectionStart = partes(i).Index
                RichTextBox1.SelectionLength = partes(i).Length
                RichTextBox1.SelectionColor = Color.LightBlue
 
            Next
            ' Buscamos todas la palabras reservadas
            reg = New Regex("(screen)")
            partes = reg.Matches(RichTextBox1.Text)
            For i As Integer = 0 To partes.Count - 1
                RichTextBox1.SelectionStart = partes(i).Index
                RichTextBox1.SelectionLength = partes(i).Length
                RichTextBox1.SelectionColor = Color.Purple
 
            Next
            ' Buscamos todas la palabras reservadas
            reg = New Regex("(print|Print)")
            partes = reg.Matches(RichTextBox1.Text)
            For i As Integer = 0 To partes.Count - 1
                RichTextBox1.SelectionStart = partes(i).Index
                RichTextBox1.SelectionLength = partes(i).Length
                RichTextBox1.SelectionColor = Color.CornflowerBlue
 
            Next
            ' Buscamos todas la palabras reservadas
            reg = New Regex("(new|New)")
            partes = reg.Matches(RichTextBox1.Text)
            For i As Integer = 0 To partes.Count - 1
                RichTextBox1.SelectionStart = partes(i).Index
                RichTextBox1.SelectionLength = partes(i).Length
                RichTextBox1.SelectionColor = Color.CornflowerBlue
 
            Next
            ' Buscamos todas la palabras reservadas
            reg = New Regex("(=)")
            partes = reg.Matches(RichTextBox1.Text)
            For i As Integer = 0 To partes.Count - 1
                RichTextBox1.SelectionStart = partes(i).Index
                RichTextBox1.SelectionLength = partes(i).Length
                RichTextBox1.SelectionColor = Color.Red
 
            Next
            RichTextBox1.SelectionStart = selStart
            RichTextBox1.SelectionLength = selLength
            RichTextBox1.Enabled = True
            RichTextBox1.Focus()
        End With
    End Sub
    Sub CambiaColores(ByVal RichTextBox1 As RichTextBox)
 
        ' RichTextBox1.Enabled = False
        ' Guardamos la selecciona actual para regresar
        ' todo a su sitio cuando terminemos
        Dim selStart As Integer = RichTextBox1.SelectionStart
        Dim selLength As Integer = RichTextBox1.SelectionLength
 
        Dim F As Long
        Dim Contador As Long
        With RichTextBox1
            .Enabled = False
            For F = 1 To Len(.Text)
                If Mid$(.Text, F, 2) = "--" Then
                    Contador = Contador + 1
                    If Contador > 2 Then Contador = 2
                    .SelectionStart = F - 1
                    .SelectionLength = 1
                    .SelectionColor = Colores(Contador)
                ElseIf Mid$(.Text, F, 1) = vbLf Then
                    .SelectionStart = F - 1
                    .SelectionLength = 1
                    .SelectionColor = Colores(Contador)
                    Contador = Contador - 1
                    If Contador < 0 Then Contador = 0
                Else
                    .SelectionStart = F - 1
                    .SelectionLength = 1
                    .SelectionColor = Colores(Contador)
                End If
            Next F
        End With
 
    End Sub
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        updateNumberLabel()
        Colores(0) = Color.Black
        Colores(1) = Color.Green
        Me.Show()
    End Sub
 
    Private Sub CortarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CortarToolStripMenuItem.Click
        RichTextBox1.Cut()
    End Sub
 
    Private Sub CopiarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopiarToolStripMenuItem.Click
        RichTextBox1.Copy()
    End Sub
 
    Private Sub PegarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PegarToolStripMenuItem.Click
        RichTextBox1.Paste()
    End Sub
 
    Private Sub RichTextBox1_FontChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RichTextBox1.FontChanged
        updateNumberLabel()
        RichTextBox1_VScroll(Nothing, Nothing)
    End Sub
    Private Sub RichTextBox1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles RichTextBox1.Resize
        RichTextBox1_VScroll(Nothing, Nothing)
    End Sub
 
    Private Sub RichTextBox1_VScroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles RichTextBox1.VScroll
        'move location of numberLabel for amount of pixels caused by scrollbar
        Dim d As Integer = RichTextBox1.GetPositionFromCharIndex(0).Y Mod (RichTextBox1.Font.Height + 1)
        'Label1.Location = New Point(0, d)
        updateNumberLabel()
    End Sub
End Class

este es mi codigo y no puedo hacer que sea mucho mas rapido porfabor ayudadme es para un proyecto de na uni.


luis

Opciones de visualización de comentarios

Seleccione la forma que prefiera para mostrar los comentarios y haga clic en «Guardar las opciones» para activar los cambios.