XML READ AND WRITE

Imports System.Xml
Imports System.IO
Imports System.Text

Dim output As StringBuilder = New StringBuilder()

Dim xmlString As String = “” & _
” & _
” & _
test with a child element stuff” & _

‘ Create an XmlReader
Using reader As XmlReader = XmlReader.Create(New StringReader(xmlString))
Dim ws As XmlWriterSettings = New XmlWriterSettings()
ws.Indent = True
Using writer As XmlWriter = XmlWriter.Create(output, ws)

‘ Parse the file and display each of the nodes.
While reader.Read()
Select Case reader.NodeType
Case XmlNodeType.Element
writer.WriteStartElement(reader.Name)
Case XmlNodeType.Text
writer.WriteString(reader.Value)
Case XmlNodeType.XmlDeclaration
Case XmlNodeType.ProcessingInstruction
writer.WriteProcessingInstruction(reader.Name, reader.Value)
Case XmlNodeType.Comment
writer.WriteComment(reader.Value)
Case XmlNodeType.EndElement
writer.WriteFullEndElement()
End Select
End While
End Using
End Using
OutputTextBlock.Text = output.ToString()

—————————————————————

Dim output As StringBuilder = New StringBuilder()

Dim xmlString As String = _
” & _
” & _
The Autobiography of Benjamin Franklin” & _
” & _
Benjamin” & _
Franklin” & _
” & _
8.99” & _
” & _

‘ Create an XmlReader
Using reader As XmlReader = XmlReader.Create(New StringReader(xmlString))

reader.ReadToFollowing(“book”)
reader.MoveToFirstAttribute()
Dim genre As String = reader.Value
output.AppendLine(“The genre value: ” + genre)

reader.ReadToFollowing(“title”)
output.AppendLine(“Content of the title element: ” + reader.ReadElementContentAsString())
End Using

OutputTextBlock.Text = output.ToString()

MSSQL CONNECTION IN VB

Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.Data.OleDb

Public Class Form1
Public SQLCon As New SqlConnection With {.ConnectionString = “Server=mobilehub.ddns.net;Database=SUN;User=alan;Pwd=xxxxxx;”}
Public SQLCmd As SqlCommand
Public Function HasConnection() As Boolean
Try
SQLCon.Open()
SQLCon.Close()
Return True
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TextBox1.AutoSize = False
TextBox1.Height = 80
Me.Show()

SQLCon.Open()
Dim cmd As New SqlCommand(“”, SQLCon)
Dim txtName As String
cmd.CommandText = “SELECT NAME FROM SUNTABLE”
txtName = IIf(IsDBNull(cmd.ExecuteScalar), “”, cmd.ExecuteScalar)
If txtName <> “” Then
MsgBox(“Record Found!”, MsgBoxStyle.Information, “Update”)
TextBox1.Text = “”
TextBox1.Text = txtName
Else
MsgBox(“No Record Found!”, MsgBoxStyle.Information, “INFO.”)
End If

End Sub
End Class

Get IMAGE from Webbrowser’s Cache

Imports mshtml

‘Search Element’s are Different
Dim get_item_n As System.Windows.Forms.HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName(“a”)
For Each get_item_n_ As HtmlElement In get_item_n
If get_item_n_.GetAttribute(“classname”) = “s_next” Then
get_item_n_.InvokeMember(“click”)
Exit For
End If
Next
‘CODE

‘copy image start
Try
Dim doc As IHTMLDocument2 = DirectCast(WebBrowser2.Document.DomDocument, IHTMLDocument2)
Dim imgRange As IHTMLControlRange = DirectCast(DirectCast(doc.body, HTMLBody).createControlRange(), IHTMLControlRange)
Dim img_no As Integer = 1
For Each img As IHTMLImgElement In doc.images
imgRange.add(DirectCast(img, IHTMLControlElement))
imgRange.execCommand(“Copy”, False, Nothing)
If img_no = 1 Then
Try
Using bmp As Bitmap = DirectCast(Clipboard.GetDataObject().GetData(DataFormats.Bitmap), Bitmap)
bmp.Save(“c:\comics\PRISONER\” + rows.ToString + “.jpg”)
End Using
Catch ex As Exception
End Try
End If
img_no += 1
Next
Catch ex As Exception
End Try
‘copy image end

ZOOM OUT WEBBROWSER in VB.net

Add 5 Buttons, one textbox, one timer, one webbrowser

CODE:

