Monday, April 11, 2016

FASTEST VB.Net Twitter Login and Post Tweet

VB.Net Twitter Login. Happy coding bro... ^_^

VB.Net Twitter Login


Public Class Form1

    Dim load, login, logout, tweet, cektweet As Boolean
    Dim iP As Integer = 0
    Private WithEvents TmrCek As New Timer
    
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        load = True
        Btnlogin.Enabled = False
        BtnLogout.Enabled = False
        WB.Navigate("https://mobile.twitter.com/session/new")

        With TmrCek
            .Interval = 1000
            .Start()
        End With
    End Sub

    Private Sub TxtPass_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TxtPass.KeyDown
        If e.KeyCode = Keys.Enter Then Btnlogin_Click(sender, e)
    End Sub

    Private Sub Btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnlogin.Click
        If TxtEmail.Text = Nothing Then
            TxtEmail.Focus()
            Return
        End If

        If TxtPass.Text = Nothing Then
            TxtPass.Focus()
            Return
        End If

        Btnlogin.Enabled = False
        Application.DoEvents()

        With WB
            .Document.GetElementById("session[username_or_email]").SetAttribute("value", TxtEmail.Text)
            .Document.GetElementById("session[password]").SetAttribute("value", TxtPass.Text)
            If .Document.Body.InnerHtml.Contains("signupbutton") Then
                .Document.GetElementById("signupbutton").InvokeMember("click")
            ElseIf .Document.Body.InnerHtml.Contains("commit") Then
                For Each input As HtmlElement In .Document.GetElementsByTagName("input")
                    If input.OuterHtml.Contains("commit") Then
                        input.InvokeMember("click")
                    End If
                    Application.DoEvents()
                Next
            End If
        End With
        login = True

        With TmrCek
            .Interval = 1000
            .Start()
        End With
    End Sub

       Private Sub BtnLogout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLogout.Click
        BtnLogout.Enabled = False
        Application.DoEvents()

        For Each inputTag As HtmlElement In WB.Document.GetElementsByTagName("a")
            If inputTag.OuterHtml.Contains("/account") Then
                inputTag.InvokeMember("click")
                logout = True
            End If
            Application.DoEvents()
        Next

        With TmrCek
            .Interval = 1000
            .Start()
        End With
    End Sub

    Private Sub BtnTweet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnTweet.Click
        If Btnlogin.Enabled = True Then
            TxtEmail.Focus()
            Return
        End If
        If TxtTweet.Text = Nothing Then
            TxtTweet.Focus()
            Return
        End If
        If WB.DocumentText.Contains("/compose/tweet") = False Then Return

        BtnTweet.Enabled = False
        Application.DoEvents()

        For Each input As HtmlElement In WB.Document.GetElementsByTagName("a")
            If input.OuterHtml.Contains("/compose/tweet") Then
                input.InvokeMember("click")
            End If
            Application.DoEvents()
        Next
        tweet = True

        With TmrCek
            .Interval = 1000
            .Start()
        End With
    End Sub

    Private Sub TmrCek_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TmrCek.Tick
        TmrCek.Stop()
        If load Then
            iP += 1
            If iP = 5 Then
                iP = 0
                load = False
                Try
                    If WB.Document.Body.InnerHtml.Contains("session[username_or_email]") Then
                        Btnlogin.Enabled = True
                        BtnLogout.Enabled = False
                        Return
                    Else
Err:
                        MsgBox("Error loading webpage", MsgBoxStyle.Critical, Text)
                        Return
                    End If
                Catch ex As Exception
                    GoTo Err
                End Try
            End If
        End If
        If login Then
            iP += 1
            If iP = 3 Then
                iP = 0
                login = False
                If WB.Document.Body.InnerHtml.Contains("session[username_or_email]") Then
                    Btnlogin.Enabled = True
                    BtnLogout.Enabled = False
                    MsgBox("The email and password you entered did not match our records." _
                            & vbCrLf & "Please double-check and try again. ", MsgBoxStyle.Critical, Text)
                    Return
                Else
                    For Each inputTag As HtmlElement In WB.Document.GetElementsByTagName("a")
                        If inputTag.OuterHtml.Contains("/account") Then
                            BtnLogout.Enabled = True
                            Return
                        End If
                        Application.DoEvents()
                    Next
                End If
            End If
        End If
        If logout Then
            iP += 1
            If iP = 3 Then
                iP = 0
                logout = False
                For Each input As HtmlElement In WB.Document.GetElementsByTagName("input")
                    If input.OuterHtml.Contains("Log out") Then
                        input.InvokeMember("click")
                    End If
                    Application.DoEvents()
                Next
                Btnlogin.Enabled = True
                Return
            End If
        End If
        If tweet Then
            iP += 1
            If iP = 2 Then
                iP = 0
                tweet = False
                WB.Document.GetElementById("tweet[text]").SetAttribute("value", TxtTweet.Text)
                WB.Document.GetElementById("commit").InvokeMember("click")
                cektweet = True

                With TmrCek
                    .Interval = 1000
                    .Start()
                End With
                Return
            End If
        End If
        If cektweet Then
            iP += 1
            If iP = 3 Then
                iP = 0
                If WB.Document.Body.InnerHtml.Contains(TxtTweet.Text) Then
                    cektweet = False
                    BtnTweet.Enabled = True
                    Return
                End If
            End If
        End If
        TmrCek.Start()
    End Sub

    Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
        BtnTweet.Enabled = True
        With TxtTweet
            .Clear()
            .Focus()
        End With
    End Sub

