Monday, July 24, 2017

[VB.NET] Mesin pencari mbah google

Google, pembuat mesin pencarian terbesar di dunia, menawarkan kecepatan, kemudahan pencarian informasi di internet. Dengan mengakses lebih dari  halaman web, mengantarkan hasil yang relevan dengan semua pemakai di seluruh dunia kurang dari setengah detik.
Dengan web browser Google Desktop maka agan akan menemukan cara baru yang lebih mudah untuk mendapat informasi, ini hanyalah sebagi contoh saja mesin pencari yang dibuat menggunakan program visual basic  mesin pencarinya mbah google yang yang berjalan dengan web browsernya google chrome , sekilas gambarannya
desktop membuat mesin perantara untuk  pencari web browser
pencari web browser
Desain Form
 pencari web browser
pencari web browser
Komponen yang dibutuhkan
  • TextBox
  • Button
  • RadioButton
  • PictureBox
Untuk code program bisa dilihat dibawah ini
Public Class Form1
Private BroswerExe As String = “chrome.exe”
Private BrowserName As String = vbNullString
Private Const FindStr As String = “https://www.google.com/search?q=”
Public Function Encode(ByVal Source As String)
Dim chars() As Char = Source.ToCharArray()
Dim sb As New System.Text.StringBuilder()
For Each c As Char In chars
‘Check for safe chars
If c Like “[A-Z-a-z-0-9]” Then
sb.Append(c)
ElseIf c = ” ” Then
‘Append space char
sb.Append(“+”)
Else
‘Get hex value from char
Dim sHex As String = Hex(Asc(c))
‘Pad out left 2 places.
sHex = “%” & sHex.PadLeft(2, “0″)
sb.Append(sHex)
End If
Next
‘Clean up
Erase chars
‘Return string
Return sb.ToString()
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
BrowserName = RadioButton1.Text
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim p As New System.Diagnostics.Process()
If (TextBox1.Text.Trim().Length > 0) Then
Try
With p
.StartInfo.FileName = BroswerExe
.StartInfo.Arguments = FindStr & Encode(TextBox1.Text)
‘Start broswer.
p.Start()
‘Minsize window to taskbar.
Me.WindowState = FormWindowState.Minimized
End With
Catch ex As Exception
MessageBox.Show(“Browser Not Found ‘” & BrowserName & “‘”, Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
BrowserName = RadioButton2.Text
BroswerExe = “chrome.exe”
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
BrowserName = RadioButton1.Text
BroswerExe = “iexplore.exe”
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = ControlChars.Cr Then
e.Handled = True
Button1_Click(sender, e)
End If
End Sub
End Class

No comments:
Write comments