martes, 13 de agosto de 2019

timespan

Private Sub btn_ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_ok.Click

        Dim totalDia As Long = (Now.AddDays(1).Date - DateTime.Now).TotalMilliseconds

        'Dim t As TimeSpan = TimeSpan.FromDays(31)



        Dim cantidad_dias_mes As Integer = (Now.AddMonths(12).Date - DateTime.Now).TotalDays
        Dim t1 As TimeSpan = TimeSpan.FromDays(cantidad_dias_mes)
        Dim cantidad_dias_semana As Integer = (Now.AddDays(2 * 7).Date - DateTime.Now).TotalDays
        Dim t2 As TimeSpan = TimeSpan.FromDays(cantidad_dias_semana)
        Dim cantidad_dias_dia As Integer = (Now.AddDays(1).Date - DateTime.Now).TotalDays
        Dim t3 As TimeSpan = TimeSpan.FromDays(cantidad_dias_dia)

    End Sub

viernes, 9 de agosto de 2019

Split string to array con vacíos

a.Split(';').Where(s => s.Length > 0).ToArray();

bloquear combobox


Private Sub cb_tareas_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles cb_tareas.MouseDown
        If e.Button = MouseButtons.Right Then
            cb_tareas.DroppedDown = True
        End If
    End Sub

    Private Sub cb_tareas_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cb_tareas.KeyDown
        e.SuppressKeyPress = True
    End Sub

    Private Sub cb_tareas_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cb_tareas.KeyPress
        e.Handled = True
    End Sub

martes, 6 de agosto de 2019

Crear archivo xml

Dim xml As New XmlDocument
        xml.AppendChild(xml.CreateXmlDeclaration("1.0", "UTF-8", Nothing))
        Dim nodo As XmlNode = xml.CreateElement("DTE")
        nodo.InnerXml = "<Documento>" &
                        "<TipoDTE></TipoDTE>" &
                        "<Folio></Folio>" &
                        "<EstadoSII></EstadoSII>" &
                        "<TrackID></TrackID>" &
                        "</Documento>"
        xml.AppendChild(nodo)
        xml.Save(archivo)

Fuente

lunes, 5 de agosto de 2019

hashset split


Dim t As New HashSet(Of String)
t.Add("33,45690;ruta xml")
t.Add("39,123;ruta txt")

Dim data As String = String.Join("@", t.Select(Function(x) x.Split(";")(0)).ToArray)
Dim path() As String = t.Select(Function(x) x.Split(";")(1)).ToArray


hashset to string separador

Dim enviar As New HashSet(Of String)
Dim str As String = ""

str = String.Join(@, enviar.ToArray)



fuente


jueves, 1 de agosto de 2019

Tamaño de un archivo

Dim archivo As String = "xml_venta.xml"
Dim size_ As Long = New System.IO.FileInfo(archivo).Length
Dim p As String = size_.ToString("N0")
MessageBox.Show(p & " bytes")

servicio existe


Agregar referencia: System.ServiceProcess

Dim se As Boolean = ServiceExists("LanmanWorkstation")

Public Function ServiceExists(ByVal ServiceName As String)
        Return ServiceController.GetServices.Any(Function(x) x.ServiceName.Equals(ServiceName))
    End Function


Dim status As String = ServiceIsRunning("LanmanWorkstation")


Public Function ServiceIsRunning(ByVal ServiceName As String) As String

        Dim sc As ServiceController = New ServiceController(ServiceName)
        Select Case sc.Status
            Case ServiceControllerStatus.Running ' Iniciado
                Return "Running"
            Case ServiceControllerStatus.Stopped ' Detenido
                Return "Stopped"
            Case ServiceControllerStatus.Paused ' Pausado
                Return "Paused"
            Case ServiceControllerStatus.StopPending ' Deteniendose
                Return "Stopping"
            Case ServiceControllerStatus.StartPending ' Iniciando
                Return "Starting"
            Case Else
                Return "Status Changing" ' Desconocido
        End Select
    End Function

fuente

buscar string regex

Dim rx As Regex = New Regex("[a-z]")

 If rx.IsMatch("string") Then
                    Return True
                End If

Crear archivo

File.Create("nombre_archivo").Dispose