Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1512

vb6 /vba call .net com object CLRHost

$
0
0
GitHub - jet2jet/vb2clr: The helper class for Visual Basic for Applications (VBA) 7.0, providing access to CLR (.NET Framework) assemblies and classes.
Code:

https://github.com/jet2jet/vb2clr
Visual Basic for Applications (VBA) 7.0 The helper class CLRHost, which provides access to the CLR (.NET Framework) assembly and classes.
(Study success: conversion to VB6)

'C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.tlb
'C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscoree.tlb


'delete PtrSafe tag
'change info
'CLngPtr to clng
'LongPtr to long

Code:

Sub Main()
  RegexSample
End Sub
Public Sub RegexSample()
    Dim host As New CLRHost
    Call host.Initialize(False)

    On Error Resume Next
    Dim asmSys As mscorlib.Assembly
    Set asmSys = host.CLRLoadAssembly("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")

    Dim cobjRegex As mscorlib.Object
    Set cobjRegex = host.CLRCreateObjectWithParams("System.Text.RegularExpressions.Regex", "([0-9])+")

    Dim cobjColl As mscorlib.Object
    Set cobjColl = host.CLRInvokeMethod(cobjRegex, "Matches", "10 20 50 1234 98765")

    Dim vMatch As Variant
    For Each vMatch In host.ToEnumerable(cobjColl)
        Dim cobjMatch As mscorlib.Object
        Set cobjMatch = vMatch
        Debug.Print "Matches: "; host.CLRProperty(cobjMatch, "Value")
        Set cobjMatch = Nothing
    Next vMatch
    vMatch = Empty
    Set cobjColl = Nothing
    Set cobjRegex = Nothing

    'Call host.Terminate
    Set host = Nothing
End Sub

vba transfer temporarily for a specific task. NET Object @VB Utilization. NET Components (Japan) Part 1-Programming Field, [powerful]
https://www.pg-fl.jp/program/tips/vb2clr1.htm
Use VBA Part 2 [Call] -CLR in the programming field (. NET)
https://www.pg-fl.jp/program/tips/vb2clr2.htm
Use CLR (. NET) Part 3 [Advanced Edition] in VBA-programming areas
https://www.pg-fl.jp/program/tips/vb2clr3.htm

Viewing all articles
Browse latest Browse all 1512

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>