viernes, 9 de marzo de 2018

martes, 6 de marzo de 2018

Eliminar último salto de línea de un string

Dim str As String = getTipoDoc(txtResumen)
        If str.EndsWith(vbCrLf) Then
            Dim oTrim() As Char = {vbCr, vbLf}
            str = str.TrimEnd(oTrim)
        End If

fuente

lunes, 26 de febrero de 2018

viernes, 23 de febrero de 2018

xml

-Cargar documento xml
Dim doc As XDocument = XDocument.Load("ruta archivo xml")

miércoles, 21 de febrero de 2018

Guardar archivo

Dim ruta As String="ruta de origen"
sv1.FileName = "nombre del archivo"

            If sv1.ShowDialog = System.Windows.Forms.DialogResult.OK Then
                Try
                    If File.Exists(sv1.FileName) Then
                        Kill(sv1.FileName)
                    End If
                    File.Copy(ruta, sv1.FileName)
                    Kill(ruta)
                    MessageBox.Show("Fin!", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Catch ex As Exception
                End Try
            End If

ExecuteScalar sql

Dim conex As String =""
Dim con As New SqlConnection(conex)
Try
Dim query As String=""
con.Open()
 Using cmd As New SqlCommand(query, con)
                cmd.Parameters.Add("@id", SqlDbType.Int).Value = TextBox.Text
                id_adjunto_IN = cmd.ExecuteScalar()
            End Using
con.Close()
Catch ex As Exception
con.close()
End Try

Obtener carpeta temporal de windows

Dim tempPath As String = Path.GetTempPath()

C:\Users\user\AppData\Local\Temp\

fuente

lunes, 19 de febrero de 2018

Enmascarar caracteres contraseña




Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DataGridView1.Rows.Add("usuario1", "123456")
        DataGridView1.Rows.Add("usuario2", "abcdef")
    End Sub

    Private Sub DataGridView1_CellFormatting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
        If e.ColumnIndex = 1 AndAlso e.Value <> Nothing AndAlso Not CheckBox1.Checked Then
            e.Value = New String("*", e.Value.ToString().Length)
        End If
    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        DataGridView1.Refresh()
    End Sub
End Class

fuente