Public Class Form1
Dim pswaHeight As Object
Dim pswaWidth As Object
Dim pswaHeightInt As Integer
Dim pswaWidthInt As Integer
Private Enum Exec
OLECMDID_OPTICAL_ZOOM = 63
End Enum
Private Enum execOpt
OLECMDEXECOPT_DODEFAULT = 0
OLECMDEXECOPT_PROMPTUSER = 1
OLECMDEXECOPT_DONTPROMPTUSER = 2
OLECMDEXECOPT_SHOWHELP = 3
End Enum
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
pswaHeight = Screen.PrimaryScreen.WorkingArea.Height
pswaWidth = Screen.PrimaryScreen.WorkingArea.Width
pswaHeightInt = CInt(pswaHeight)
pswaWidthInt = CInt(pswaWidth)
Me.Text = “Web Browser”
End Sub
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Timer1.Start()
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If WebBrowser1.Width > Math.Round(pswaWidthInt / 5.6) And WebBrowser1.Width < Math.Round(pswaWidthInt / 2.97) Or WebBrowser1.Height > Math.Round(pswaHeightInt / 3.0) And WebBrowser1.Height < Math.Round(pswaHeightInt / 2.4) Then Try Dim Res As Object = Nothing Dim MyWeb As Object MyWeb = Me.WebBrowser1.ActiveXInstance MyWeb.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, execOpt.OLECMDEXECOPT_PROMPTUSER, 40, IntPtr.Zero) Catch ex As Exception MsgBox(ex.Message) End Try End If If WebBrowser1.Width > Math.Round(pswaWidthInt / 2.97) And WebBrowser1.Width < Math.Round(pswaWidthInt / 2.58) Or WebBrowser1.Height > Math.Round(pswaHeightInt / 2.4) And WebBrowser1.Height < Math.Round(pswaHeightInt / 2.13) Then Try Dim Res As Object = Nothing Dim MyWeb As Object MyWeb = Me.WebBrowser1.ActiveXInstance MyWeb.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, execOpt.OLECMDEXECOPT_PROMPTUSER, 50, IntPtr.Zero) Catch ex As Exception MsgBox(ex.Message) End Try End If If WebBrowser1.Width > Math.Round(pswaWidthInt / 2.58) And WebBrowser1.Width < Math.Round(pswaWidthInt / 2.23) Or WebBrowser1.Height > Math.Round(pswaHeightInt / 2.13) And WebBrowser1.Height < Math.Round(pswaHeightInt / 1.85) Then Try Dim Res As Object = Nothing Dim MyWeb As Object MyWeb = Me.WebBrowser1.ActiveXInstance MyWeb.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, execOpt.OLECMDEXECOPT_PROMPTUSER, 60, IntPtr.Zero) Catch ex As Exception MsgBox(ex.Message) End Try End If If WebBrowser1.Width > Math.Round(pswaWidthInt / 2.23) And WebBrowser1.Width < Math.Round(pswaWidthInt / 1.89) Or WebBrowser1.Height > Math.Round(pswaHeightInt / 1.85) And WebBrowser1.Height < Math.Round(pswaHeightInt / 1.64) Then Try Dim Res As Object = Nothing Dim MyWeb As Object MyWeb = Me.WebBrowser1.ActiveXInstance MyWeb.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, execOpt.OLECMDEXECOPT_PROMPTUSER, 70, IntPtr.Zero) Catch ex As Exception MsgBox(ex.Message) End Try End If If WebBrowser1.Width > Math.Round(pswaWidthInt / 1.89) And WebBrowser1.Width < Math.Round(pswaWidthInt / 1.6) Or WebBrowser1.Height > Math.Round(pswaHeightInt / 1.64) And WebBrowser1.Height < Math.Round(pswaHeightInt / 1.53) Then Try Dim Res As Object = Nothing Dim MyWeb As Object MyWeb = Me.WebBrowser1.ActiveXInstance MyWeb.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, execOpt.OLECMDEXECOPT_PROMPTUSER, 80, IntPtr.Zero) Catch ex As Exception MsgBox(ex.Message) End Try End If If WebBrowser1.Width > Math.Round(pswaWidthInt / 1.6) And WebBrowser1.Width < Math.Round(pswaWidthInt / 1.2) Or WebBrowser1.Height > Math.Round(pswaHeightInt / 1.53) And WebBrowser1.Height < Math.Round(pswaHeightInt / 1.16) Then Try Dim Res As Object = Nothing Dim MyWeb As Object MyWeb = Me.WebBrowser1.ActiveXInstance MyWeb.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, execOpt.OLECMDEXECOPT_PROMPTUSER, 90, IntPtr.Zero) Catch ex As Exception MsgBox(ex.Message) End Try End If If WebBrowser1.Width > Math.Round(pswaWidthInt / 1.2) AndAlso WebBrowser1.Height > Math.Round(pswaHeightInt / 1.16) Then
Try
Dim Res As Object = Nothing
Dim MyWeb As Object
MyWeb = Me.WebBrowser1.ActiveXInstance
MyWeb.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, execOpt.OLECMDEXECOPT_PROMPTUSER, 100, IntPtr.Zero)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Navigate(TextBox1.Text)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
WebBrowser1.GoBack()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
WebBrowser1.GoForward()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
WebBrowser1.Refresh()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
WebBrowser1.Navigate(“http://www.baidu.com”)
End Sub
End Class

MOUSE EMU

Private Declare Sub mouse_event Lib “user32.dll” (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
Private Sub Mouse_Click(ByVal button As Integer, ByVal state As String)
Select Case button
Case 1
If state = “down” Then ‘left button
mouse_event(2, 100, 100, 0, 0)
Else
mouse_event(4, 100, 100, 0, 0)
End If
Case 2 ‘right button
If state = “down” Then
mouse_event(8, 100, 100, 0, 0)
Else
mouse_event(16, 100, 100, 0, 0)
End If
Case 3
If state = “down” Then ‘middle button
mouse_event(32, 100, 100, 0, 0)
Else
mouse_event(64, 100, 100, 0, 0)
End If
End Select
End Sub

BUTTON:
‘MessageBox.Show(“X: ” & MousePosition.X & ” Y: ” & MousePosition.Y)
Dim x As Integer = Cursor.Position.X
Dim y As Integer = Cursor.Position.Y
‘Mouse_Click(1, “down”)
Cursor.Position = New Point(200, 50)
‘Mouse_Click(1, “up”)
Mouse_Click(1, “down”)
Mouse_Click(1, “up”)
”Mouse_Click(1, “down”)
”Mouse_Click(1, “up”)

Webbrowser Click Submit Button (IF NO ID FOUND)

Dim item_name As String = “”
Dim get_item_name As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName(“input”)
For Each get_item_name_ As HtmlElement In get_item_name
If get_item_name_.GetAttribute(“type”) = “submit” Then
‘MsgBox(get_item_name_.GetAttribute(“value”))
get_item_name_.InvokeMember(“click”)
End If
Next

WITH ID:
WebBrowser1.Document.GetElementById(“dns_records_show_add_record”).InvokeMember(“click”)

Webbrowser Input Data (Username and Password)

WebBrowser1.Document.GetElementById(“member_username”).SetAttribute(“value”, “usernamea”)
WebBrowser1.Document.GetElementById(“member_password”).SetAttribute(“value”, “usernamep”)

Active Webbrowser (Focus window) Click Button

SetForegroundWindow(Me.Handle())
WebBrowser1.Document.Focus()

CLICK BUTTON BY ID
WebBrowser1.Document.GetElementById(“dns_records_add_new_record”).InvokeMember(“click”)

Download File Stream from website

1:
Function getip() As String
Dim ip As New WebClient
Return ip.DownloadString(“http://bot.whatismyipaddress.com/”)
End Function
2:
Function getfromfile() As String
Dim ip As New WebClient
Dim ip_string As String = “”
Try
ip_string = ip.DownloadString(“http://bigfox.com.au/ip.html”)
Catch ex As Exception
End Try
Return ip_string
End Function

Generate a TXT file and FTP Upload

Imports System.Net
Dim filePath As String
filePath = System.IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, “test.txt”)
Dim objWriter As New System.IO.StreamWriter(filePath)
objWriter.Write(“text content”)
objWriter.Close()
UploadFile(filePath, “ftp://bigfox.com.au/test.txt”, “ftp@bigfox.com.au”, “xxxxxxxx”)

SUB HERE:
Public Sub UploadFile(ByVal _FileName As String, ByVal _UploadPath As String, ByVal _FTPUser As String, ByVal _FTPPass As String)
Dim _FileInfo As New System.IO.FileInfo(_FileName)
‘ Create FtpWebRequest object from the Uri provided
Dim _FtpWebRequest As System.Net.FtpWebRequest = CType(System.Net.FtpWebRequest.Create(New Uri(_UploadPath)), System.Net.FtpWebRequest)
‘ Provide the WebPermission Credintials
_FtpWebRequest.Credentials = New System.Net.NetworkCredential(_FTPUser, _FTPPass)
‘ By default KeepAlive is true, where the control connection is not closed
‘ after a command is executed.
_FtpWebRequest.KeepAlive = False
‘ set timeout for 20 seconds
_FtpWebRequest.Timeout = 20000
‘ Specify the command to be executed.
_FtpWebRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
‘ Specify the data transfer type.
_FtpWebRequest.UseBinary = True
‘ Notify the server about the size of the uploaded file
_FtpWebRequest.ContentLength = _FileInfo.Length
‘ The buffer size is set to 2kb
Dim buffLength As Integer = 2048
Dim buff(buffLength – 1) As Byte
‘ Opens a file stream (System.IO.FileStream) to read the file to be uploaded
Dim _FileStream As System.IO.FileStream = _FileInfo.OpenRead()
Try
‘ Stream to which the file to be upload is written
Dim _Stream As System.IO.Stream = _FtpWebRequest.GetRequestStream()
‘ Read from the file stream 2kb at a time
Dim contentLen As Integer = _FileStream.Read(buff, 0, buffLength)
‘ Till Stream content ends
Do While contentLen <> 0
‘ Write Content from the file stream to the FTP Upload Stream
_Stream.Write(buff, 0, contentLen)
contentLen = _FileStream.Read(buff, 0, buffLength)
Loop
‘ Close the file stream and the Request Stream
_Stream.Close()
_Stream.Dispose()
_FileStream.Close()
_FileStream.Dispose()
Catch ex As Exception
MessageBox.Show(ex.Message, “Upload Error”, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub

EXCEL Disable Alerts in VB.net

app.DisplayAlerts = False

START Thunder Process

Try
Process.Start(System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + “\Thunder Network\Thunder9\Program\Thunder.exe”)
Catch ex As Exception
End Try