|
9162
|
Programación / .NET (C#, VB.NET, ASP) / Re: Alguien sabe que son los indices ?
|
en: 30 Mayo 2013, 19:14 pm
|
¿ Sabéis como se le llama a esto o tenéis algún ejemplo que me pueda servir para usarlos ? Se denomina "Array de controles", pero si nos ponemos tecnicistas y nos fijamos en el detalle de usar una variable de esa forma, eso se denomina "Variables dinámicas", y bueno, lo del índice ya te lo han explicado. ...hastable ...parece que se usan para meter dentro de ellos un grupo de botones o eso creo. ¿ Estoy equivocado ?. ¿Equivocado?, pues eso depende de como se mire, más bien confuso... ...Un hastable es un "contenedor" donde puedes meter objetos de cualquier tipo, pero no es algo que exprésamente existe para meter controles "indexados", de hecho si solo quieres crear un "contenedor" con objetos de un solo tipo (Botónes) entonces te recomiendo que mejor uses un "Dictionary". El Hashtable es para meter distintos objetos sin que haya problemas (por ejemplo un objeto de un control, y aparte una variable "Integer", y otra de tipo "String"), pero si quisieras añadir un tipo de objeto, aunque puedes usar cualquiera de los dos, lo correcto sería usar la Class "Dictionary". La diferencia es que en el Dictionary tienes que definir el tipo de objeto y valor, y en el hashtable no, lo puedes meter todo sin preocupaciones, así que si no tienes cuidado con el hashtable ...la puedes liar parda. Te hago un ejemplo: Dim MyDictionary As New Dictionary(Of Integer, Boolean) MyDictionary.Add(1, True) MyDictionary.Add(2, False) MyDictionary.Add(3, Nothing) ' Set value MyDictionary.Item(1) = False ' Get Value MsgBox(MyDictionary.Item(1))
Dim MyHashtable As New Hashtable MyHashtable.Add(1, True) MyHashtable.Add(Button1, False) MyHashtable.Add("1", Nothing) ' Set value MyHashtable.Item(1) = False MyHashtable.Item("1") = True ' Get Value MsgBox(MyHashtable.Item(1)) MsgBox(MyHashtable.Item("1"))
Saludos.
|
|
|
9163
|
Programación / Desarrollo Web / Re: ¿Cual es el tamaño máximo para un source HTML?
|
en: 30 Mayo 2013, 15:57 pm
|
teóricamente no hay límite de tamaño en bajarse un fichero de internet, pues tampoco de un fichero HTML. Pues visto lo visto... me parece que deberían implementar algo en los navegadores para regular el límite de tamaños... No sé quien va a perder el tiempo subiendo a un server una página de 1 GB, imagino que habría que tener pocas neuraonas para hacer eso (digo yo, perdón si me equivoco), o algún gracioso podría hackear la página principal de un server y escribir líneas en el html a lo "troll" para que pese 1 GB y que los pobres usuarios descarguen ese archivo html temporal en su pc consumiendo espacio innecesario ...séa como séa pueden haber mil razones y habría que regularlo. Saludos!
|
|
|
9164
|
Informática / Software / Re: Ikillnukes Launcher! :) (WIP)
|
en: 30 Mayo 2013, 15:48 pm
|
@OmarHack Puedes seguir diciendo todo lo que tu quieras, pero no me cuentes historias a mi, porque tengo bastante experiencia con personas como tú. Vas un poco de defensor de la mujer y del homosexual, pero si tu respetases un poco a las demás personas por igual, entonces por simple educación esto me lo habrías comentado por privado para poder rectificarlo: Creo que eso es bastante ofensivo y discriminatorio... ...Y no lo habrías dicho en público para empezar (y seguir) una discusión sin sentido llamando la atención de los usuarios, tú puedes llamarlo "libertad de expresión" si quieres que parezca eso ...para quien se trague esa historia. La verdad por delante, las cosas como son, no me gusta el rosa, ni tampoco los trolls que se meten con alguien por decir "el rosa queda un poco gay", venga ya, porfavor, que no me he metido con nadie, basta ya chico. Ahora si, lo dejo, no comento más el tema. Salu2
|
|
|
9165
|
Informática / Software / Re: Ikillnukes Launcher! :) (WIP)
|
en: 30 Mayo 2013, 14:47 pm
|
Te he dicho que era ofensivo por si no te dieras cuenta y querías enmendarlo. No sé de que te quejas, igual que tú te has expresado libremente y has dicho que te da asco yo también me voy a expresar libremente y decirte que los comentarios como esos son lo que me dan asco a mi. ¿Me vas a decir ahora que por ser rosa un botón va a tener menos público la web? Te recuerdo que hay más mujeres que hombres en el mundo. Si aún por encima le sumas todos los gays creo que te puede dar un porcentaje de más del 70% de público al que le gusta el color rosa. Esto basándome en tu comentario en el que afirmas que el color rosa solo le guste a las mujeres y a los gays. A mi me gusta el color rosa y no soy gay ni mujer. Nadie te priva de tu libertad de expresión, pero en mi simple opinión faltas al respeto a dos colectivos como son las mujeres y los gays. Y yo haciendo uso también de mi libertad de expresión te he dado mi más sincera opinión sin faltarte al respeto ni a ti ni a nadie. Te recuerdo que el derecho a la libertad abarca hasta donde comienza la libertad de los demás. Un saludo.
@OmarHack Relájate un poco y no te des por aludido, que lo de "sensibles" no iba para ti, aunque desde luego... lo eres, chico, como te pones por un comentario sobre el rosa. Ya puedes dejar de expresar tu libre opinión trollear con el tema rosa, las mujeres, y los gays. saludos
|
|
|
9166
|
Informática / Software / Re: Ikillnukes Launcher! :) (WIP)
|
en: 29 Mayo 2013, 11:31 am
|
Ayer te iba a comentar todo lo que dijistes... Sobre lo del botón gay, un Gay te daría de palos... Pero la opinión publica te daría la razón... Es más yo te la doy... xD
Si, bueno... hay mucho sensible, siempre hay que cuidar las palabras, y yo no lo hice, pero... por otro lado... a ver si en este país al final uno no va a poder decir lo que le gusta y lo que no, o lo que me da " asquito" y lo que no, sería el colmo ya, y eso que tampoco me metí con los homosexuales, solo dije una frase hecha. Ehm cuales botones cuadrados? En un principio dijistes el Form... Ni idea... Tienes 3 botones default "on the bottom" rectangulares, grises, y el resto de botones son con bordes bastantes redondos, a eso me refería. Saludos
|
|
|
9168
|
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 #Region " Is Connectivity Avaliable? function " ' [ Is Connectivity Avaliable? Function ] ' ' // By Elektro H@cker ' ' Examples : ' MsgBox(Is_Connectivity_Avaliable()) ' While Not Is_Connectivity_Avaliable() : Application.DoEvents() : End While Private Function Is_Connectivity_Avaliable() Dim WebSites() As String = {"Google.com", "Facebook.com", "Microsoft.com"} If My.Computer.Network.IsAvailable Then For Each WebSite In WebSites Try My.Computer.Network.Ping(WebSite) Return True ' Network connectivity is OK. Catch : End Try Next Return False ' Network connectivity is down. Else Return False ' No network adapter is connected. End If End Function #End Region
Comprobar si un número es negativo #Region " Number Is Negavite " ' [ Number Is Negavite? Function ] ' ' // By Elektro H@cker ' ' Examples : ' MsgBox(Number_Is_Negavite(-5)) ' Result: True ' MsgBox(Number_Is_Negavite(5)) ' Result: False Private Function Number_Is_Negavite(ByVal Number As Int64) As Boolean Return Number < 0 End Function #End Region
Comprobar si un número es positivo #Region " Number Is Positive " ' [ Number Is Positive? Function ] ' ' // By Elektro H@cker ' ' Examples : ' MsgBox(Number_Is_Positive(5)) ' Result: True ' MsgBox(Number_Is_Positive(-5)) ' Result: False Private Function Number_Is_Positive(ByVal Number As Int64) As Boolean Return Number > 0 End Function #End Region
Convierte un color html a rgb #Region " HTML To RGB " ' [ HTML To RGB Function ] ' ' // By Elektro H@cker ' ' Examples : ' MsgBox(HTML_To_RGB("#FFFFFF")) ' Result: 255,255,255 ' MsgBox(HTML_To_RGB("#FFFFFF", RGB.R)) ' Result: 255 Public Enum RGB As Int16 RGB R G B End Enum Private Function HTML_To_RGB(ByVal HTML_Color As String, Optional ByVal R_G_B As RGB = RGB.RGB) As String Dim Temp_Color As Color = ColorTranslator.FromHtml(HTML_Color) Select Case R_G_B Case RGB.R : Return Temp_Color.R Case RGB.G : Return Temp_Color.G Case RGB.B : Return Temp_Color.B Case RGB.RGB : Return (Temp_Color.R & "," & Temp_Color.G & "," & Temp_Color.B) Case Else : Return Nothing End Select End Function #End Region
Convierte color hexadecimal a html #Region " HTML To HEX " ' [ HTML To HEX Function ] ' ' // By Elektro H@cker ' ' Examples : ' MsgBox(HTML_To_HEX("#FFFFFF")) ' Result: 0xFFFFFF Private Function HTML_To_HEX(ByVal HTML_Color As String) As String Dim Temp_Color As Color = ColorTranslator.FromHtml(HTML_Color) Return ("0x" & Hex(Temp_Color.R) & Hex(Temp_Color.G) & Hex(Temp_Color.B)) End Function #End Region
color rgb a html #Region " RGB To HTML " ' [ RGB To HTML Function ] ' ' // By Elektro H@cker ' ' Examples : ' MsgBox(RGB_To_HTML(255, 255, 255)) ' Result: #FFFFFF ' PictureBox1.BackColor = ColorTranslator.FromHtml(RGB_To_HTML(255, 255, 255)) Private Function RGB_To_HTML(ByVal R As Int16, ByVal G As Int16, ByVal B As Int16) As String Return ColorTranslator.ToHtml(Color.FromArgb(R, G, B)) End Function #End Region
color rgb a hexadecimal #Region " RGB To HEX " ' [ RGB To HEX Function ] ' ' // By Elektro H@cker ' ' Examples : ' MsgBox(RGB_To_HEX(255, 255, 255)) ' Result: 0xFFFFFF Private Function RGB_To_HEX(ByVal R As Int16, ByVal G As Int16, ByVal B As Int16) As String Return ("0x" & Hex(R) & Hex(G) & Hex(B)) End Function #End Region
color conocido a rgb #Region " Color To RGB " ' [ Color To RGB Function ] ' ' // By Elektro H@cker ' ' Examples : ' MsgBox(Color_To_RGB(Color.White)) ' MsgBox(Color_To_RGB(Color.White, RGB.R)) ' 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)) Public Enum RGB As Int16 RGB R G B End Enum Private Function Color_To_RGB(ByVal Color As Color, Optional ByVal R_G_B As RGB = RGB.RGB) As String Select Case R_G_B Case RGB.R : Return Color.R Case RGB.G : Return Color.G Case RGB.B : Return Color.B Case RGB.RGB : Return (Color.R & "," & Color.G & "," & Color.B) Case Else : Return Nothing End Select End Function #End Region
color conocido a html #Region " Color To HTML " ' [ Color To HTML Function ] ' ' // By Elektro H@cker ' ' Examples : ' MsgBox(Color_To_HTML(Color.White)) ' PictureBox1.BackColor = ColorTranslator.FromHtml(Color_To_HTML(Color.White)) Private Function Color_To_HTML(ByVal Color As Color) As String Return ColorTranslator.ToHtml(Color.FromArgb(Color.R, Color.G, Color.B)) End Function #End Region
color conocido a hexadecimal #Region " Color To Hex " ' [ Color To Hex Function ] ' ' // By Elektro H@cker ' ' Examples : ' MsgBox(Color_To_Hex(Color.White)) Private Function Color_To_Hex(ByVal Color As Color) As String Return ("0x" & Hex(Color.R) & Hex(Color.G) & Hex(Color.B)) End Function #End Region
Guardar configuración en archivo INI ' By Elektro H@cker ' ' Example content of Test.ini: ' ' File=C:\File.txt ' SaveFile=True Dim INI_File As String = ".\Test.ini" ' Save INI Settings Private Sub Save_INI_Settings() Dim Current_Settings As String = _ "File=" & TextBox_file.Text & Environment.NewLine & _ "SaveFile=" & CheckBox_SaveFile.Checked My.Computer.FileSystem.WriteAllText(INI_File, Current_Settings, False) End Sub
Descargar imágen web #Region " Get Url Image Function " ' [ Get Url Image Function ] ' ' // By Elektro H@cker ' ' Examples : ' ' PictureBox1.Image = Get_URL_Image("http://www.google.com/recaptcha/static/images/smallCaptchaSpaceWithRoughAlpha.png") Public Function Get_URL_Image(ByVal URL As String) As System.Drawing.Bitmap Try Return New System.Drawing.Bitmap(New IO.MemoryStream(New System.Net.WebClient().DownloadData(URL))) Catch ex As Exception MsgBox(ex.Message) Return Nothing End Try End Function #End Region
Cargar configuración desde archivo INI (Este snippet es una versión mejorada del otro que posteé) ' By Elektro H@cker ' ' Example content of Test.ini: ' ' File=C:\File.txt ' SaveFile=True Dim INI_File As String = ".\Test.ini" ' Load INI Settings Private Sub Load_INI_Settings() Dim xRead As IO. StreamReader = IO. File. OpenText(INI_File ) Dim Line As String = String.Empty Dim Delimiter As String = "=" Dim ValueName As String = String.Empty Dim Value As Object Do Until xRead.EndOfStream Line = xRead.ReadLine().ToLower ValueName = Line.Split(Delimiter).First Value = Line.Split(Delimiter).Last Select Case ValueName.ToLower Case "File".ToLower : TextBox_File.Text = Value Case "SaveFile".ToLower : CheckBox_SaveFile.Checked() End Select Application.DoEvents() Loop xRead.Close() : xRead.Dispose() End Sub
Obtener respuesta http #Region " Get Http Response " ' [ Validate URL Function ] ' ' Examples : ' ' Dim Response As System.Net.HttpWebResponse = Get_Http_Response(System.Net.HttpWebRequest.Create("http://www.google.com/StatusCode404")) ' If Response.StatusCode = System.Net.HttpStatusCode.NotFound Then MsgBox("Error 404") Public Shared Function Get_Http_Response(request As System.Net.HttpWebRequest) As System.Net.HttpWebResponse Try : Return DirectCast(request.GetResponse(), System.Net.HttpWebResponse) Catch ex As System.Net.WebException If ex.Response Is Nothing OrElse ex.Status <> System.Net.WebExceptionStatus.ProtocolError Then Throw Return DirectCast(ex.Response, System.Net.HttpWebResponse) End Try End Function #End Region
|
|
|
9169
|
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. #Region " Get RichTextBox Cursor Position " ' [ Get RichTextBox Cursor Position Function ] ' ' // By Elektro H@cker ' ' Examples : ' MsgBox(Get_RichTextBox_Cursor_Position(RichTextBox1)) ' RichTextBox1.SelectionStart = (Get_RichTextBox_Cursor_Position(RichTextBox1) + 1) : RichTextBox1.Focus() Public Function Get_RichTextBox_Cursor_Position(ByVal RichTextBox_Object As RichTextBox) As Int64 Return RichTextBox_Object.SelectionStart End Function #End Region
Copia todo el texto del RichTextBox al portapapeles #Region " Copy All RichTextBox Text " ' [ Copy All RichTextBox Text Function ] ' ' // By Elektro H@cker ' ' Examples : ' Copy_All_RichTextBox_Text(RichTextBox1) Public Sub Copy_All_RichTextBox_Text(ByVal RichTextBox_Object As RichTextBox) ' Save the current cursor position Dim Caret_Position As Int64 = RichTextBox_Object.SelectionStart ' Save the current selected text (If any) Dim Selected_Text_Start As Int64, Selected_Text_Length As Int64 If RichTextBox_Object.SelectionLength > 0 Then Selected_Text_Start = RichTextBox_Object.SelectionStart Selected_Text_Length = RichTextBox_Object.SelectionLength End If RichTextBox_Object.SelectAll() ' Select all text RichTextBox_Object.Copy() ' Copy all text RichTextBox_Object.Select(Selected_Text_Start, Selected_Text_Length) ' Returns to the previous selected text RichTextBox_Object.SelectionStart = Caret_Position ' Returns to the previous cursor position ' RichTextBox_Object.Focus() ' Focus again the richtextbox End Sub #End Region
Desactiva un menú contextual si el RichTextBox no contiene texto, activa el menú si el RichTextBox contiene texto. #Region " Toggle RichTextBox Menu " ' [ Toggle RichTextBox Menu ] ' ' // By Elektro H@cker ' ' Examples : ' Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged ' Toogle_RichTextBox_Menu(sender, ContextMenuStrip1) ' End Sub Private Sub Toggle_RichTextBox_Menu(ByVal RichTextBox As RichTextBox, ByVal ContextMenuStrip As ContextMenuStrip) If RichTextBox.Lines.Count > 0 Then ContextMenuStrip.Enabled = True Else ContextMenuStrip.Enabled = False End If End Sub #End Region
Seleccionar líneas enteras ' RichTextBox [ MouseDown ] Private Sub RichTextBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles RichTextBox1.MouseDown Try Dim line = sender.GetLineFromCharIndex(sender.GetCharIndexFromPosition(e.Location)) Dim lineStart = sender.GetFirstCharIndexFromLine(line) Dim lineEnd = sender.GetFirstCharIndexFromLine(line + 1) - 1 sender.SelectionStart = lineStart If (lineEnd - lineStart) > 0 Then sender.SelectionLength = lineEnd - lineStart Else sender.SelectionLength = lineStart - lineEnd ' Reverse the values because is the last line of RichTextBox End If Catch ex As Exception : MsgBox(ex.Message) End Try End Sub
Abrir links en el navegador ' RichTextBox [ LinkClicked ] Private Sub RichTextBox1_LinkClicked(sender As Object, e As LinkClickedEventArgs) Handles RichTextBox1.LinkClicked Process.Start(e.LinkText) End Sub
|
|
|
9170
|
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 #Region " Remove Item From Array " ' [ Remove Item From Array ] ' ' Examples : ' Dim MyArray() As String = {"Elektro", "H@cker", "Christian"} ' Remove_Item_From_Array(MyArray, 0) ' Remove first element => {"H@cker", "Christian"} ' Remove_Item_From_Array(MyArray, UBound(MyArray)) ' Remove last element => {"Elektro", "H@cker"} Public Sub Remove_Item_From_Array(Of T)(ByRef Array_Name() As T, ByVal Index As Integer) Array.Copy(Array_Name, Index + 1, Array_Name, Index, UBound(Array_Name) - Index) ReDim Preserve Array_Name(UBound(Array_Name) - 1) End Sub #End Region
Concatena un array, con opción de enumerarlo... #Region " Join Array " ' [ Join Array Function ] ' ' // By Elektro H@cker ' ' Examples : ' Dim MyArray() As String = {"Hola", "que", "ase?"} ' MsgBox(Join_Array(MyArray, vbNewLine)) ' MsgBox(Join_Array(MyArray, vbNewLine, True)) Private Function Join_Array(ByRef Array_Name As Array, ByVal Separator As String, _ Optional ByVal Enumerate As Boolean = False) As String Try If Enumerate Then Dim Index As Int64 = 0 Dim Joined_str As String = String.Empty For Each Item In Array_Name Joined_str += Index & ". " & Item & Separator Index += 1 Next Return Joined_str Else Return String.Join(Separator, Array_Name) End If Catch ex As Exception MsgBox(ex.Message) Return Nothing End Try End Function #End Region
Revierte el contenido de un texto #Region " Reverse TextFile " ' [ Reverse TextFile ] ' ' // By Elektro H@cker ' ' Examples : ' Reverse_TextFile("C:\File.txt") Private Sub Reverse_TextFile (ByVal File As String) Try Dim strArray () As String = IO. File. ReadAllLines(File) Array.Reverse(strArray) Using WriteFile As New IO. StreamWriter(File, False, System. Text. Encoding. Default) WriteFile.WriteLine(String.Join(vbNewLine, strArray)) End Using Catch ex As Exception MsgBox(ex.Message) End Try End Sub #End Region
Elimina una línea de un texto #Region " Delete Line From TextFile " ' [ Delete Line From TextFile Function ] ' ' // By Elektro H@cker ' ' Examples : ' Delete_Line_From_TextFile("C:\File.txt", 3) ' Delete_Line_From_TextFile("C:\File.txt", 3, True) Private Sub Delete_Line_From_TextFile (ByVal File As String, ByVal Line_Number As Int64, _ Optional ByVal Make_Empty_Line As Boolean = False) Dim Line_Length As Int64 = 0 Line_Number -= 1 Try Line_Length = IO. File. ReadAllLines(File). Length Catch ex As Exception MsgBox(ex.Message) Exit Sub End Try Select Case Line_Number Case Is <= (0 Or 1), Is > Line_Length MsgBox("Want to cut first " & (Line_Number - 1) & " lines" & vbNewLine & _ "But """ & File & """ have " & Line_Length & " lines.") Exit Sub Case Else Dim strArray () As String = IO. File. ReadAllLines(File) If Make_Empty_Line Then Array.Copy(strArray, Line_Number + 1, strArray, Line_Number, UBound(strArray) - Line_Number) ReDim Preserve strArray(UBound(strArray) - 1) End If MsgBox(String.Join(vbNewLine, strArray)) Using WriteFile As New IO. StreamWriter(File, False, System. Text. Encoding. Default) WriteFile.WriteLine(String.Join(vbNewLine, strArray)) End Using End Select End Sub #End Region
Elimina las primeras X líneas de un archivo de texto #Region " Cut First Lines From TextFile " ' [ Cut First Lines From TextFile Function ] ' ' // By Elektro H@cker ' ' Examples : ' Cut_First_Lines_From_TextFile("C:\File.txt", 3) Private Sub Cut_First_Lines_From_TextFile (ByVal File As String, ByVal Lines As Int64 ) Dim Line_Length As Int64 = 0 Lines += 1 Try Line_Length = IO. File. ReadAllLines(File). Length Catch ex As Exception MsgBox(ex.Message) Exit Sub End Try Select Case Lines Case Is <= (0 Or 1), Is > Line_Length MsgBox("Want to cut first " & (Lines - 1) & " lines" & vbNewLine & _ "But """ & File & """ have " & Line_Length & " lines.") Exit Sub Case Else Dim strArray () As String = IO. File. ReadAllLines(File) Array.Reverse(strArray) ReDim Preserve strArray(strArray.Length - (Lines)) Array.Reverse(strArray) Using WriteFile As New IO. StreamWriter(File, False, System. Text. Encoding. Default) WriteFile.WriteLine(String.Join(vbNewLine, strArray)) End Using End Select End Sub #End Region
Elimina las últimas X líneas de un archivo de texto #Region " Cut Last Lines From TextFile " ' [ Cut Last Lines From TextFile Function ] ' ' // By Elektro H@cker ' ' Examples : ' Cut_Last_Lines_From_TextFile("C:\File.txt", 3) Private Sub Cut_Last_Lines_From_TextFile (ByVal File As String, ByVal Lines As Int64 ) Dim Line_Length As Int64 = 0 Lines += 1 Try Line_Length = IO. File. ReadAllLines(File). Length Catch ex As Exception MsgBox(ex.Message) Exit Sub End Try Select Case Lines Case Is <= (0 Or 1), Is > Line_Length MsgBox("Want to cut last " & (Lines - 1) & " lines" & vbNewLine & _ "But """ & File & """ have " & Line_Length & " lines.") Exit Sub Case Else Dim strArray () As String = IO. File. ReadAllLines(File) ReDim Preserve strArray(strArray.Length - (Lines)) Using WriteFile As New IO. StreamWriter(File, False, System. Text. Encoding. Default) WriteFile.WriteLine(String.Join(vbNewLine, strArray)) End Using End Select End Sub #End Region
Guarda las primmeras X líneas y elimina el resto de líneas de un archivo de texto. #Region " Keep First Lines From TextFile " ' [ Keep First Lines From TextFile Function ] ' ' // By Elektro H@cker ' ' Examples : ' Keep_First_Lines_From_TextFile("C:\File.txt", 3) Private Sub Keep_First_Lines_From_TextFile (ByVal File As String, ByVal Lines As Int64 ) Dim Line_Length As Int64 = 0 Lines -= 1 Try Line_Length = IO. File. ReadAllLines(File). Length Catch ex As Exception MsgBox(ex.Message) Exit Sub End Try Select Case Lines Case Is < 0, Is >= Line_Length MsgBox("Want to keep first " & (Lines + 1) & " lines" & vbNewLine & _ "But """ & File & """ have " & Line_Length & " lines.") Exit Sub Case Else Dim strArray () As String = IO. File. ReadAllLines(File) ReDim Preserve strArray(Lines) Using WriteFile As New IO. StreamWriter(File, False, System. Text. Encoding. Default) WriteFile.WriteLine(String.Join(vbNewLine, strArray)) End Using End Select End Sub #End Region
Guarda las últimas X líneas y elimina el resto de líneas de un archivo de texto. #Region " Keep Last Lines From TextFile " ' [ Keep Last Lines From TextFile Function ] ' ' // By Elektro H@cker ' ' Examples : ' Keep_Last_Lines_From_TextFile("C:\File.txt", 3) Private Sub Keep_Last_Lines_From_TextFile (ByVal File As String, ByVal Lines As Int64 ) Dim Line_Length As Int64 = 0 Lines -= 1 Try Line_Length = IO. File. ReadAllLines(File). Length Catch ex As Exception MsgBox(ex.Message) Exit Sub End Try Select Case Lines Case Is < 0, Is >= Line_Length MsgBox("Want to keep last " & (Lines + 1) & " lines" & vbNewLine & _ "But """ & File & """ have " & Line_Length & " lines.") Exit Sub Case Else Dim strArray () As String = IO. File. ReadAllLines(File) Array.Reverse(strArray) ReDim Preserve strArray(Lines) Array.Reverse(strArray) Using WriteFile As New IO. StreamWriter(File, False, System. Text. Encoding. Default) WriteFile.WriteLine(String.Join(vbNewLine, strArray)) End Using End Select End Sub #End Region
Devuelve el el total de líneas de un archivo de texto, con opción de incluir líneas en blanco #Region " Get TextFile Total Lines " ' [ Get TextFile Total Lines Function ] ' ' Examples : ' ' MsgBox(Get_TextFile_Total_Lines("C:\File.txt")) ' MsgBox(Get_TextFile_Total_Lines("C:\File.txt", False)) Private Function Get_TextFile_Total_Lines (ByVal File As String, _ Optional ByVal Include_BlankLines As Boolean = True) As Int64 Try If Include_BlankLines Then Return IO. File. ReadAllLines(File). Length Else Dim LineCount As Int64 For Each Line In IO. File. ReadAllLines(File) If Not Line = String.Empty Then LineCount += 1 ' Application.DoEvents() Next Return LineCount End If Catch ex As Exception MsgBox(ex.Message) Return -1 End Try End Function #End Region
|
|
|
|
|
|
|