Monday, July 25, 2011

How to create Reverse String?






Option Explicit

Private Sub Command1_Click()
Dim str As String
str = Text1.Text
Text2.Text = ReversString(str)
End Sub

Private Function ReversString(str As String) As String
ReversString = StrReverse(str)
End Function


'''''''''''''''''''''''''''''''''''''''''''''''''''''''' another function ''''''''''''''''''''''''''''''''''''''''''''''''''''

Option Explicit

Private Sub Command1_Click()
Dim str As String
str = Text1.Text
Text2.Text = ReversString(str)
End Sub

Public Function ReversString(ByVal InputString As String) _
  As String

Dim lLen As Long, lCtr As Long
Dim sChar As String
Dim sAns As String

lLen = Len(InputString)
For lCtr = lLen To 1 Step -1
    sChar = Mid(InputString, lCtr, 1)
    sAns = sAns & sChar
Next

ReversString = sAns

End Function

How to create a BACKSPACE key?



Option Explicit

Private Sub Command1_Click()
Dim pos As Long
Dim strLeft As String, strRight As String
With Text1
    If Len(.Text) Then
        pos = .SelStart
        If pos Then
            strLeft = Left$(.Text, pos - 1)
            strRight = Mid$(.Text, pos + 1)
            .Text = strLeft & strRight
            .SelStart = pos - 1
        End If
    End If
    .SetFocus
End With

End Sub

Wednesday, July 20, 2011

How to use unicode in vb?

Visual Basic में  Unicode (यूनीकोड ) का उपयोग .......
       
यूनीकोड प्रत्येक अक्षर के लिए एक विशेष नम्बर प्रदान करता है,
  • चाहे कोई भी प्लैटफॉर्म हो,
  • चाहे कोई भी प्रोग्राम हो,
  • चाहे कोई भी भाषा हो।

 इस प्रोजेक्ट से आप एक यूनीकोड  को इससे संबंधित  अक्षर में बदल सकते है ...




 'add component Microsoft Forms 2.0 Object Library
 'use textbox and scroll bar of this component 

Using Form


Option Explicit


Private Sub Form_Load()
    ScrollBar1.Min = 33
    ScrollBar1.Max = 65535

    'Font.Name = "Arial Unicode MS"
    'Font.Size = 12

    ScrollBar1_Change
End Sub

Private Sub ScrollBar1_Change()
   Dim sCodePoint

    txtDecimalNumber.Text = ScrollBar1.Value
    txtUnicodeNumber.Text = "U+" & Hex(txtDecimalNumber.Text)
    sCodePoint = ChrW(txtDecimalNumber.Text)

    txtCodePoint.Text = sCodePoint
   
End Sub

 
   

Tuesday, July 19, 2011

How to check status of Keybord?


Option Explicit
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Dim kstatus As Integer

Private Function CapsLockOn() As Boolean
    Dim xState As Integer
    xState = GetKeyState(vbKeyCapital)
    CapsLockOn = (xState = 1 Or xState = -127)
End Function

Private Sub Command1_Click()
Dim str As String
If CapsLockOn = True Then
    Select Case kstatus
        Case 1
            str = "Shift pressed"
        Case 2
            str = "Ctrl pressed"
        Case 4
            str = "Alt pressed"
        Case Else
            str = "No shift"
    End Select
    Text1.Text = "CapsLock is on" & " - " & str
Else
    Select Case kstatus
        Case 1
            str = "Shift pressed"
        Case 2
            str = "Ctrl pressed"
        Case 4
            str = "Alt pressed"
        Case Else
            str = "No shift"
    End Select
    Text1.Text = "CapsLock is off" & " - " & str
End If
End Sub


Private Sub Command1_KeyDown(KeyCode As Integer, Shift As Integer)
kstatus = Shift
End Sub

Private Sub Command1_KeyPress(KeyAscii As Integer)
    Dim str As String
    str = Chr(KeyAscii)
    Text1.Text = str
End Sub

Private Sub Command1_KeyUp(KeyCode As Integer, Shift As Integer)
kstatus = Shift
End Sub

Monday, July 18, 2011

How to fine a special lengh sting?


Visual Basic String Function : Mid

Purpose : The Mid functions the specified portion of a string expression.

Syntax :
Mid ( strExpression , ingStart [ , ingLength ] )
MidB ( strExpression , ingStart [ , ingLength ] )

strExpression : Specifies the string from which you want to return a substring.
ingStart : Specifies the starting position for the returned substring.
ingLength : Specifies the number of characters of the returned substring.

Dim strGood as String
Dim strBye as String , strDolly as String
strGood = "Good bye, Arvind"
strBye = Mid ( strGood, 6 , 3 )
strDolly = Mid ( strGood , 11 )

The first example uses the Mid function to assign the value " bye " to the variable strBye. In the second example, the length parameter is omitted so the string returned starts where indicated and continues for the balance of then length of strGood . Therefore , the variable strDolly is assigned the value " Arvind "
 
 
Using this in Form
Private Sub Command1_Click()
Dim i As Integer
Dim strS As String
Dim strD As String
strS = Text1.Text
i = Len(Text1.Text)
strD = Mid(strS, 1, i - 1)
Text2.Text = strD
End Sub
 

How to Create a DataReport by Recordset?


Inculcated References file : Microsoft ActiveX Data Objects 2.0 Library

Using Module

Option Explicit

Public cn As New ADODB.Connection

Sub Main()

cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\NWIND.mdb;Persist Security Info=False"
cn.Open
Form1.Show
End Sub

Using Form

Option Explicit

Private Sub Command1_Click()

Dim rs As New ADODB.Recordset
rs.ActiveConnection = cn
rs.CursorType = adOpenStatic
rs.CursorLocation = adUseServer
rs.Open "SELECT * FROM Customers"

If rs.RecordCount > 0 Then
Set DataReport1.DataSource = rs
DataReport1.Show
End If

End Sub

Using DataReport

In Detail section
Use a text box and it's Properties DataField :CompanyName

How to Create a DataReport by DataEnvironment?

See on this pictures and using this







Sunday, July 17, 2011

How to split a string on a specified delimiter?


Visual Basic String Function : Split

purpose : Split examines an expression and parses out substrings based on a specified delimiter.The substrings that are parsed out are placed into a zero-based array.

Syntax :
Split ( expression [ , delimiter [ , count [ , compare ] ] ] )

expression : String value to be processed.
delimiter : String value identifying one substring from another. If this value is omitted, a blank space ( " " ) is used a s the delimiter.
count : Indicator how many time through the expression the function loops . if this value is omitted, the entire expression is processed.
compare : Indicator for the type of comparison between the delimiter and the expression.

0 : vbBinaryCompare
1 : vbTextCompare
2 : vbDatabasecompare

sName = Split ( "Mr. Arvind Nahar")

the result of the Split function crates a one-dimensional array in sName, where
sName(0) = "Mr."
sName(1) = "Arvind"
sName(2) = "Nahar"
 
 
 
Option Explicit

Private Sub Command1_Click()
Dim i As Integer
Dim sName() As String
Dim str As String
str = Text1.Text
sName = Split(str, ",")

For i = 0 To UBound(sName)
    List1.AddItem sName(i)
Next i
End Sub
 

Friday, July 15, 2011

How to get font folder path?

Using this in Module

Option Explicit

Public Const SFID_FONTS = &H14
Public Function GetSpecialFolderPath(SpecialFolder) As String
  Dim oShlApp, oFolder, oFItem
 
  Set oShlApp = CreateObject("Shell.Application")
  Set oFolder = oShlApp.Namespace(SpecialFolder)
  If Not oFolder Is Nothing Then
     Set oFItem = oFolder.Self
     GetSpecialFolderPath = oFItem.Path
  End If
End Function





Using in this in Form

Option Explicit
Private FontFolder As String

Private Sub Command1_Click()
FontFolder = GetSpecialFolderPath(SFID_FONTS)
MsgBox FontFolder
End Sub

How to get font folder path?



Option Explicit
Private FontFolder As String

Private Sub Command1_Click()
FontFolder = Environ("WINDIR") & "\Fonts\"
MsgBox FontFolder
End Sub

Sunday, July 10, 2011

How the project always on top?



'Set window to be top most (always on top)
'This code will allow you to toggle your window as
'being always on top or not always 'on top,
'as seen in things like AIM and HTML Help.
Option Explicit

    'declare constants:
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2

Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40

    'declare API:
Private Declare Sub 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)

Private Sub Command1_Click()
      'set topmost:
    SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or _
    SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub

Private Sub Command2_Click()
      'set not topmost:
    SetWindowPos Me.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or _
    SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub

Private Sub Form_Load()
      'project requires 2 commandbuttons:
    Command1.Caption = "Top Most"
    Command2.Caption = "Not Top Most"
End Sub

How to run a exe file?






Option Explicit

'I have made the code to run the calculator, which
' is present in every Windows Based PC.
'the command button  click() event triggers
'the application to run.

'General Syntax is
'RetVal = Shell([Pathname of EXE], [WindowStyle As vbAppWinStyle = vbMinimisedFocus])

'----------------CODE--------------------
Private Sub Command1_Click()
Dim RetVal
RetVal = Shell("C:\WINDOWS\System32\calc.exe", 1)    ' Run Calculator.
End Sub

The Shell function runs a specified .EXE , .COM , .BAT OR .PIF  program.

A% = Shell ("calc.exe")

B% = Shell ("C:\WINDOWS\System32\calc.exe", 1)

VbHide :0
VbNormalFocus :1
VbMinimzedFocus :2
VbMaximizedFocus :3
VbNormalNoFocus :4
VbMinimizedNoFocus :6

How to get file list in a folder?



Option Explicit

Private Sub Command1_Click()
Dim strFile
strFile = Dir$(App.Path & "\*.*", vbNormal)
Do While strFile <> vbNullString
    Debug.Print strFile
    strFile = Dir$()
Loop
End Sub