End Class
Farray Cool Social Media, Twitter, VB.Net
Monday, November 03, 2014

How To Insert Cells In An Excel File In VB.NET

Hi, folow this step for insert or edit cells in excel. You must add reference Microsoft Excel 12.0 Object Library in you project.

* Create a new project and add a button to the Form.

* Select reference dialouge from Project menu.


Insert Cells In An Excel File In VB.NET
Insert Cells In An Excel File In VB.NET | gambar from images.google.co.id

* Select Microsoft Excel 12.0 Object Library and click OK button

Edit Update Cells In An Excel File In VB.NET
Edit Update Cells In An Excel File In VB.NET | gambar from images.google.co.id

Done... Run your project for  Insert Cells In An Excel File In VB.NET.

result insert cells

When you execute this program , the program open the file c:\trial.xls and insert in the cell B7, it replace the old content to "your string here" . Before running this program you have to create an excel file name trial.xls. See other tutorial Add Items To Combobox From Database In Visual Basic 2010 (VB.Net 2010).

Source Code :

Imports Excel = Microsoft.Office.Interop.Excel
Imports System.Globalization
Imports System.Threading.Thread

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim newCulture As CultureInfo
        Dim OldCulture As CultureInfo = CurrentThread.CurrentCulture
        Dim xlApp As Excel.Application
        Dim xlWorkBook As Excel.Workbook
        Dim xlWorkSheet As Excel.Worksheet

        xlApp = New Excel.ApplicationClass
        newCulture = New System.Globalization.CultureInfo(xlApp.LanguageSettings.LanguageID(Microsoft.Office.Core.MsoAppLanguageID.msoLanguageIDUI))
        CurrentThread.CurrentCulture = newCulture
        xlWorkBook = xlApp.Workbooks.Open("c:\trial.xls")
        xlWorkSheet = xlWorkBook.Worksheets("sheet1")
        'edit the cell with new value
        xlWorkSheet.Cells(7, 2) = "your string here"
        xlWorkBook.Close()
        xlApp.Quit()

        releaseObject(xlApp)
        releaseObject(xlWorkBook)
        releaseObject(xlWorkSheet)

    End Sub

    Private Sub releaseObject(ByVal obj As Object)
        Try
            System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
            obj = Nothing
        Catch ex As Exception
            obj = Nothing
        Finally
            GC.Collect()
        End Try
    End Sub


End Class

Farray Cool Excel
Thursday, October 16, 2014

Add Items To Combobox From Database In Visual Basic 2010 (VB.Net 2010)

This is tutorial how to add items to Combobox from Database in Visual Basic 2010 (VB.Net 2010). Easy way binding datasource to Combobox.

combox vb.net

SOURCE CODE


Imports System.Data.SqlClient

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'CREATE OBJECT CONNECTION
        Dim cn As New SqlConnection

        With cn
            .ConnectionString = "server=(local)\sqlexpress;database=trial;integrated security=true"
            .Open()
        End With

        'CREATE OBJECT DATA TABLE AND DATA ADAPTER
        Dim dt As New DataTable
        Dim da As New SqlDataAdapter("select kode,nama from warna order by kode", cn)

        da.Fill(dt)
        If dt.Rows.Count > 0 Then
            With ComboBox1
                .Items.Clear() 'CLEAR ITEMS COMBOBOX
                For i As Integer = 0 To dt.Rows.Count - 1
                    'ADD ITEMS TO COMBOBOX
                    .Items.Add(dt.Rows(i).Item("kode") & " - " & dt.Rows(i).Item("nama"))
                Next
                'CLEAR TEXT COMBOBOX
                .Text = Nothing
                .SelectedIndex = -1
            End With
        End If

        'CLEAR ALL OBJECT AND MEMORY
        With cn
            .Close()
            .Dispose()
        End With
        cn = Nothing
        dt.Dispose()
        dt = Nothing
        da.Dispose()
        da = Nothing

    End Sub

End Class


Video Tutorial

https://www.youtube.com/watch?v=klASZPDHtZs

Farray Cool Combobox, Database, VB.Net
Sunday, August 05, 2012

VB.NET String ToLower()


ToLower() As String

Returns a copy of this System.String converted to lowercase, using the casing rules of the current culture.

Return Values :
A System.String in lowercase.

Ex :


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim Str As String = "VBCODESBLOG"


        MsgBox(Str.ToLower)

End Sub


When you execute this code, you will get vbcodesblog in the MessageBox
izzel aza VB.Net

VB.NET String ToUpper()


ToUpper() As String
Returns a copy of this System.String converted to uppercase, using the casing rules of the current culture.

Return Values :
A System.String in uppercase.

Ex :


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click



        Dim Str As String = "vbcodesblog"


        MsgBox(Str.ToUpper)

End Sub


When you execute this code, you will get VBCODESBLOG in the MessageBox
izzel aza VB.Net