Thursday, June 30, 2011

How to search in List box when use Text box

  

Use this API in Modual 


Public Declare Function SendMessage Lib "user32" Alias "SendMessageA"  _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As String, lParam As Any) As Long

Global Const LB_FINDSTRING = &H18F

Use in Form

Private Sub Text1_Change()
On Error Resume Next

List1.ListIndex = SendMessage(List1.hWnd, LB_FINDSTRING, Text1, ByVal Text1.Text)

End Sub
 

How to hyper link in a Label


Use this API and Function in Modual 

Option Explicit

Private Declare Function ShellExecute _
Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hWnd _
As Long, ByVal lpOperation _
As String, ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Public Sub HyperJump(ByVal URL As String)
Call ShellExecute(0&, _
vbNullString, URL, _
vbNullString, vbNullString, _
vbNormalFocus)
End Sub

Use in Form

Option Explicit

Private m_Active As Boolean
Private Sub Form_Load()
Label1.Caption = "http://www.vbcode.in"
Label1.Tag = Label1.Caption
End Sub

Private Sub Label1_Click()
With Label1
Call HyperJump(.Tag)
.Font.Underline = False
.ForeColor = vbBlack
End With

End Sub

How to Line Break or new line in Text box






'Text3.MultiLine = True

Private Sub Command1_Click()
Dim a, b
a = Text1
b = Text2
'Text3 = a & vbNewLine & b
Text3 = a & vbCrLf & b


End Sub

Sunday, June 26, 2011

How clear all text in all text box in a form


 Use this code in module


Public Sub clearAll(currentForm As Form)
    Dim ctl As Control
   
    For Each ctl In currentForm.Controls
        If TypeOf ctl Is TextBox Then ctl.Text = ""
    Next
End Sub

Use in Form



Private Sub Form_Load()
'
Call clearAll(Me)
End Sub

Thursday, June 23, 2011

How to Spech by "Text to Spech" in VB Project

Option Explicit

Private Sub Command1_Click()
Dim speech
speech = "Arvind Nahar"
Dim ObjTextToSpeach As Object
Set ObjTextToSpeach = CreateObject("SAPI.spVoice")

ObjTextToSpeach.speak speech
End Sub



How to use Office Assistant in VB project





Use this Code in Module

Option Explicit

Public myCharacter      As IAgentCtlCharacterEx 'ms agent



Public Sub Merlin(Optional ByVal Msg As String, Optional ByVal Animation As String = "Explain")
    On Error Resume Next
    If myCharacter.Visible Then
        myCharacter.StopAll
        myCharacter.Play Animation
       
        If Not Msg = "" Then myCharacter.Speak Msg
    End If
End Sub

Public Sub showMerlin()
        myCharacter.Show
       
        'to botton right corner
        myCharacter.MoveTo 850, 550
End Sub

Use this code in Form

Option Explicit

Private Sub Command1_Click()
Merlin "Hello"

End Sub

Private Sub Form_Load()
    MyAgent.Characters.Load "Merlin", "Merlin.Acs"
    Set myCharacter = MyAgent.Characters("Merlin")
    myCharacter.SoundEffectsOn = True
   
    showMerlin
End Sub




Monday, June 20, 2011

How to use vertical scroll bar






Option Explicit

Private Sub ConfigureScrollBarsLabel()
    If Label1.Height > Picture1.ScaleHeight Then
        VScroll1.Visible = True
        VScroll1.Min = 0
        VScroll1.Max = Picture1.ScaleHeight - Label1.Height
        VScroll1.LargeChange = Picture1.ScaleHeight
        VScroll1.SmallChange = Picture1.ScaleHeight / 5

        Label1.Top = VScroll1.Value
    End If
End Sub

Private Sub Text1_Change()
Label1.Caption = Text1.Text
ConfigureScrollBarsLabel
End Sub

Private Sub VScroll1_Change()
Label1.Top = VScroll1.Value
End Sub

Private Sub VScroll1_Scroll()
Label1.Top = VScroll1.Value
End Sub

Sunday, June 19, 2011

A Function : Number or Characters filter


Use in Modual :

Option Explicit

Public Const gstrNUMERIC_DIGITS As String = "0123456789"
Public Const gstrUPPER_ALPHA_PLUS As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ,'-"

Public gblnPopulating As Boolean
Public Function ValidKey(pintKeyValue As Integer, _
pstrSearchString As String) As Integer '------------------------------------------------------------------------

' Common function to filter out keyboard characters passed to this
' function from KeyPress events.
'
' Typical call:
' KeyAscii = ValidKey(KeyAscii, gstrNUMERIC_DIGITS)
'

If pintKeyValue < 32 _
Or InStr(pstrSearchString, Chr$(pintKeyValue)) > 0 Then
'Do nothing - i.e., accept the control character or any key
' in the search string passed to this function ...
Else
'cancel (do not accept) any other key ...
pintKeyValue = 0
End If

ValidKey = pintKeyValue

End Function

Private Sub Text1_KeyPress(KeyAscii As Integer)
Call ValidKey(KeyAscii, gstrNUMERIC_DIGITS)
End Sub

इस function मे मुझे एक problem नजर आई | copy past करने पर कोई भी तरह कि value text box मे fill कर सकते है
function मे Error handling आपनी सुविधा के अनुसार coding करे |