elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado:


  Mostrar Mensajes
Páginas: 1 ... 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 [900] 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 ... 1236
8991  Programación / .NET (C#, VB.NET, ASP) / Re: [Duda] Mostrar nueva pantalla sin cambiar de Form en: 29 Mayo 2013, 11:24 am
Ya eso pensé... Pero cuando diga de editar código voy a tener que estar moviendo veintimil paneles así que no...  :silbar:

pues no los muevas uno a uno... haz un user contorl dinámico, hay algun "multi page" ya hecho en Codeproject.com

Saludos
8992  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 29 Mayo 2013, 03:30 am
Comprobar la conectividad de red

Código
  1. #Region " Is Connectivity Avaliable? function "
  2.  
  3.    ' [ Is Connectivity Avaliable? Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Is_Connectivity_Avaliable())
  9.    ' While Not Is_Connectivity_Avaliable() : Application.DoEvents() : End While
  10.  
  11.    Private Function Is_Connectivity_Avaliable()
  12.  
  13.        Dim WebSites() As String = {"Google.com", "Facebook.com", "Microsoft.com"}
  14.  
  15.        If My.Computer.Network.IsAvailable Then
  16.            For Each WebSite In WebSites
  17.                Try
  18.                    My.Computer.Network.Ping(WebSite)
  19.                    Return True ' Network connectivity is OK.
  20.                Catch : End Try
  21.            Next
  22.            Return False ' Network connectivity is down.
  23.        Else
  24.            Return False ' No network adapter is connected.
  25.        End If
  26.  
  27.    End Function
  28.  
  29. #End Region



Comprobar si un número es negativo

Código
  1. #Region " Number Is Negavite "
  2.  
  3.    ' [ Number Is Negavite? Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Number_Is_Negavite(-5)) ' Result: True
  9.    ' MsgBox(Number_Is_Negavite(5))  ' Result: False
  10.  
  11.    Private Function Number_Is_Negavite(ByVal Number As Int64) As Boolean
  12.        Return Number < 0
  13.    End Function
  14.  
  15. #End Region



Comprobar si un número es positivo

Código
  1. #Region " Number Is Positive "
  2.  
  3.    ' [ Number Is Positive? Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Number_Is_Positive(5))  ' Result: True
  9.    ' MsgBox(Number_Is_Positive(-5)) ' Result: False
  10.  
  11.    Private Function Number_Is_Positive(ByVal Number As Int64) As Boolean
  12.        Return Number > 0
  13.    End Function
  14.  
  15. #End Region



Convierte un color html a rgb

Código
  1. #Region " HTML To RGB "
  2.  
  3.    ' [ HTML To RGB Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(HTML_To_RGB("#FFFFFF"))        ' Result: 255,255,255
  9.    ' MsgBox(HTML_To_RGB("#FFFFFF", RGB.R)) ' Result: 255
  10.  
  11.    Public Enum RGB As Int16
  12.        RGB
  13.        R
  14.        G
  15.        B
  16.    End Enum
  17.  
  18.    Private Function HTML_To_RGB(ByVal HTML_Color As String, Optional ByVal R_G_B As RGB = RGB.RGB) As String
  19.        Dim Temp_Color As Color = ColorTranslator.FromHtml(HTML_Color)
  20.  
  21.        Select Case R_G_B
  22.            Case RGB.R : Return Temp_Color.R
  23.            Case RGB.G : Return Temp_Color.G
  24.            Case RGB.B : Return Temp_Color.B
  25.            Case RGB.RGB : Return (Temp_Color.R & "," & Temp_Color.G & "," & Temp_Color.B)
  26.            Case Else : Return Nothing
  27.        End Select
  28.  
  29.    End Function
  30.  
  31. #End Region



Convierte color hexadecimal a html

Código
  1. #Region " HTML To HEX "
  2.  
  3.    ' [ HTML To HEX Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(HTML_To_HEX("#FFFFFF")) ' Result: 0xFFFFFF
  9.  
  10.    Private Function HTML_To_HEX(ByVal HTML_Color As String) As String
  11.        Dim Temp_Color As Color = ColorTranslator.FromHtml(HTML_Color)
  12.        Return ("0x" & Hex(Temp_Color.R) & Hex(Temp_Color.G) & Hex(Temp_Color.B))
  13.    End Function
  14.  
  15. #End Region



color rgb a html

Código
  1. #Region " RGB To HTML "
  2.  
  3.    ' [ RGB To HTML Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(RGB_To_HTML(255, 255, 255)) ' Result: #FFFFFF
  9.    ' PictureBox1.BackColor = ColorTranslator.FromHtml(RGB_To_HTML(255, 255, 255))
  10.  
  11.    Private Function RGB_To_HTML(ByVal R As Int16, ByVal G As Int16, ByVal B As Int16) As String
  12.        Return ColorTranslator.ToHtml(Color.FromArgb(R, G, B))
  13.    End Function
  14.  
  15. #End Region



color rgb a hexadecimal

Código
  1. #Region " RGB To HEX "
  2.  
  3.    ' [ RGB To HEX Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(RGB_To_HEX(255, 255, 255)) ' Result: 0xFFFFFF
  9.  
  10.    Private Function RGB_To_HEX(ByVal R As Int16, ByVal G As Int16, ByVal B As Int16) As String
  11.        Return ("0x" & Hex(R) & Hex(G) & Hex(B))
  12.    End Function
  13.  
  14. #End Region



color conocido a rgb

Código
  1. #Region " Color To RGB "
  2.  
  3.    ' [ Color To RGB Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Color_To_RGB(Color.White))
  9.    ' MsgBox(Color_To_RGB(Color.White, RGB.R))
  10.    ' PictureBox1.BackColor = Color.FromArgb(Color_To_RGB(Color.Red, RGB.R), Color_To_RGB(Color.Red, RGB.G), Color_To_RGB(Color.Red, RGB.B))
  11.  
  12.    Public Enum RGB As Int16
  13.        RGB
  14.        R
  15.        G
  16.        B
  17.    End Enum
  18.  
  19.    Private Function Color_To_RGB(ByVal Color As Color, Optional ByVal R_G_B As RGB = RGB.RGB) As String
  20.  
  21.        Select Case R_G_B
  22.            Case RGB.R : Return Color.R
  23.            Case RGB.G : Return Color.G
  24.            Case RGB.B : Return Color.B
  25.            Case RGB.RGB : Return (Color.R & "," & Color.G & "," & Color.B)
  26.            Case Else : Return Nothing
  27.        End Select
  28.  
  29.    End Function
  30.  
  31. #End Region



color conocido a html

Código
  1. #Region " Color To HTML "
  2.  
  3.    ' [ Color To HTML Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Color_To_HTML(Color.White))
  9.    ' PictureBox1.BackColor = ColorTranslator.FromHtml(Color_To_HTML(Color.White))
  10.  
  11.    Private Function Color_To_HTML(ByVal Color As Color) As String
  12.        Return ColorTranslator.ToHtml(Color.FromArgb(Color.R, Color.G, Color.B))
  13.    End Function
  14.  
  15. #End Region



color conocido a hexadecimal

Código
  1. #Region " Color To Hex "
  2.  
  3.    ' [ Color To Hex Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Color_To_Hex(Color.White))
  9.  
  10.    Private Function Color_To_Hex(ByVal Color As Color) As String
  11.        Return ("0x" & Hex(Color.R) & Hex(Color.G) & Hex(Color.B))
  12.    End Function
  13.  
  14. #End Region



Guardar configuración en archivo INI

Código
  1.       ' By Elektro H@cker
  2.       '
  3.       ' Example content of Test.ini:
  4.       '
  5.       ' File=C:\File.txt
  6.       ' SaveFile=True
  7.  
  8.       Dim INI_File As String = ".\Test.ini"
  9.  
  10.    ' Save INI Settings
  11.    Private Sub Save_INI_Settings()
  12.  
  13.        Dim Current_Settings As String = _
  14.            "File=" & TextBox_file.Text & Environment.NewLine & _
  15.            "SaveFile=" & CheckBox_SaveFile.Checked
  16.  
  17.        My.Computer.FileSystem.WriteAllText(INI_File, Current_Settings, False)
  18.  
  19.    End Sub



Descargar imágen web

Código
  1. #Region " Get Url Image Function "
  2.  
  3.    ' [ Get Url Image Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    '
  9.    ' PictureBox1.Image = Get_URL_Image("http://www.google.com/recaptcha/static/images/smallCaptchaSpaceWithRoughAlpha.png")
  10.  
  11.    Public Function Get_URL_Image(ByVal URL As String) As System.Drawing.Bitmap
  12.        Try
  13.            Return New System.Drawing.Bitmap(New IO.MemoryStream(New System.Net.WebClient().DownloadData(URL)))
  14.        Catch ex As Exception
  15.          MsgBox(ex.Message)
  16.          Return Nothing
  17.        End Try
  18.    End Function
  19.  
  20. #End Region



Cargar configuración desde archivo INI
(Este snippet es una versión mejorada del otro que posteé)

Código
  1.       ' By Elektro H@cker
  2.       '
  3.       ' Example content of Test.ini:
  4.       '
  5.       ' File=C:\File.txt
  6.       ' SaveFile=True
  7.  
  8.       Dim INI_File As String = ".\Test.ini"
  9.  
  10.       ' Load INI Settings
  11.       Private Sub Load_INI_Settings()
  12.  
  13.           Dim xRead As IO.StreamReader = IO.File.OpenText(INI_File)
  14.           Dim Line As String = String.Empty
  15.           Dim Delimiter As String = "="
  16.           Dim ValueName As String = String.Empty
  17.           Dim Value As Object
  18.  
  19.           Do Until xRead.EndOfStream
  20.  
  21.               Line = xRead.ReadLine().ToLower
  22.               ValueName = Line.Split(Delimiter).First
  23.               Value = Line.Split(Delimiter).Last
  24.  
  25.               Select Case ValueName.ToLower
  26.                   Case "File".ToLower : TextBox_File.Text = Value
  27.                   Case "SaveFile".ToLower : CheckBox_SaveFile.Checked()
  28.               End Select
  29.  
  30.               Application.DoEvents()
  31.  
  32.           Loop
  33.  
  34.           xRead.Close() : xRead.Dispose()
  35.  
  36.       End Sub



Obtener respuesta http

Código
  1. #Region " Get Http Response "
  2.  
  3.    ' [ Validate URL Function ]
  4.    '
  5.    ' Examples :
  6.    '
  7.    ' Dim Response As System.Net.HttpWebResponse = Get_Http_Response(System.Net.HttpWebRequest.Create("http://www.google.com/StatusCode404"))
  8.    ' If Response.StatusCode = System.Net.HttpStatusCode.NotFound Then MsgBox("Error 404")
  9.  
  10.    Public Shared Function Get_Http_Response(request As System.Net.HttpWebRequest) As System.Net.HttpWebResponse
  11.        Try : Return DirectCast(request.GetResponse(), System.Net.HttpWebResponse)
  12.        Catch ex As System.Net.WebException
  13.            If ex.Response Is Nothing OrElse ex.Status <> System.Net.WebExceptionStatus.ProtocolError Then Throw
  14.            Return DirectCast(ex.Response, System.Net.HttpWebResponse)
  15.        End Try
  16.    End Function
  17.  
  18. #End Region
8993  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 29 Mayo 2013, 03:23 am
Unos snippets especiálmente para un RichTextBox:

Devuelve la posición actual del cursor.

Código
  1. #Region " Get RichTextBox Cursor Position "
  2.  
  3.    ' [ Get RichTextBox Cursor Position Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Get_RichTextBox_Cursor_Position(RichTextBox1))
  9.    ' RichTextBox1.SelectionStart = (Get_RichTextBox_Cursor_Position(RichTextBox1) + 1) : RichTextBox1.Focus()
  10.  
  11.    Public Function Get_RichTextBox_Cursor_Position(ByVal RichTextBox_Object As RichTextBox) As Int64
  12.        Return RichTextBox_Object.SelectionStart
  13.    End Function
  14.  
  15. #End Region



Copia todo el texto del RichTextBox al portapapeles

Código
  1. #Region " Copy All RichTextBox Text "
  2.  
  3.    ' [ Copy All RichTextBox Text Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' Copy_All_RichTextBox_Text(RichTextBox1)
  9.  
  10.    Public Sub Copy_All_RichTextBox_Text(ByVal RichTextBox_Object As RichTextBox)
  11.  
  12.        ' Save the current cursor position
  13.        Dim Caret_Position As Int64 = RichTextBox_Object.SelectionStart
  14.  
  15.        ' Save the current selected text (If any)
  16.        Dim Selected_Text_Start As Int64, Selected_Text_Length As Int64
  17.        If RichTextBox_Object.SelectionLength > 0 Then
  18.            Selected_Text_Start = RichTextBox_Object.SelectionStart
  19.            Selected_Text_Length = RichTextBox_Object.SelectionLength
  20.        End If
  21.  
  22.        RichTextBox_Object.SelectAll() ' Select all text
  23.        RichTextBox_Object.Copy() ' Copy all text
  24.        RichTextBox_Object.Select(Selected_Text_Start, Selected_Text_Length) ' Returns to the previous selected text
  25.        RichTextBox_Object.SelectionStart = Caret_Position ' Returns to the previous cursor position
  26.        ' RichTextBox_Object.Focus() ' Focus again the richtextbox
  27.  
  28.    End Sub
  29.  
  30. #End Region



Desactiva un menú contextual si el RichTextBox no contiene texto, activa el menú si el RichTextBox contiene texto.

Código
  1. #Region " Toggle RichTextBox Menu "
  2.  
  3.    ' [ Toggle RichTextBox Menu ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged
  9.    '     Toogle_RichTextBox_Menu(sender, ContextMenuStrip1)
  10.    ' End Sub
  11.  
  12.    Private Sub Toggle_RichTextBox_Menu(ByVal RichTextBox As RichTextBox, ByVal ContextMenuStrip As ContextMenuStrip)
  13.        If RichTextBox.Lines.Count > 0 Then
  14.            ContextMenuStrip.Enabled = True
  15.        Else
  16.            ContextMenuStrip.Enabled = False
  17.        End If
  18.    End Sub
  19.  
  20. #End Region



Seleccionar líneas enteras

Código
  1.     ' RichTextBox [ MouseDown ]
  2.    Private Sub RichTextBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles RichTextBox1.MouseDown
  3.  
  4.        Try
  5.            Dim line = sender.GetLineFromCharIndex(sender.GetCharIndexFromPosition(e.Location))
  6.            Dim lineStart = sender.GetFirstCharIndexFromLine(line)
  7.            Dim lineEnd = sender.GetFirstCharIndexFromLine(line + 1) - 1
  8.            sender.SelectionStart = lineStart
  9.  
  10.            If (lineEnd - lineStart) > 0 Then
  11.                sender.SelectionLength = lineEnd - lineStart
  12.            Else
  13.                sender.SelectionLength = lineStart - lineEnd ' Reverse the values because is the last line of RichTextBox
  14.            End If
  15.  
  16.        Catch ex As Exception : MsgBox(ex.Message)
  17.        End Try
  18.  
  19.    End Sub



Abrir links en el navegador

Código
  1.    ' RichTextBox [ LinkClicked ]
  2.    Private Sub RichTextBox1_LinkClicked(sender As Object, e As LinkClickedEventArgs) Handles RichTextBox1.LinkClicked
  3.        Process.Start(e.LinkText)
  4.    End Sub
8994  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 29 Mayo 2013, 03:07 am
Elimina un Item de un Array

Código
  1. #Region " Remove Item From Array "
  2.  
  3.    ' [ Remove Item From Array ]
  4.    '
  5.    ' Examples :
  6.    ' Dim MyArray() As String = {"Elektro", "H@cker", "Christian"}
  7.    ' Remove_Item_From_Array(MyArray, 0)               ' Remove first element => {"H@cker", "Christian"}
  8.    ' Remove_Item_From_Array(MyArray, UBound(MyArray)) ' Remove last element => {"Elektro", "H@cker"}
  9.  
  10.    Public Sub Remove_Item_From_Array(Of T)(ByRef Array_Name() As T, ByVal Index As Integer)
  11.        Array.Copy(Array_Name, Index + 1, Array_Name, Index, UBound(Array_Name) - Index)
  12.        ReDim Preserve Array_Name(UBound(Array_Name) - 1)
  13.    End Sub
  14.  
  15. #End Region



Concatena un array, con opción de enumerarlo...

Código
  1. #Region " Join Array "
  2.  
  3.    ' [ Join Array Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' Dim MyArray() As String = {"Hola", "que", "ase?"}
  9.    ' MsgBox(Join_Array(MyArray, vbNewLine))
  10.    ' MsgBox(Join_Array(MyArray, vbNewLine, True))
  11.  
  12.    Private Function Join_Array(ByRef Array_Name As Array, ByVal Separator As String, _
  13.                                Optional ByVal Enumerate As Boolean = False) As String
  14.  
  15.        Try
  16.            If Enumerate Then
  17.                Dim Index As Int64 = 0
  18.                Dim Joined_str As String = String.Empty
  19.  
  20.                For Each Item In Array_Name
  21.                    Joined_str += Index & ". " & Item & Separator
  22.                    Index += 1
  23.                Next
  24.  
  25.                Return Joined_str
  26.            Else
  27.                Return String.Join(Separator, Array_Name)
  28.            End If
  29.  
  30.        Catch ex As Exception
  31.            MsgBox(ex.Message)
  32.            Return Nothing
  33.        End Try
  34.  
  35.    End Function
  36.  
  37. #End Region



Revierte el contenido de un texto

Código
  1. #Region " Reverse TextFile "
  2.  
  3.    ' [ Reverse TextFile ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' Reverse_TextFile("C:\File.txt")
  9.  
  10.    Private Sub Reverse_TextFile(ByVal File As String)
  11.  
  12.        Try
  13.  
  14.            Dim strArray() As String = IO.File.ReadAllLines(File)
  15.            Array.Reverse(strArray)
  16.  
  17.            Using WriteFile As New IO.StreamWriter(File, False, System.Text.Encoding.Default)
  18.                WriteFile.WriteLine(String.Join(vbNewLine, strArray))
  19.            End Using
  20.  
  21.        Catch ex As Exception
  22.            MsgBox(ex.Message)
  23.        End Try
  24.  
  25.    End Sub
  26.  
  27. #End Region



Elimina una línea de un texto

Código
  1. #Region " Delete Line From TextFile "
  2.  
  3.    ' [ Delete Line From TextFile Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' Delete_Line_From_TextFile("C:\File.txt", 3)
  9.    ' Delete_Line_From_TextFile("C:\File.txt", 3, True)
  10.  
  11.    Private Sub Delete_Line_From_TextFile(ByVal File As String, ByVal Line_Number As Int64, _
  12.                                          Optional ByVal Make_Empty_Line As Boolean = False)
  13.  
  14.        Dim Line_Length As Int64 = 0
  15.        Line_Number -= 1
  16.  
  17.        Try
  18.            Line_Length = IO.File.ReadAllLines(File).Length
  19.        Catch ex As Exception
  20.            MsgBox(ex.Message)
  21.            Exit Sub
  22.        End Try
  23.  
  24.        Select Case Line_Number
  25.  
  26.            Case Is <= (0 Or 1), Is > Line_Length
  27.  
  28.                MsgBox("Want to cut first " & (Line_Number - 1) & " lines" & vbNewLine & _
  29.                       "But """ & File & """ have " & Line_Length & " lines.")
  30.                Exit Sub
  31.  
  32.            Case Else
  33.  
  34.                Dim strArray() As String = IO.File.ReadAllLines(File)
  35.  
  36.                If Make_Empty_Line Then
  37.                    Array.Copy(strArray, Line_Number + 1, strArray, Line_Number, UBound(strArray) - Line_Number)
  38.                    ReDim Preserve strArray(UBound(strArray) - 1)
  39.                End If
  40.  
  41.                MsgBox(String.Join(vbNewLine, strArray))
  42.  
  43.                Using WriteFile As New IO.StreamWriter(File, False, System.Text.Encoding.Default)
  44.                    WriteFile.WriteLine(String.Join(vbNewLine, strArray))
  45.                End Using
  46.  
  47.        End Select
  48.  
  49.    End Sub
  50.  
  51. #End Region



Elimina las primeras X líneas de un archivo de texto

Código
  1. #Region " Cut First Lines From TextFile "
  2.  
  3.    ' [ Cut First Lines From TextFile Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' Cut_First_Lines_From_TextFile("C:\File.txt", 3)
  9.  
  10.    Private Sub Cut_First_Lines_From_TextFile(ByVal File As String, ByVal Lines As Int64)
  11.  
  12.        Dim Line_Length As Int64 = 0
  13.        Lines += 1
  14.  
  15.        Try
  16.            Line_Length = IO.File.ReadAllLines(File).Length
  17.        Catch ex As Exception
  18.            MsgBox(ex.Message)
  19.            Exit Sub
  20.        End Try
  21.  
  22.        Select Case Lines
  23.  
  24.            Case Is <= (0 Or 1), Is > Line_Length
  25.  
  26.                MsgBox("Want to cut first " & (Lines - 1) & " lines" & vbNewLine & _
  27.                       "But """ & File & """ have " & Line_Length & " lines.")
  28.                Exit Sub
  29.  
  30.            Case Else
  31.  
  32.                Dim strArray() As String = IO.File.ReadAllLines(File)
  33.                Array.Reverse(strArray)
  34.                ReDim Preserve strArray(strArray.Length - (Lines))
  35.                Array.Reverse(strArray)
  36.  
  37.                Using WriteFile As New IO.StreamWriter(File, False, System.Text.Encoding.Default)
  38.                    WriteFile.WriteLine(String.Join(vbNewLine, strArray))
  39.                End Using
  40.  
  41.        End Select
  42.  
  43.    End Sub
  44.  
  45. #End Region



Elimina las últimas X líneas de un archivo de texto

Código
  1. #Region " Cut Last Lines From TextFile "
  2.  
  3.    ' [ Cut Last Lines From TextFile Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' Cut_Last_Lines_From_TextFile("C:\File.txt", 3)
  9.  
  10.    Private Sub Cut_Last_Lines_From_TextFile(ByVal File As String, ByVal Lines As Int64)
  11.  
  12.        Dim Line_Length As Int64 = 0
  13.        Lines += 1
  14.  
  15.        Try
  16.            Line_Length = IO.File.ReadAllLines(File).Length
  17.        Catch ex As Exception
  18.            MsgBox(ex.Message)
  19.            Exit Sub
  20.        End Try
  21.  
  22.        Select Case Lines
  23.  
  24.            Case Is <= (0 Or 1), Is > Line_Length
  25.  
  26.                MsgBox("Want to cut last " & (Lines - 1) & " lines" & vbNewLine & _
  27.                       "But """ & File & """ have " & Line_Length & " lines.")
  28.                Exit Sub
  29.  
  30.            Case Else
  31.  
  32.                Dim strArray() As String = IO.File.ReadAllLines(File)
  33.                ReDim Preserve strArray(strArray.Length - (Lines))
  34.  
  35.                Using WriteFile As New IO.StreamWriter(File, False, System.Text.Encoding.Default)
  36.                    WriteFile.WriteLine(String.Join(vbNewLine, strArray))
  37.                End Using
  38.  
  39.        End Select
  40.  
  41.    End Sub
  42.  
  43. #End Region



Guarda las primmeras X líneas y elimina el resto de líneas de un archivo de texto.

Código
  1. #Region " Keep First Lines From TextFile "
  2.  
  3.    ' [ Keep First Lines From TextFile Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' Keep_First_Lines_From_TextFile("C:\File.txt", 3)
  9.  
  10.    Private Sub Keep_First_Lines_From_TextFile(ByVal File As String, ByVal Lines As Int64)
  11.  
  12.        Dim Line_Length As Int64 = 0
  13.        Lines -= 1
  14.  
  15.        Try
  16.            Line_Length = IO.File.ReadAllLines(File).Length
  17.        Catch ex As Exception
  18.            MsgBox(ex.Message)
  19.            Exit Sub
  20.        End Try
  21.  
  22.        Select Case Lines
  23.  
  24.            Case Is < 0, Is >= Line_Length
  25.  
  26.                MsgBox("Want to keep first " & (Lines + 1) & " lines" & vbNewLine & _
  27.                       "But """ & File & """ have " & Line_Length & " lines.")
  28.                Exit Sub
  29.  
  30.            Case Else
  31.  
  32.                Dim strArray() As String = IO.File.ReadAllLines(File)
  33.                ReDim Preserve strArray(Lines)
  34.  
  35.                Using WriteFile As New IO.StreamWriter(File, False, System.Text.Encoding.Default)
  36.                    WriteFile.WriteLine(String.Join(vbNewLine, strArray))
  37.                End Using
  38.  
  39.        End Select
  40.  
  41.    End Sub
  42.  
  43. #End Region



Guarda las últimas X líneas y elimina el resto de líneas de un archivo de texto.

Código
  1. #Region " Keep Last Lines From TextFile "
  2.  
  3.    ' [ Keep Last Lines From TextFile Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' Keep_Last_Lines_From_TextFile("C:\File.txt", 3)
  9.  
  10.    Private Sub Keep_Last_Lines_From_TextFile(ByVal File As String, ByVal Lines As Int64)
  11.  
  12.        Dim Line_Length As Int64 = 0
  13.        Lines -= 1
  14.  
  15.        Try
  16.            Line_Length = IO.File.ReadAllLines(File).Length
  17.        Catch ex As Exception
  18.            MsgBox(ex.Message)
  19.            Exit Sub
  20.        End Try
  21.  
  22.        Select Case Lines
  23.  
  24.            Case Is < 0, Is >= Line_Length
  25.  
  26.                MsgBox("Want to keep last " & (Lines + 1) & " lines" & vbNewLine & _
  27.                       "But """ & File & """ have " & Line_Length & " lines.")
  28.                Exit Sub
  29.  
  30.            Case Else
  31.  
  32.                Dim strArray() As String = IO.File.ReadAllLines(File)
  33.                Array.Reverse(strArray)
  34.                ReDim Preserve strArray(Lines)
  35.                Array.Reverse(strArray)
  36.  
  37.                Using WriteFile As New IO.StreamWriter(File, False, System.Text.Encoding.Default)
  38.                    WriteFile.WriteLine(String.Join(vbNewLine, strArray))
  39.                End Using
  40.  
  41.        End Select
  42.  
  43.    End Sub
  44.  
  45. #End Region



Devuelve el el total de líneas de un archivo de texto, con opción de incluir líneas en blanco

Código
  1. #Region " Get TextFile Total Lines "
  2.  
  3.    ' [ Get TextFile Total Lines Function ]
  4.    '
  5.    ' Examples :
  6.    '
  7.    ' MsgBox(Get_TextFile_Total_Lines("C:\File.txt"))
  8.    ' MsgBox(Get_TextFile_Total_Lines("C:\File.txt", False))
  9.  
  10.    Private Function Get_TextFile_Total_Lines(ByVal File As String, _
  11.                                              Optional ByVal Include_BlankLines As Boolean = True) As Int64
  12.        Try
  13.            If Include_BlankLines Then
  14.                Return IO.File.ReadAllLines(File).Length
  15.            Else
  16.                Dim LineCount As Int64
  17.                For Each Line In IO.File.ReadAllLines(File)
  18.                    If Not Line = String.Empty Then LineCount += 1
  19.                    ' Application.DoEvents()
  20.                Next
  21.                Return LineCount
  22.            End If
  23.        Catch ex As Exception
  24.            MsgBox(ex.Message)
  25.            Return -1
  26.        End Try
  27.    End Function
  28.  
  29. #End Region
8995  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 29 Mayo 2013, 02:55 am
Descarga el código fuente de una URL al disco duro

Código
  1. #Region " Download URL SourceCode "
  2.  
  3.    ' [ Download URL SourceCode ]
  4.    '
  5.    ' Examples :
  6.    ' Download_URL_SourceCode("http://www.elhacker.net", "C:\Source.html")
  7.  
  8.    Private Sub Download_URL_SourceCode(ByVal url As String, ByVal OutputFile As String)
  9.  
  10.        Try
  11.            Using TextFile As New IO.StreamWriter(OutputFile, False, System.Text.Encoding.Default)
  12.                TextFile.WriteLine(New System.IO.StreamReader(System.Net.HttpWebRequest.Create(url).GetResponse().GetResponseStream()).ReadToEnd())
  13.            End Using
  14.  
  15.        Catch ex As Exception
  16.            MsgBox(ex.Message)
  17.        End Try
  18.  
  19.    End Sub
  20.  
  21. #End Region



Devuelve el código fuente de una URL

Código
  1. #Region " Get URL SourceCode "
  2.  
  3.    ' [ Get URL SourceCode Function ]
  4.    '
  5.    ' Examples :
  6.    ' MsgBox(Get_URL_SourceCode("http://www.google.com"))
  7.    ' Clipboard.SetText(Get_URL_SourceCode("http://www.google.com"))
  8.  
  9.    Private Function Get_URL_SourceCode(ByVal url As String, Optional ByVal OutputFile As String = Nothing) As String
  10.  
  11.        Try
  12.            Return New System.IO.StreamReader(System.Net.HttpWebRequest.Create(url).GetResponse().GetResponseStream()).ReadToEnd()
  13.        Catch ex As Exception
  14.            MsgBox(ex.Message)
  15.            Return Nothing
  16.        End Try
  17.  
  18.    End Function
  19.  
  20. #End Region




Parsear un HTML usando RegEx

Código
  1.    Private Sub Parse_HTML(ByVal TextFile As String)
  2.  
  3.        ' RegEx
  4.        Dim RegEx_Url As New System.Text.RegularExpressions.Regex("http://www.mp3crank.com.*\.html?")
  5.        Dim RegEx_Year As New System.Text.RegularExpressions.Regex("[1-2][0-9][0-9][0-9]")
  6.  
  7.        Dim Line As String = Nothing
  8.        Dim Text As New IO.StringReader(My.Computer.FileSystem.ReadAllText(TextFile))
  9.  
  10.        Do
  11.  
  12.            Line = Text.ReadLine()
  13.  
  14.            If Line Is Nothing Then
  15.  
  16.                Exit Do ' End of file
  17.  
  18.            Else
  19.  
  20.                ' Strip Year
  21.                '
  22.                ' Example:
  23.                ' <span class="year">2009</span>
  24.                '
  25.                If Line.Contains(<a><![CDATA[<span class="year">]]></a>.Value) Then
  26.                    MsgBox(RegEx_Year.Match(Line).Groups(0).ToString)
  27.                End If
  28.  
  29.                ' Strip URL
  30.                '
  31.                ' Example:
  32.                ' <div class="album"><h2><a href="http://www.mp3crank.com/echo-movement/in-the-ocean.htm"</a></h2></div>
  33.                '
  34.                If Line.Contains(<a><![CDATA[<div class="album">]]></a>.Value) Then
  35.                    MsgBox(RegEx_Url.Match(Line).Groups(0).ToString)
  36.                End If
  37.  
  38.            End If
  39.  
  40.        Loop
  41.  
  42.        Text.Close() : Text.Dispose()
  43.  
  44.    End Sub
8996  Sistemas Operativos / Windows / Re: Aumentar rango al hacer click! en: 29 Mayo 2013, 02:14 am
es posible esto?
Es una pregunta curiosa y extravagante, todo hay que decirlo... Pero NO, se hace click en un pixel, ni en más, ni en menos, es como una ley.

EDITO: PD: Los juegos están programados para hacer lo que ellos quieren que haga y reproducir los clicks como ellos quieren, no alteran "la ley", pero para aumentar "el rango" en un juego que de por sí permita ese "rango" habría que modificar el source del juego ...o algo parecido, no creo que con cheat engine se pudiese hacer el "trick".

Saludos!
8997  Programación / Desarrollo Web / ¿Cual es el tamaño máximo para un source HTML? en: 29 Mayo 2013, 01:11 am
Hola.

Esto es pura curiosidad...

Me estaba preguntando cuanto tardaría en pulir un parser para los tags de un sitio específico, y esa pregunta me ha llevado a otra un poco ridícula quizás:
¿Cuanto tardaría en parsear un html de 100 mb?, y esta pregunta me lleva a la pregunta que reálmente quiero hacer (por curiosidad):

- ¿Existe un tamaño límite especificado en el lenguaje html?

...Es decir, ¿Si un html sobrepasa X tamaño (o número de líneas) es posible que el intérprete del navegador no pueda interpretar el código?

...¿Puede existir por la inmensa Internet un html de 2 Gb por ejemplo?, sé que es un tamaño descomunal, debería contener millones de líneas escritas, pero ahí tengo esa duda xD

Saludos!
8998  Programación / .NET (C#, VB.NET, ASP) / Re: [Duda] Mostrar nueva pantalla sin cambiar de Form en: 29 Mayo 2013, 00:20 am
Usa paneles.




saludos
8999  Informática / Software / Re: Ikillnukes Launcher! :) (WIP) en: 28 Mayo 2013, 23:49 pm
Creo que eso es bastante ofensivo y discriminatorio...

Tienes razón, a veces se me va la boca sin pensar.
...Rectificado, espero que nadie más se haya molestado.

Saludos
9000  Informática / Software / Re: Ikillnukes Launcher! :) (WIP) en: 28 Mayo 2013, 23:39 pm
@Seazoux
pásame el proyecto please, que sé que dryv a echo muchas cosas ahí y a lo mejor me sale algún snippet de la class "basdeclaraciones.vb" xD (¿Era de este proyecto, no?)

Saludos de nuevo xD
Páginas: 1 ... 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 [900] 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 ... 1236
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines