martes, 13 de diciembre de 2011

vb2010 COMO CARGAR UN DATAGRIDVIEW

Esta función nos permite cargar un datagridview en visual basic 2010.
'Funcion para cargar los registros consultados en datagridview
    Public Sub loadRegistros(ByVal mySQL As String, ByVal grView As DataGridView)
        Dim dt As New DataTable
        Dim da As New Odbc.OdbcDataAdapter
        Dim cmd As New Odbc.OdbcCommand
        Try
            Cursor.Current = Cursors.WaitCursor
            cmd.Connection = conn
            cmd.CommandText = mySQL
            cmd.CommandType = CommandType.Text
            da.SelectCommand = cmd
            da.Fill(dt)
            'Çargamos el Datagridview
            grView.DataSource = dt
            'Coloreamos intercaladamente el datagridview
            grView.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGray
            For i As Integer = 0 To grView.ColumnCount - 1
                grView.AutoResizeColumn(i)
            Next
            grView.Refresh()
            Cursor.Current = Cursors.Default
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            cmd.Dispose()
        End Try
    End Sub

VB2010 Conectarse a una BD via DNS o DSN

Funcion para conectarse a Base de datos, cualquiera, via DNS desde visual basic 2010.

'Funcion para conectarsea base de datos DB2
    Public Function Conectar(ByVal Servidor As String, ByVal Usuario As String, ByVal Password As String) As Boolean
        cnString = "DSN=SPEED;Uid=" & Usuario & ";Pwd=" & Password & ";"
        conn = New OdbcConnection(cnString)
        Try
            Cursor.Current = Cursors.WaitCursor
            'Aperturamos conexión
            conn.Open()
            If conn.State = ConnectionState.Open Then Conectar = True Else Conectar = False
            Cursor.Current = Cursors.Default
        Catch ex As Odbc.OdbcException
            MessageBox.Show("Error: " & ex.ToString & vbCrLf)
        End Try
    End Function

VB2010 Cerrar todos los formularios de un MDI

En visual basic 2010 para cerrar todos los formularios contenidos en un MDI.



        For Each ChildForm As Form In Me.MdiChildren
            ChildForm.Close()
        Next

lunes, 12 de diciembre de 2011

EXPORTAR LISTVIEW A EXCEL O LIBRE OFFICE O OPEN OFFICE

Modulo para extortar un Listview a Excel o Libre Office o Open Office en visual basic 2010.
Primero hay que crear un modulo con con el nombre ExportarXML.
Luego pegamos el código siguiente en el modulo.

Module ExportarXML
'Exportar a Excel
    'Autor: Adalberto Chavez

    Public Sub ExportarListViewXML(ByVal ListView As ListView, ByVal Ruta As String)
        Dim xmlFile As New System.Text.StringBuilder
        Dim CurrLine As String = String.Empty
        CurrLine = xmlEncabezado()
        CurrLine &= "<ss:Row>" & vbNewLine

        For columnIndex As Integer = 0 To ListView.Columns.Count - 1
            CurrLine &= "<ss:Cell  ss:StyleID='s27><Data ss:Type='String>" & ListView.Columns(columnIndex).Text & "</Data></ss:Cell>" & vbNewLine
        Next
        CurrLine &= "</ss:Row>" & vbNewLine
        xmlFile.AppendLine(CurrLine)
        Dim Tipo As String

        CurrLine = String.Empty
        For Each item As ListViewItem In ListView.Items
            CurrLine &= "<ss:Row>" & vbNewLine
            For Each subItem As ListViewItem.ListViewSubItem In item.SubItems
                If (IsNumeric(subItem.Text) And InStr(subItem.Text, ".")) Then
                    Tipo = "Number"
                Else
                    Tipo = "String"
                End If
                CurrLine &= "<ss:Cell><Data ss:Type='" & Tipo & ">" & subItem.Text & "</Data></ss:Cell>" & vbNewLine
            Next
            CurrLine &= "</ss:Row>" & vbNewLine
            xmlFile.AppendLine(CurrLine.Substring(0, CurrLine.Length - 1))
            CurrLine = String.Empty
        Next
        CurrLine = xmlFinal()
        xmlFile.AppendLine(CurrLine)
        Dim Sys As New System.IO.StreamWriter(Ruta)
        Sys.WriteLine(xmlFile.ToString)
        Sys.Flush()
        Sys.Dispose()


        If Comprobar("Excel.Application") Then
            'Abrimos con excel
            Process.Start("Excel.exe", Ruta)
        Else
            'Si no esta excel instalado abrimos con Libre Office
            Process.Start("scalc.exe", Ruta)
        End If
    End Sub


    'Formateamos el XML para Excel y Libre Office
    Private Function xmlEncabezado() As String

        xmlEncabezado = ""
        xmlEncabezado = xmlEncabezado & "<?xml version='1.0?>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "<?mso-application progid='Excel.Sheet?>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "<Workbook" & vbNewLine
        xmlEncabezado = xmlEncabezado & "xmlns:x='urn:schemas-microsoft-com:office:excel" & vbNewLine
        xmlEncabezado = xmlEncabezado & "xmlns='urn:schemas-microsoft-com:office:spreadsheet" & vbNewLine
        xmlEncabezado = xmlEncabezado & "xmlns:ss='urn:schemas-microsoft-com:office:spreadsheet>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "<Styles>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "<Style ss:ID='Default ss:Name='Normal>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "<Alignment ss:Vertical='Bottom/>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "<Borders/>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "<Font/>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "<Interior/>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "<NumberFormat/>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "<Protection/>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "</Style>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "<Style ss:ID='s27>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "<Font x:Family='Swiss ss:Color='#0000FF ss:Bold='1/>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "</Style>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "<Style ss:ID='s21>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "<NumberFormat ss:Format='yyyy\-mm\-dd/>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "</Style>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "<Style ss:ID='s22>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "<NumberFormat ss:Format='yyyy\-mm\-dd\ hh:mm:ss/>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "</Style>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "<Style ss:ID='s23>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "<NumberFormat ss:Format='hh:mm:ss/>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "</Style>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "</Styles>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "<Worksheet ss:Name='Hoja 1>" & vbNewLine
        xmlEncabezado = xmlEncabezado & "<ss:Table>" & vbNewLine

    End Function


    'Finalizamos el xml
    Private Function xmlFinal() As String
        xmlFinal = ""
        'Finalizamos la Tabla
        xmlFinal = xmlFinal & "</ss:Table>" & vbNewLine
        'Finalizamos la Hoja
        xmlFinal = xmlFinal & "</Worksheet>" & vbNewLine
        ''Finalizamos el Libro
        xmlFinal = xmlFinal & "</Workbook>" & vbNewLine
    End Function

    Private Function Comprobar(Clase_Application As String) As Boolean

        Dim Objeto As Object

        ' Deshabilitar errores temporalmente  
        On Error Resume Next

        ' -- Crear una referencia al objeto  
        Objeto = CreateObject(Clase_Application)

        ' -- No dío error  
        If Err.Number <> 0 Then
            Comprobar = False
        Else
            ' .. error  
            Comprobar = True
            ' -- Eliminar  referencia  
            Objeto = Nothing
        End If

        ' -- Limpiar error  
        On Error GoTo 0

    End Function

