Librería de Snippets para VB.NET !! (Compartan aquí sus snippets)

Iniciado por Eleкtro, 18 Diciembre 2012, 22:23 PM

0 Miembros y 1 Visitante están viendo este tema.

Eleкtro

Un AppActivate más sencillo de usar que el default, se puede usar especificando el nombre del proceso.

PD: Sirve para activar (darle Focus) a un proceso externo.

Código (vbnet) [Seleccionar]
   #Region " App Activate "
   
   ' [ App Activate ]
   '
   ' // By Elektro H@cker
   '
   ' Examples :
   '
   ' App_Activate("cmd")
   ' App_Activate("cmd.exe")
   ' If App_Activate("cmd") Then...

   Private Function App_Activate(ByVal ProcessName As String) As Boolean
       If ProcessName.ToLower.EndsWith(".exe") Then ProcessName = ProcessName.Substring(0, ProcessName.Length - 4)
       Dim ProcessArray = Process.GetProcessesByName(ProcessName)
       If ProcessArray.Length = 0 Then
           Return False
       Else
           AppActivate(ProcessArray(0).Id)
           Return True
           End If
   End Function
   
   #End Region








Eleкtro

#231
Una Class para controlar WinAmp: http://pastebin.com/4yC91AnD
También está disponible compilada en un dll: http://sourceforge.net/projects/wacc/

PD: Funciona en las versiones 5.X

Ejemplos de uso (Aparte de los oficiales):

Código (vbnet) [Seleccionar]
#Region " Examples "

' // By Elektro H@cker
'
' INSTRUCTIONS:
'
' 1. Add a reference for "WACC.DLL"

Public Class Form1

   Dim Winamp As WACC.clsWACC = New WACC.clsWACC

   Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

       ' // Bind the WinAmp process to the variable object
       Winamp.Bind()

       ' // Get WinAmp process PID
       ' Winamp.ProcessID()

       ' // Close WinAmp
       ' Winamp.CloseWinamp()

       ' // Restart WinAmp
       ' Winamp.RestartWinamp()

       ' // Open new instance of WinAmp
       ' Winamp.OpenNewInstance()

       ' // Play playback
       ' Winamp.Playback.Play()

       ' // Pause playback
       ' Winamp.Playback.PauseUnpause()

       ' // Stop playback
       ' Winamp.Playback.Stop()

       ' // Junp to previous track
       ' Winamp.Playlist.JumpToPreviousTrack()

       ' // Junp to next track
       ' Winamp.Playlist.JumpToNextTrack()

       ' // Rewind 5 seconds of the current song
       ' Winamp.Playback.Rewind5s()

       ' // Forward 5 seconds of the current song
       ' Winamp.Playback.Forward5s()

       ' // Get Track Length
       ' Winamp.Playback.GetTrackLength * 1000 '(ms)

       ' // Set Track Position
       ' Winamp.Playback.TrackPosition = 60000 ' (ms)

       ' // Get WinAmp state
       ' MsgBox(Winamp.Playback.PlaybackState().ToString)
       ' If Winamp.Playback.PlaybackState = clsWACC.cPlayback.Playback_State.Playing Then : End If

       ' // Set volume
       ' Winamp.AudioControls.Volume = Math.Round(50 / (100 / 255))

       ' // Volume up
       ' Winamp.AudioControls.VolumeUp()

       ' // Volume down
       ' Winamp.AudioControls.VolumeDown()

       ' // Get current track BitRate
       ' MsgBox(Winamp.Playback.Bitrate.ToString & " kbps")

       ' // Get current track SampleRate
       ' MsgBox(Winamp.Playback.SampleRate.ToString & " kHz")

       ' // Get current track channels
       ' MsgBox(Winamp.Playback.Channels.ToString & " channels")

       ' // Clear playlist
       ' Winamp.Playlist.Clear()

       ' // Remove missing files in playlist
       ' Winamp.Playlist.RemoveMissingFiles()

       ' // Enable/Disable Shuffle
       ' Winamp.Playback.ShuffleEnabled = True

       ' // Enable/Disable Repeat
       ' Winamp.Playback.RepeatEnabled = True

       ' // Set WinAmp OnTop
       ' Winamp.Options.AlwaysOnTop = True

   End Sub

