Hanya sharing pengalaman: nge blog, google AdSense, cyber enjoyable

Naruto Fans Kampanye Damai Pemilu Indonesia 2009 Mendukung SBY untuk menjadi Presiden 2009-2014
Showing posts with label Visual basic. Show all posts
Showing posts with label Visual basic. Show all posts

Jul 6, 2007

Concatenating Strings

Visual Basic supports only one string operator, the concatenation operator. This operator combines two or more strings of text, similar to the way the addition operator is used to combine two or more numbers. The concatenation operator is the "ampersand" symbol (&). When you combine two strings with the concatenation operator, the second string is added directly to the end of the first string. The result is a longer string containing the full contents of both source strings.

The concatenation operator is used in an assignment statement as follows:

NewString = stringOne & stringTwo & stringThree

In this syntax, NewString represents the variable that contains the result of the concatenation operation. stringOne, stringTwo, and stringThree all represent string expressions. These can be any valid strings, including string variables, literal expressions (enclosed in quotation marks), or functions that return a string.

The ampersand between a pair of string expressions tells Visual Basic to concatenate the two expressions. The ampersand must be preceded and followed by a space. The syntax shows an optional second ampersand and a third string expression. You can combine any number of strings with a single statement. Just remember to separate each pair of expressions with an ampersand.

Code example:

Private Sub Command1_Click()

Dim STR1, STR2 As String

STR1 = "mas Basy"

STR2 = " Belum Makan"

Form1.Print (STR1 & STR2)

End Sub

Reversing the Order of Characters in Strings

Visual Basic's new StrReverse() function enables you to completely reverse the order of a string. Its syntax is as follows:

strResult = StrReverse(strMyString)

In this syntax,

  • Text2 is the string returned from the function.
  • Text1 is the function name.

Visual Basic defaults all internal variables to valid values--numeric variables default to zero, and strings default to empty. The problem happens when you take a null data field from a database and assign it to an internal variable or when you perform a string function on the null data field.

In this version, a loop was required to step through each character in the string and then build the new string in reverse order. The code in Listing below delivers the same result with the new "StrReverse()" function, with no loops and only one simple command.

Code example:

Private Sub Form_Load()

Text1.Text = "Pitik Jago Kluruk 34X"

Text2.Text = ""

End Sub

Private Sub Command1_Click()

Text2.Text = StrReverse(Text1.Text)

End Sub


Jun 13, 2007

play wave file

Task : create play wave file

'Place in declaration or modul

Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

Public Function WaVe(pathfile As String)

SoundPlay = PlaySound(pathfile, 0&, &H1)

End Function

'Place this code

Private Sub Form_Load()

WaVe ("C:\WINDOWS\Media\windows xp startup.wav") 'path your wave file

End Sub

Create digital clock (VB)

Task : Create digital clock

Create label object

Name

Lbl_Clock

Caption

Clock

Create timer object with interval 1000
Place this code

Private Sub Timer1_Timer()
Me.Lbl_Clock.Caption = Format(Now(), "HH:mm:ss")

End Sub


Visual basic 6

Create popup menu

Task Create popup menu

First, you must create an menu in menu editor (Tool >> menu editor or press Ctrl + E)

For Example :
Caption : File
Name : mnFile

CODE

'For making an Popupmenu action

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button = 2 Then

PopupMenu mnFile

End If

End Sub

Private Sub mnFile_Click()
MsgBox "This is Popupmenu", vbInformation, "Info"

End Sub

Add an icon to the system tray

Task Add an icon to the system tray, and recognize when the icon is clicked or hoovered over

Declaration

'Declare
a user-defined variable to pass to the Shell_NotifyIcon

'function.

Private Type NOTIFYICONDATA cbSize As Long hWnd As Long uId As Long
uFlags As Long uCallBackMessage As Long hIcon As Long szTip As String *
64
End Type

'Declare the constants for the API function. These constants can be

'found in the header file Shellapi.h.

'The following constants are the messages sent to the

'Shell_NotifyIcon function to add, modify, or delete an icon from the

'taskbar status area.
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
'The following constant is the message sent when a mouse event occurs
'within the rectangular boundaries of the icon in the taskbar status
'area.
Private Const WM_MOUSEMOVE = &H200
'The following constants are the flags that indicate the valid
'members of the NOTIFYICONDATA data type.
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
'The following constants are used to determine the mouse input on the
'the icon in the taskbar status area.
'Left-click constants.

Private Const WM_LBUTTONDBLCLK = &H203 'Double-click
Private Const WM_LBUTTONDOWN = &H201 'Button down
Private Const WM_LBUTTONUP = &H202 'Button up

'Right-click constants.

Private Const WM_RBUTTONDBLCLK = &H206 'Double-click
Private Const WM_RBUTTONDOWN = &H204 'Button down
Private Const WM_RBUTTONUP = &H205 'Button up