End Module

sábado, 10 de diciembre de 2011

COMO CONFIGURAR EN ESCRITORIO REMOTO WINDOWS XP

Como configurar mi escritorio remoto para acceder desde Internet a mi pc?

1.-  Activamos el acceso remoto a nuestra PC

En el icono de mi pc, click derecho propiedades. allí nos vamos a la pestaña que dice remoto y activamos la casilla que dice: Permitir que los usuarios se conecten de manera remota a este equipo.

COMO GANAR DINERO EN INTERNET

COMO GANAR DINERO EN INTERNET


Primer Paso:
Para comenzar a ganar dinero en internet, lo primero que debemos hacer es elegir un tema para nuestra web.
El  tema debe ser sobre algo que comprendamos y nos guste. Para este caso los temas son infinitos. Recuerda que hay gente que tiene los mismos intereses que tu.

Fotos de Nereida Gallardo


Completamente desnuda y con poses de lo más sugerentes, la modelo canaria vuelve a descubrirles a los portugueses los encantos que volvieron loco a Cristiano Ronaldo. Con un collar de perlas y unos guantes como únicos complementos, Nereida vuelve a posar ligerita de ropa.

EN VIVO - REAL MADRID VS BARCELONA ONLINE



ALINEACIONES CONFIRMADAS:
REAL MADRID: Casillas; Altintop, Ramos, Carvalho; Coentrao, Xabi Alonso, Pepe, Lass; Cristiano, Benzema e Higuaín. DT: José Mourinho.
FC BARCELONA: Pinto; Alves, Puyol, Piqué, Abidal; Busquets, Xavi, Iniesta, Cesc; Alexis Sánchez y Messi. DT: Josep Guardiola.
ÁRBITRO: Muñíz Fernández
ESTADIO: Santiago Bernabéu.


 EN VIVO - REAL MADRID VS BARCELONA ONLINE 2012

martes, 6 de diciembre de 2011

National Geofrafic Turismo peru

Publicación de National Geografic, declara a Perú como destino turístico.

VB.NET Funcion para cargar un datagridview

Esta función nos permite cargar un datagridview con el resultado de una búsqueda en base de datos.

'Funcion para cargar los registros consultados
    Public Sub loadRegistros(ByVal mySQL As String, ByVal grView As DataGridView, Optional ByVal Check As Boolean = False)
        Dim dt As New DataTable
        Dim da As New Odbc.OdbcDataAdapter
        Dim cmd As New Odbc.OdbcCommand
        Try
            Cursor.Current = Cursors.WaitCursor
            cmd.Connection = conn
            cmd.CommandText = mySQL
            cmd.CommandType = CommandType.Text
            da.SelectCommand = cmd
            da.Fill(dt)
            grView.DataSource = dt
            If Check = True Then
                If grView.Columns(0).Name = ":::" Then grView.Columns.Remove(":::")
                Dim column As New DataGridViewCheckBoxColumn()
                With column
                    .Name = ":::"
                    .HeaderText = .Name
                    .AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet
                    .FlatStyle = FlatStyle.Standard
                    .CellTemplate = New DataGridViewCheckBoxCell()
                    '.ReadOnly = False
                End With
                grView.Columns.Insert(0, column)
                grView.Columns(0).ReadOnly = True
            End If
            grView.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGray
            For i As Integer = 0 To grView.ColumnCount - 1
                grView.AutoResizeColumn(i)
            Next
            grView.Refresh()
            Cursor.Current = Cursors.Default
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            cmd.Dispose()
        End Try
    End Sub