End Class

#End Region








Eleкtro

#232
He extendido y mejorado la función para buscar texto en la colección de Items de un listview:

PD: la versión antigua la pueden encontrar aquí: http://foro.elhacker.net/net/libreria_de_snippets_posteen_aqui_sus_snippets-t378770.0.html;msg1865639#msg1865639

#Region " [ListView] Find ListView Text "

   ' [ListView] Find ListView Text Function
   '
   ' // By Elektro H@cker
   '
   ' Examples :
   ' MsgBox(Find_ListView_Text(ListView1, "Test"))
   ' MsgBox(Find_ListView_Text(ListView1, "Test", 2, True, True))
   ' If Find_ListView_Text(ListView1, "Test") Then...

   Private Function Find_ListView_Text(ByVal ListView As ListView, _
                                       ByVal SearchString As String, _
                                       Optional ByVal ColumnIndex As Int32 = Nothing, _
                                       Optional ByVal MatchFullText As Boolean = True, _
                                       Optional ByVal IgnoreCase As Boolean = True) As Boolean

       Dim ListViewColumnIndex As Int32 = ListView.Columns.Count - 1

       Select Case ColumnIndex

           Case Is < 0, Is > ListViewColumnIndex ' ColumnIndex is out of range

               Throw New Exception("ColumnIndex is out of range. " & vbNewLine & _
                                   "ColumnIndex Argument: " & ColumnIndex & vbNewLine & _
                                   "ColumnIndex ListView: " & ListViewColumnIndex)

           Case Nothing ' ColumnIndex is nothing

               If MatchFullText AndAlso IgnoreCase Then ' Match full text, All columns, IgnoreCase
                   For Each Item As ListViewItem In ListView.Items
                       For X As Int32 = 0 To ListViewColumnIndex
                           If Item.SubItems(X).Text.ToLower = SearchString.ToLower Then Return True
                       Next
                   Next
               ElseIf MatchFullText AndAlso Not IgnoreCase Then ' Match full text, All columns, CaseSensitive
                   For Each Item As ListViewItem In ListView.Items
                       For X As Int32 = 0 To ListViewColumnIndex
                           If Item.SubItems(X).Text = SearchString Then Return True
                       Next
                   Next
               ElseIf Not MatchFullText AndAlso IgnoreCase Then ' Match part of text, All columns, IgnoreCase
                   If ListView1.FindItemWithText(SearchString) IsNot Nothing Then _
                        Return True _
                   Else Return False
               ElseIf Not MatchFullText AndAlso Not IgnoreCase Then ' Match part of text, All columns, CaseSensitive
                   For Each Item As ListViewItem In ListView.Items
                       For X As Int32 = 0 To ListViewColumnIndex
                           If Item.SubItems(X).Text.Contains(SearchString) Then Return True
                       Next
                   Next
               End If

           Case Else ' ColumnIndex is other else

               If MatchFullText AndAlso IgnoreCase Then ' Match full text, ColumnIndex, IgnoreCase
                   For Each Item As ListViewItem In ListView.Items
                       If Item.SubItems(ColumnIndex).Text.ToLower = SearchString.ToLower Then Return True
                   Next
               ElseIf MatchFullText AndAlso Not IgnoreCase Then  ' Match full text, ColumnIndex, CaseSensitive
                   For Each Item As ListViewItem In ListView.Items
                       If Item.SubItems(ColumnIndex).Text = SearchString Then Return True
                   Next
               ElseIf Not MatchFullText AndAlso IgnoreCase Then ' Match part of text, ColumnIndex, IgnoreCase
                   For Each Item As ListViewItem In ListView.Items
                       If Item.SubItems(ColumnIndex).Text.ToLower.Contains(SearchString.ToLower) Then Return True
                   Next
               ElseIf Not MatchFullText AndAlso Not IgnoreCase Then ' Match part of text, ColumnIndex, CaseSensitive
                   For Each Item As ListViewItem In ListView.Items
                       If Item.SubItems(ColumnIndex).Text.Contains(SearchString) Then Return True
                   Next
               End If

       End Select

       Return False

   End Function

