Microsoft Office Excel ® Kod Kılavuzu

Microsoft Office Excel® Code Guide

20 Ocak 2011 Perşembe

Microsoft® VBScript and Object Expressions





'UserForm1

'A) VBProject References List
     'Name: VBA, Description: Visual Basic For Applications, Full Path: C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6.DLL
     'Name: Excel, Description: Microsoft Excel 11.0 Object Library, Full Path: C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE
     'Name: stdole, Description: OLE Automation, Full Path: C:\WINDOWS\system32\stdole2.tlb
     'Name: Office, Description: Microsoft Office 11.0 Object Library, Full Path: C:\Program Files\Common Files\Microsoft Shared\OFFICE11\MSO.DLL
     'Name: MSForms, Description: Microsoft Forms 2.0 Object Library, Full Path: C:\WINDOWS\system32\FM20.DLL
     'Name: SpeechLib, Description: Microsoft Speech Object Library, Full Path: C:\Program Files\Common Files\Microsoft Shared\Speech\sapi.dll [Picture:1]
'B) Addition Tools on UserForm1
     'Image1, Label1, Label2
     'TextBox1, TextBox2, ListBox1
'C) Microsoft VBScript and Object Expressions
     'A. Objects
          'a. VBScript RegExp Object
               'a1. Properties: Pattern, Methods: Test (search-string)
               'a2. Properties: IgnoreCase, Methods : Replace (search-string, replace-string)
               'a3. Properties: Global, Methods : Execute (search-string)
                     'Pattern - A string that is used to define the regular expression. This must be set before use of the regular expression object. Patterns are described in more detail below.
                     'IgnoreCase - A Boolean property that indicates if the regular expression should be tested against all possible matches in a string. By default, IgnoreCase is set to False.
                     'Global - A Boolean property that indicates if the regular expression should be tested against all possible matches in a string. By default, Global is set to False.
                     'Test (string) - The Test method takes a string as its argument and returns True if the regular expression can successfully be matched against the string, otherwise False is returned.
                     'Replace (search-string, replace-string) - The Replace method takes 2 strings as its arguments. If it is able to successfully match the regular expression in the search-string, then it replaces that match with the replace-string, and the new string is returned. If no matches were found, then the original search-string is returned.
                     'Execute (search-string) - The Execute method works like Replace, except that it returns               'a Matches collection object, containing a Match object for each successful match. It doesn't modify the original string.
          'b. VBScript Matches Collection Object
               'b1. Properties: Count
               'b2. Properties: Item
                     'Count - A read-only value that contains the number of Match objects in the collection.
                     'Item - A read-only value that enables Match objects to be randomly accessed from the Matches collection object. The Match objects may also be incrementally accessed from the Matches collection object, using a For-Next loop.
         'c. VBScript Match Object
              'c1. Properties: FirstIndex
              'c2. Properties: Length
              'c3. Properties: Value
                    'FirstIndex - A read-only value that contains the position within the original string where the match occurred. This index uses a zero-based offset to record positions, meaning that the first position in a string is 0.
                    'Length - A read-only value that contains the total length of the matched string.
                    'Value - A read-only value that contains the matched value or text. It is also the default value when accessing the Match object.
     'B. Pattern Options
          'a. Position Matching [Position matching involves the use of the ^ and $ to search for beginning or ending of strings. Setting the pattern property to "^VBScript" will only successfully match "VBScript is cool." But it will fail to match "I like VBScript."]
               'a1. Symbol: ^, Function: Only match the beginning of a string. "^A" matches first "A" in "An A+ for Anita."
               'a2. Symbol: $, Function: Only match the ending of a string. "tquot; matches the last "t" in "A cat in the hat"
               'a3. Symbol: \b, Function: Matches any word boundary "ly\b" matches "ly" in "possibly tomorrow."
               'a4. Symbol: \B, Function: Matches any non-word boundary
          'b. Literals [Literals can be taken to mean alphanumeric characters, ACSII, octal characters, hexadecimal characters, UNICODE, or special escaped characters. Since some characters have special meanings, we must escape them. To match these special characters, we precede them with a "\" in a regular expression.]
              'b1. Symbol: Alphanumeric, Function: Matches alphabetical and numerical characters literally.
              'b2. Symbol: \n, Function: Matches a new line
              'b3. Symbol: \f, Function: Matches a form feed
              'b4. Symbol: \r, Function: Matches carriage return
              'b5. Symbol: \t, Function: Matches horizontal tab
              'b6. Symbol: \v, Function: Matches vertical tab
              'b7. Symbol: \?, Function: Matches ?
              'b8. Symbol: \*, Function: Matches *
              'b9. Symbol: \+, Function: Matches +
              'b10. Symbol: \., Function: Matches .
              'b11. Symbol: \, Function: Matches
              'b12. Symbol: \{, Function: Matches {
              'b13. Symbol: \}, Function: Matches }
              'b14. Symbol: \\, Function: Matches \
              'b15. Symbol: \[, Function: Matches [
              'b16. Symbol: \], Function: Matches ]
              'b17. Symbol: \(, Function: Matches (
              'b18. Symbol: \), Function: Matches )
              'b19. Symbol: \xxx, Function: Matches the ASCII character expressed by the octal number xxx.
              'b20. Symbol: \xxx, Function: "\50" matches "(" or chr (40).
              'b21. Symbol: \xdd, Function: Matches the ASCII character expressed by the hex number dd.
              'b22. Symbol: \xdd, Function: "\x28" matches "(" or chr (40).
              'b23. Symbol: \uxxxx, Function: Matches the ASCII character expressed by the UNICODE xxxx.
               'b24. Symbol: \uxxxx, Function: "\u00A3" matches "£".
           'c. Character Classes [Character classes enable customized grouping by putting expressions within [] braces. A negated character class may be created by placing ^ as the first character inside the []. Also, a dash can be used to relate a scope of characters. For example, the regular expression "[^a-zA-Z0-9]" matches everything except alphanumeric characters. In addition, some common character sets are bundled as an escape plus a letter.]
               'c1. Symbol: [xyz], Function: Match any one character enclosed in the character set., "[a-e]" matches "b" in "basketball".
               'c2. Symbol: [^xyz], Function: Match any one character not enclosed in the character set., "[^a-e]" matches "s" in "basketball".
               'c3. Symbol: ., Function: Match any character except \n.
               'c4. Symbol: \w, Function: Match any word character. Equivalent to [a-zA-Z_0-9].
               'c5. Symbol: \W, Function: Match any non-word character. Equivalent to [^a-zA-Z_0-9].
               'c6. Symbol: \d, Function: Match any digit. Equivalent to [0-9].
               'c7. Symbol: \D, Function: Match any non-digit. Equivalent to [^0-9].
               'c8. Symbol: \s, Function: Match any space character. Equivalent to [ \t\r\n\v\f].
               'c9. Symbol: \S, Function: Match any non-space character. Equivalent to [^ \t\r\n\v\f].
          'd. Repetition [Repetition allows multiple searches on the clause within the regular expression. By using repetition matching, we can specify the number of times an element may be repeated in a regular expression.]
               'd1. Symbol: {x}, Function: Match exactly x occurrences of a regular expression., "\d{5}" matches 5 digits.
              'd2. Symbol: {x,}, Function: Match x or more occurrences of a regular expression., "\s{2,}" matches at least 2 space characters.
              'd3. Symbol: {x,y}, Function: Matches x to y number of occurrences of a regular expression., "\d{2,3}" matches at least 2 but no more than 3 digits.
              'd4. Symbol: ?, Function: Match zero or one occurrences. Equivalent to {0,1}., "a\s?b" matches "ab" or "a b".
              'd5. Symbol: *, Function: Match zero or more occurrences. Equivalent to {0,}.
              'd6. Symbol: +, Function: Match one or more occurrences. Equivalent to {1,}.
         'e. Alternation & Grouping [Alternation and grouping is used to develop more complex regular expressions. Using alternation and grouping techniques can create intricate clauses within a regular expression, and offer more flexibility and control.]
             'e1. Symbol: (), Function: Grouping a clause to create a clause. May be nested. "(ab)?(c)" matches "abc" or "c".
             'e2. Symbol: , Function: Alternation combines clauses into one regular expression and then matches any of the individual clauses., "(ab)(cd)(ef)" matches "ab" or "cd" or "ef".
         'f. BackReferences [Backreferences enable the programmer to refer back to a portion of the regular expression. This is done by use of parenthesis and the backslash (\) character followed by a single digit. The first parenthesis clause is referred by \1, the second by \2, etc.]
             'f1. Symbol: ()\n, Function: Matches a clause as numbered by the left parenthesis., "(\w+)\s+\1" matches any word that occurs twice in a row, such as "hubba hubba."
     'C. Example
           '"^\s*((\$\s?)(£\s?))?((\d+(\.(\d\d)?)?)(\.\d\d))\s*(UKGBPGBUSAUSUSD)?)\s*quot;
           '"^\s*…" and "…\s*quot; - means that there can be any number of leading and end space characters, and the input must be on a line by itself
           '"((\$\s?)(£\s?))?" - means an optional $ or £ sign followed by an optional space
           '"((\d+(\.(\d\d)?)?)(\.\d\d))" - searches for at least one digit, followed by an optional decimal and two digits (which are optional) or a decimal and two digits. This means that input such as 6., 23.33, .88 are all allowed, but 5.5 is not.
           '"\s*(UKGBPGBUSAUSUSD)?" - means that any number of space characters are valid followed by optional and acceptable arguments to the string.

Option Explicit
Private i As Single
Private No As Double, Uzunluk As Double
Private Metin As String, Kelime As String
Private ObjRegExp As Object
Private Eleman, Küme, Change
Private WithEvents Seslendirme As SpVoice
Private Sub UserForm_Initialize()
     On Error Resume Next
     Me.Caption = "[PBİD®] Microsoft VBScript and Object Expressions"
     Call EkranDüzenle
     Call VeriDüzenle
     Set Seslendirme = New SpVoice
End Sub
Private Sub ListBox1_Click()
     On Error Resume Next
     No = ListBox1.ListIndex
     Uzunluk = (ListBox1.List(No, 2) - ListBox1.List(No, 0))
     Kelime = ListBox1.List(No, 1)
     TextBox1.SelStart = ListBox1.List(No, 0)
     TextBox1.SelLength = Uzunluk
     TextBox1.SetFocus
     TextBox2.SelStart = ListBox1.List(No, 0)
     TextBox2.SelLength = Uzunluk
     TextBox2.SelText = ListBox1.List(No, 1)
     Seslendirme.Speak Kelime, SVSFlagsAsync
     VBA.DoEvents
End Sub
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
     On Error Resume Next
     For i = 0 To (ListBox1.ListCount - 1)
          No = i
          Uzunluk = (ListBox1.List(No, 2) - ListBox1.List(No, 0))
          Kelime = ListBox1.List(No, 1)
          TextBox1.SelStart = ListBox1.List(No, 0)
          TextBox1.SelLength = Uzunluk
          TextBox1.SetFocus
          DoEvents
          TextBox2.SelStart = ListBox1.List(No, 0)
          TextBox2.SelLength = Uzunluk
          TextBox2.SelText = ListBox1.List(No, 1)
          Seslendirme.Speak Kelime, SVSFlagsAsync
          DoEvents
     Next i
End Sub
Private Sub EkranDüzenle()
     On Error Resume Next
     With Me
          .Height = 256
          .Width = 426
          '.Picture = LoadPicture("C:\Documents and Settings\Administrator\Belgelerim\Mustafa ULUSARAÇ\VectorBackround.jpg")
          .Picture = Resim(URL1)
          .PictureAlignment = fmPictureAlignmentTopLeft
          .PictureSizeMode = fmPictureSizeModeStretch
          .PictureTiling = False
          With Image1
               .Left = 6
               .Top = 6
               .Height = 24
               .Width = 24
               .BorderColor = vbWhite
               .BorderStyle = fmBorderStyleSingle
               .BackStyle = fmBackStyleTransparent
               '.Picture = LoadPicture("C:\Documents and Settings\Administrator\Belgelerim\Mustafa ULUSARAÇ\PBİD.ico")
               .Picture = Resim(URL2)
               .PictureAlignment = fmPictureAlignmentCenter
               .PictureSizeMode = fmPictureSizeModeClip
               .PictureTiling = False
          End With
          With Label1
               .Top = 6
               .Left = 36
               .Height = 12
               .Width = 228
               .AutoSize = False
               .BackStyle = fmBackStyleTransparent
               .BorderStyle = fmBorderStyleNone
               .Caption = "Mustafa ULUSARAÇ"
               .Font.Bold = True
               .ForeColor = vbBlue
               .SpecialEffect = fmSpecialEffectFlat
               .TextAlign = fmTextAlignLeft
          End With
          With Label2
               .Top = 18
               .Left = 36
               .Height = 12
               .Width = 228
               .AutoSize = False
               .BackStyle = fmBackStyleTransparent
               .BorderStyle = fmBorderStyleNone
               .Caption = "01ulusarac@superonline.com"
               .Font.Bold = True
               .ForeColor = vbBlue
               .SpecialEffect = fmSpecialEffectFlat
               .TextAlign = fmTextAlignLeft
          End With
          With TextBox1
               .Left = 6
               .Top = 36
               .Height = 93.75
               .Width = 258
               .BackStyle = fmBackStyleTransparent
               .AutoTab = True
               .AutoSize = False
               .AutoWordSelect = True
               .BorderStyle = fmBorderStyleSingle
               .BorderColor = &HFFFF80
               .Font.Bold = False
               .ForeColor = vbBlue
               .Locked = True
               .MultiLine = True
               .ScrollBars = fmScrollBarsBoth
               .SpecialEffect = fmSpecialEffectFlat
          End With
          With TextBox2
               .Left = 6
               .Top = 133
               .Height = 93.75
               .Width = 258
               .BackStyle = fmBackStyleTransparent
               .AutoTab = True
               .AutoSize = False
               .AutoWordSelect = True
               .BorderStyle = fmBorderStyleSingle
               .BorderColor = &HFFFF80
               .Font.Bold = False
               .ForeColor = &H404000
               .Locked = True
               .MultiLine = True
               .ScrollBars = fmScrollBarsBoth
               .SpecialEffect = fmSpecialEffectFlat
          End With
          With ListBox1
               .Left = 267
               .Top = 36
               .Height = (TextBox2.Top + TextBox2.Height) - TextBox1.Top
               .Width = 150
               .BorderColor = &HFFFF80
               .BorderStyle = fmBorderStyleSingle
               .BackColor = vbWhite
               .ColumnCount = 3
               .ColumnWidths = "36;72;36"
               .ForeColor = vbBlue
               .ListStyle = fmListStylePlain
               .Locked = False
               .MultiSelect = fmMultiSelectSingle
               .SpecialEffect = fmSpecialEffectFlat
          End With
     End With
End Sub
Private Sub VeriDüzenle()
     On Error Resume Next
     TextBox1.Text = "VBScript Regular Expressions Regular expression reference and examples for VBScript. Regular expressions in VBScript are two words that can bring many to their knees, weeping, but they are not as scary as some would have you believe. With their roots in Perl, regular expressions in VBScript use similar syntax, and the chances are that you may already be familiar with the concepts here if you have played with regular expression matching before."
     Metin = TextBox1.Text
     Set ObjRegExp = VBA.CreateObject("VBScript.RegExp")
     With ObjRegExp
          .Pattern = "\w+"
          .IgnoreCase = False
          .Global = True
          Set Küme = .Execute(Metin)
     End With
     No = 0
     For Each Eleman In Küme
          ListBox1.AddItem (Eleman.FirstIndex & " ")
          ListBox1.List(No, 1) = Eleman.Value
          ListBox1.List(No, 2) = VBA.Len(Eleman.Value) + (Eleman.FirstIndex & " ")
          No = No + 1
     Next
     For i = 0 To ListBox1.List((No - 1), 2)
          TextBox2.Text = TextBox2.Text & "_" '" "
     Next i
End Sub

'Module1

Option Explicit
Public Declare Function CLSIDFromString Lib "ole32" (ByVal lpstrCLSID As Long, lpCLSID As Any) As Long
Public Declare Function OleLoadPicturePath Lib "oleaut32" (ByVal szURLorPath As Long, ByVal punkCaller As Long, ByVal dwReserved As Long, ByVal clrReserved As OLE_COLOR, ByRef riid As Any, ByRef ppvRet As Any) As Long
Public IPic(15) As Byte
Public Const ClsID As Variant = "{7BF80980-BF32-101A-8BBB-00AA00300CAB}" 'It may take a few seconds, please wait.Public URL As String
Public Const URL1 As String = "http://2.bp.blogspot.com/_hsHTxo_5L8E/S7rn6KHVfNI/AAAAAAAACRs/fxVMg9YGzb4/s1600/VectorBackround.jpg" 'Microsoft Office Excel® Kod Kılavuzu [UserFormBackround]
Public Const URL2 As String = "http://2.bp.blogspot.com/_hsHTxo_5L8E/S78EbvJyhRI/AAAAAAAACS0/txbOQ1qubg8/s1600/PB%C4%B0D_jpg.jpg" 'Microsoft Office Excel® Kod Kılavuzu [PBİD Icon]
Sub FormAç() 'Open UserForm
     On Error Resume Next
     UserForm1.Show 0
End Sub
Public Function Resim(URL) As Picture 'Picture load frome web address...
     On Error Resume Next
     CLSIDFromString StrPtr(ClsID), IPic(0)
     OleLoadPicturePath StrPtr(URL), 0&, 0&, 0&, IPic(0), Resim
End Function
'Sub ReferenceList()
     'On Error Resume Next
     'Dim Eleman, No
     'No = 1
     'For Each Eleman In ThisWorkbook.VBProject.References
          'Cells(No, 1) = "Name: "
          'Cells(No, 2) = Eleman.Name
          'Cells(No, 3) = ", Description: "
          'Cells(No, 4) = Eleman.Description
          'Cells(No, 5) = ", Full Path: "
          'Cells(No, 6) = Eleman.FullPath
          'No = No + 1
     'Next Eleman
'End Sub

Hiç yorum yok:

Blog Arşivi

Bu gadget'ta bir hata oluştu

Bu Blogda Ara

Contributor

Contributor
Mustafa ULUSARAÇ İstanbul, TÜRKİYE
free counters
T. C. Central Bank Indicative Exchange Rates
Currency Exchange Rate Widget,Currency Converter Widget
Borsa İstanbul