Dim hostName As String = Environment.MachineName
Dim hostName2 As String = My.Computer.Name
Dim hostName2 As String = My.Computer.Network.IsAvailable
miércoles, 27 de junio de 2018
Nombre del equipo
Etiquetas:
Computer,
Environment,
Machine
ip del equipo
Dim localIp As String = ""
For Each address As System.Net.IPAddress In System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName).AddressList
If address.AddressFamily = Net.Sockets.AddressFamily.InterNetwork Then
localIp = address.ToString()
Exit For
End If
Next
fuente
For Each address As System.Net.IPAddress In System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName).AddressList
If address.AddressFamily = Net.Sockets.AddressFamily.InterNetwork Then
localIp = address.ToString()
Exit For
End If
Next
fuente
Etiquetas:
AddressFamily,
ip,
IPAddress,
windows
martes, 26 de junio de 2018
Archivos con extensión específica
Dim ext() As String = {".txt", ".XML"}
Dim dinfo As DirectoryInfo = New DirectoryInfo("C:\carpeta")
Dim xfiles() As FileInfo = dinfo.GetFiles.Where(Function(f) ext.Contains(f.Extension.ToLower)).ToArray
Ejemplo1:
Dim files() As String = Directory.GetFiles("C:\carpeta").Where(Function(f) f.EndsWith(".txt")).ToArray
Ejemplo2:
Dim xfiles() As FileInfo = New DirectoryInfo("C:\carpeta").GetFiles.Where(Function(f) Regex.IsMatch(f.Name, "\.(txt|mp3|xml)$")).ToArray
fuente
fuente2
Dim dinfo As DirectoryInfo = New DirectoryInfo("C:\carpeta")
Dim xfiles() As FileInfo = dinfo.GetFiles.Where(Function(f) ext.Contains(f.Extension.ToLower)).ToArray
Ejemplo1:
Dim files() As String = Directory.GetFiles("C:\carpeta").Where(Function(f) f.EndsWith(".txt")).ToArray
Ejemplo2:
Dim xfiles() As FileInfo = New DirectoryInfo("C:\carpeta").GetFiles.Where(Function(f) Regex.IsMatch(f.Name, "\.(txt|mp3|xml)$")).ToArray
fuente
fuente2
jueves, 21 de junio de 2018
Enviar correo gmail
Dim email As String = "123@gmail.com"
Dim password As String = "******"
Dim server As New System.Net.Mail.SmtpClient
Dim mail As New System.Net.Mail.MailMessage
Dim attach As System.Net.Mail.Attachment = Nothing
Try
attach = New System.Net.Mail.Attachment(archivo)
mail.Attachments.Add(attach)
server.Credentials = New System.Net.NetworkCredential(email, password)
server.Port = "587"
server.Host = "smtp.gmail.com"
server.EnableSsl = True
mail.To.Add(email)
mail.From = New System.Net.Mail.MailAddress(email, xrutempresa, System.Text.Encoding.UTF8)
mail.Subject = xrutempresa & " Reporte " & Path.GetFileName(archivo)
server.Send(mail)
attach.Dispose()
Catch ex As Exception
attach.Dispose()
End Try
Dim password As String = "******"
Dim server As New System.Net.Mail.SmtpClient
Dim mail As New System.Net.Mail.MailMessage
Dim attach As System.Net.Mail.Attachment = Nothing
Try
attach = New System.Net.Mail.Attachment(archivo)
mail.Attachments.Add(attach)
server.Credentials = New System.Net.NetworkCredential(email, password)
server.Port = "587"
server.Host = "smtp.gmail.com"
server.EnableSsl = True
mail.To.Add(email)
mail.From = New System.Net.Mail.MailAddress(email, xrutempresa, System.Text.Encoding.UTF8)
mail.Subject = xrutempresa & " Reporte " & Path.GetFileName(archivo)
server.Send(mail)
attach.Dispose()
Catch ex As Exception
attach.Dispose()
End Try
miércoles, 20 de junio de 2018
Variables SQL
DECLARE @var1 VARCHAR(10)
DECLARE @var2 INT
Ejemplo:
DECLARE @var3 INT = (SELECT MIN(id_tabla) FROM tabla)
DECLARE @var4 INT
SET @var4=9
Recorrer una tabla sql
USE base_de_datos
DECLARE @minID INT=0
SELECT @minID = MIN(id_tabla) FROM tabla
DECLARE @maxID INT=0
SELECT @maxID = MAX(id_tabla) FROM tabla
WHILE @minID <= @maxID
BEGIN
IF EXISTS(SELECT * FROM tabla WHERE id_tabla=@minID)
PRINT 'exists ' + CAST(@minID AS VARCHAR)
ELSE
PRINT 'no exists ' + CAST(@minID AS VARCHAR)
SET @minID = @minID + 1
END
DECLARE @minID INT=0
SELECT @minID = MIN(id_tabla) FROM tabla
DECLARE @maxID INT=0
SELECT @maxID = MAX(id_tabla) FROM tabla
WHILE @minID <= @maxID
BEGIN
IF EXISTS(SELECT * FROM tabla WHERE id_tabla=@minID)
PRINT 'exists ' + CAST(@minID AS VARCHAR)
ELSE
PRINT 'no exists ' + CAST(@minID AS VARCHAR)
SET @minID = @minID + 1
END
jueves, 14 de junio de 2018
Verificar formato correo en campo SQL
miércoles, 13 de junio de 2018
Comparar fechas
Dim fs As DateTime = Convert.ToDateTime("2018-08-10").Date
Dim fh As DateTime = Convert.ToDateTime("2018-05-14").Date
If fs > fh Then
MessageBox("ok")
End If
Public Function compareDate(ByVal fechaInicial As String, ByVal fechaActual As String) As Integer
Dim result As Integer = 0
Dim dif As TimeSpan = Convert.ToDateTime(fechaActual) - Convert.ToDateTime(fechaInicial)
Dim nDays As Integer = dif.Days
If nDays = 0 Then
result = 0
'MessageBox.Show("Es el mismo día")
ElseIf nDays > 0 Then
result = 1
'MessageBox.Show("La fecha actual es mayor")
ElseIf nDays < 0 Then
result = -1
'MessageBox.Show("La fecha inicial es mayor")
End If
Return result
End Function
Dim fh As DateTime = Convert.ToDateTime("2018-05-14").Date
If fs > fh Then
MessageBox("ok")
End If
Public Function compareDate(ByVal fechaInicial As String, ByVal fechaActual As String) As Integer
Dim result As Integer = 0
Dim dif As TimeSpan = Convert.ToDateTime(fechaActual) - Convert.ToDateTime(fechaInicial)
Dim nDays As Integer = dif.Days
If nDays = 0 Then
result = 0
'MessageBox.Show("Es el mismo día")
ElseIf nDays > 0 Then
result = 1
'MessageBox.Show("La fecha actual es mayor")
ElseIf nDays < 0 Then
result = -1
'MessageBox.Show("La fecha inicial es mayor")
End If
Return result
End Function
viernes, 8 de junio de 2018
Remover el último caracter de un string
Inicializar arreglo string en tiempo de ejecución
Dim array() As String = New String(3) {}
miércoles, 6 de junio de 2018
Obtener ruta donde se ejecuta un el programa
Dim ruta As String = My.Application.Info.DirectoryPath & "/sql.exe"
Limpiar variables Settings
My.Settings.Reset()
martes, 5 de junio de 2018
Nombre arhivos RCV
Compra: RCV_COMPRA_REGISTRO_12345678-9_201804.csv
Venta: RCV_VENTA_12345678-9_201804.csv
Pendiente: RCV_COMPRA_PENDIENTE_12345678-9_201804.csv
No incluir: RCV_COMPRA_NO_INCLUIR_12345678-9_201804.csv
Reclamado: RCV_COMPRA_RECLAMADO_12345678-9_201804.csv
Venta: RCV_VENTA_12345678-9_201804.csv
Pendiente: RCV_COMPRA_PENDIENTE_12345678-9_201804.csv
No incluir: RCV_COMPRA_NO_INCLUIR_12345678-9_201804.csv
Reclamado: RCV_COMPRA_RECLAMADO_12345678-9_201804.csv
lunes, 4 de junio de 2018
Contar nodos hijos de un nodo padre
Dim doc As New XmlDocument
doc.Load("archivo.xml")
Dim n As Integer = doc.SelectSingleNode("NodoCabecera/nodos").ChildNodes.Count
doc.Load("archivo.xml")
Dim n As Integer = doc.SelectSingleNode("NodoCabecera/nodos").ChildNodes.Count
Suscribirse a:
Entradas (Atom)