#End Region



EDITO:

Vuelto a mejorar:

(El anterior no medía la cantidad de subitems de cada item, por ejemplo en un listview con 3 columnas, un item con dos subitems y otro item con 3 subitems entonces daba error porque el primer item no tenia un tercer subitem)

Código (vbnet) [Seleccionar]
#Region " [ListView] Find ListView Text "

   ' [ListView] Find ListView Text Function
   '
   ' // By Elektro H@cker
   '
   ' Examples :
   ' MsgBox(Find_ListView_Text(ListView1, "Test"))
   ' MsgBox(Find_ListView_Text(ListView1, "Test", 2, True, True))
   ' If Find_ListView_Text(ListView1, "Test") Then...

   Private Function Find_ListView_Text(ByVal ListView As ListView, _
                                       ByVal SearchString As String, _
                                       Optional ByVal ColumnIndex As Int32 = Nothing, _
                                       Optional ByVal MatchFullText As Boolean = True, _
                                       Optional ByVal IgnoreCase As Boolean = True) As Boolean

       Select Case ColumnIndex

           Case Is < 0, Is > ListView.Columns.Count - 1 ' ColumnIndex is out of range

               Throw New Exception("ColumnIndex is out of range. " & vbNewLine & _
                                   "ColumnIndex Argument: " & ColumnIndex & vbNewLine & _
                                   "ColumnIndex ListView: " & ListView.Columns.Count - 1)

           Case Nothing ' ColumnIndex is nothing

               If MatchFullText Then ' Match full text in all columns

                   For Each Item As ListViewItem In ListView.Items
                       For X As Int32 = 0 To Item.SubItems.Count - 1
                           If String.Compare(Item.SubItems(X).Text, SearchString, IgnoreCase) = 0 Then
                               Return True
                           End If
                       Next
                   Next

               ElseIf Not MatchFullText Then ' Match part of text in all columns

                   Select Case IgnoreCase
                       Case True ' IgnoreCase
                           If ListView1.FindItemWithText(SearchString) IsNot Nothing Then
                               Return True
                           End If
                       Case False ' CaseSensitive
                           For Each Item As ListViewItem In ListView.Items
                               For X As Int32 = 0 To Item.SubItems.Count - 1
                                   If Item.SubItems(X).Text.Contains(SearchString) Then Return True
                               Next
                           Next
                   End Select

               End If

           Case Else ' ColumnIndex is other else

               If MatchFullText Then ' Match full text in ColumnIndex

                   For Each Item As ListViewItem In ListView.Items
                       If String.Compare(Item.SubItems(ColumnIndex).Text, SearchString, IgnoreCase) = 0 Then
                           Return True
                       End If
                   Next

               ElseIf Not MatchFullText Then ' Match part of text in ColumnIndex

                   For Each Item As ListViewItem In ListView.Items
                       Select Case IgnoreCase
                           Case True ' IgnoreCase
                               If Item.SubItems(ColumnIndex).Text.ToLower.Contains(SearchString.ToLower) Then
                                   Return True
                               End If
                           Case False ' CaseSensitive
                               If Item.SubItems(ColumnIndex).Text.Contains(SearchString) Then
                                   Return True
                               End If
                       End Select
                   Next

               End If

       End Select

       Return False ' Any matches

   End Function

#End Region








z3nth10n


Interesados hablad por Discord.

Eleкtro

Cita de: Ikillnukes en  3 Julio 2013, 10:42 AMAhora si va. ;D

No quiero desvirtuar mucho el tema, pero por curiosidad cual era el fallo?








z3nth10n

Cita de: EleKtro H@cker en  3 Julio 2013, 14:31 PM
No quiero desvirtuar mucho el tema, pero por curiosidad cual era el fallo?

Que el archivo no se descargaba, no lo hablamos ayer? xD