'Declare the API function call.
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
'Dimension a variable as the user-defined data type.

Dim nid As NOTIFYICONDATA

CODE
' create a form named Form1
' add a commond dialog control named CommonDialog1
' add two command buttons named Command1 and Command2

Private Sub Command1_Click()
'Click this button to add an icon to the taskbar status area.

'Set the individual values of the NOTIFYICONDATA data type.

nid.cbSize = Len(nid)
nid.hwnd = Form1.hwnd
nid.uId = vbNull
nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
nid.uCallBackMessage = WM_MOUSEMOVE
nid.hIcon = Form1.Icon

nid.szTip = "Taskbar Status Area Sample Program" & vbNullChar

'Call the Shell_NotifyIcon function to add the icon to the taskbar
'status area.
Shell_NotifyIcon NIM_ADD, nid
End Sub

Private Sub Command2_Click()
'Click this button to delete the added icon from the taskbar

'status area by calling the Shell_NotifyIcon function.

Shell_NotifyIcon NIM_DELETE, nid

End Sub

Private Sub Form_Load()

'Set the captions of the command button when the form loads.
Command1.Caption = "Add an Icon"
Command2.Caption = "Delete Icon"

End Sub

Private Sub Form_Terminate()

'Delete the added icon from the taskbar status area when the

'program ends.

Shell_NotifyIcon NIM_DELETE, nid

End Sub

Private Sub Form_MouseMove _
(Button As Integer, _

Shift As Integer, _

X As Single, _

Y As Single)

'Event occurs when the mouse pointer is within the rectangular

'boundaries of the icon in the taskbar status area.

Dim msg As Long

Dim sFilter As String

msg = X / Screen.TwipsPerPixelX

Select Case msg

Case WM_LBUTTONDOWN

Case WM_LBUTTONUP

Case WM_LBUTTONDBLCLK

CommonDialog1.DialogTitle = "Select an Icon"

sFilter = "Icon Files (*.ico)|*.ico"

sFilter = sFilter & "|All Files (*.*)|*.*"

CommonDialog1.Filter = sFilter

CommonDialog1.ShowOpen

If CommonDialog1.FileName <> "" Then

Form1.Icon = LoadPicture(CommonDialog1.FileName)

nid.hIcon = Form1.Icon

Shell_NotifyIcon NIM_MODIFY, nid

End If

Case WM_RBUTTONDOWN

Dim ToolTipString As String

ToolTipString = InputBox("Enter the new ToolTip:", "Change ToolTip")

If ToolTipString <> "" Then

nid.szTip = ToolTipString & vbNullChar

Shell_NotifyIcon NIM_MODIFY, nid
End If
Case WM_RBUTTONUP
Case WM_RBUTTONDBLCLK

End Select
End Sub

HIDE Windows taskbar

Task:

HIDE Windows taskbar

Place on the Module
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Const SWP_HIDEWINDOW = &H80
Public Const SWP_SHOWWINDOW = &H40

Code
Dim rtn As Long

'hide the taskbar
rtn = FindWindow("Shell_traywnd", "") 'get the Window
Call SetWindowPos(rtn, 0, 0, 0, 0, 0, SWP_HIDEWINDOW) 'hide the Tasbar
'show th taskbar
rtn = FindWindow("Shell_traywnd", "") 'get the Window
Call SetWindowPos(rtn, 0, 0, 0, 0, 0, SWP_SHOWWINDOW) 'show the Taskbar

Create a circular form

Task: Create a circular form (VB)

Declarations

Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal

Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long

Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long,

ByVal hRgn As Long, ByVal bRedraw As Long) As Long

Code

'place this code in the form load event

Private Sub Form_Load()

Dim lngRegion As Long

Dim lngReturn As Long

Dim lngFormWidth As Long

Dim lngFormHeight As Long

lngFormWidth = Me.Width / Screen.TwipsPerPixelX

lngFormHeight = Me.Height / Screen.TwipsPerPixelY

lngRegion = CreateEllipticRgn(0, 0, lngFormWidth, lngFormHeight)

lngReturn = SetWindowRgn(Me.hWnd, lngRegion, True)

End Sub


freez windows

Visual Basic 6 Application
Task: freez windows

Declarations
Public Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

Put in command button
sub Freezcomputer (frm as form)
dim freez
freez = setparent (frm, frm)
end sub

Jun 11, 2007

Cara Daftar Google adsense

It's Quickly
kamu harus punya blog (Website) sendiri. Kalo belum punya Buruan Daftar disini.
Setelah kamu buat Blog masuk ke sini.
Tekan logo google adsense ... disamping
......................................
Tekan Sign Up NOw
Ikuti langkah perlangkah, Ingat ya untuk nulis alamat jangat sampai salah. Entar malah nyasar. terus kalo diminta masukkan Url , masukkan alamat blog kamu. Selamat mencoba

Alexa Rank