Interesados hablad por Discord.

Eleкtro

Cita de: Ikillnukes en  3 Julio 2013, 14:51 PM
Que el archivo no se descargaba, no lo hablamos ayer? xD

claro, quiero decir que ¿Como lo arreglaste? que correcciones habia que hacerle? xD








z3nth10n

Pues llevababas tu razón con los Ifs... A parte:

Código (vbnet) [Seleccionar]
If File.Exists(patha) Then
            File.Delete(patha)
        End If


Esto si lo pongo al final, lo va a borrar y no va a leer nada. Si lo ponemos al principio, lo borra y lo vuelve a descargar. :P

Interesados hablad por Discord.

Eleкtro

Format Time

Formatea un número de milisegundos.

Código (vbnet) [Seleccionar]
#Region " Format Time "

    ' [ Format Time Function ]
    '
    ' // By Elektro H@cker
    '
    ' Examples :
    ' MsgBox(Format_Time(61500, TimeFormat.M_S_MS)) ' Result: "01:01:500"
    ' MsgBox(Format_Time(65000, TimeFormat.M_S))    ' Result: "01:05"

    ' TimeFormat [ENUM]
    Public Enum TimeFormat
        D_H_M_S_MS
        D_H_M_S
        D_H_M
        D_H
        D

        H_M_S_MS
        H_M_S
        H_M
        H

        M_S_MS
        M_S
        M

        S_MS
        S
    End Enum

    ' Format Time [FUNC]
    Private Function Format_Time(ByVal MilliSeconds As Int64, ByVal TimeFormat As TimeFormat) As String

        Dim Time As New TimeSpan(TimeSpan.TicksPerMillisecond * MilliSeconds)

        Select Case TimeFormat

            Case TimeFormat.D_H_M_S_MS
                Return Time.ToString("dd\:hh\:mm\:ss\:fff")
            Case TimeFormat.D_H_M_S
                Return Time.ToString("dd\:hh\:mm\:ss")
            Case TimeFormat.D_H_M
                Return Time.ToString("dd\:hh\:mm")
            Case TimeFormat.D_H
                Return Time.ToString("dd\:hh")
            Case TimeFormat.D
                Return Time.ToString("dd")
            Case TimeFormat.H_M_S_MS
                Return Time.ToString("hh\:mm\:ss\:fff")
            Case TimeFormat.H_M_S
                Return Time.ToString("hh\:mm\:ss")
            Case TimeFormat.H_M
                Return Time.ToString("hh\:mm")
            Case TimeFormat.H
                Return Time.ToString("hh")
            Case TimeFormat.M_S_MS
                Return Time.ToString("mm\:ss\:fff")
            Case TimeFormat.M_S
                Return Time.ToString("mm\:ss")
            Case TimeFormat.M
                Return Time.ToString("mm")
            Case TimeFormat.S_MS
                Return Time.ToString("ss\:fff")
            Case TimeFormat.S
                Return Time.ToString("ss")
            Case Else
                Return Nothing
        End Select

    End Function

#End Region







Cuando creo un listview suelo añadir un índice numérico en la primera columna, para mantener un orden, bueno pues este snippet sirve para reindexar esa columna por ejemplo cuando eliminamos un item del listview.



Código (vbnet) [Seleccionar]
#Region " ReIndex ListView "

    ' [ ReIndex ListView ]
    '
    ' // By Elektro H@cker
    '
    ' Examples :
    ' ReIndex_ListView(ListView1)

    ' ReIndex ListView [SUB]
    Private Sub ReIndex_ListView(ByVal ListView As ListView, Optional ByVal Column As Int32 = 0)
        Dim Index As Int32 = 0
        For Each Item As ListViewItem In ListView.Items
            Index += 1
            Item.SubItems(Column).Text = Index
        Next
    End Sub

#End Region








Eleкtro

Actualizada la colección de snippets con un total de 400 Snippets...
...Casi nada!!

-> http://elektrostudios.tk/Snippets.zip

En la primera página de este hilo tienen un índice de todos los snippets que contiene el pack.

Saludos!