'-Begin-----------------------------------------------------------------
'-Directives----------------------------------------------------------
Option Strict On
'-Imports-------------------------------------------------------------
Imports System
Imports Microsoft.VisualBasic
'-VBCode--------------------------------------------------------------
Namespace VBCode
Public Class VB
Public Shared Function Hello1() As String
Return "Hello World!"
End Function
Public Function Hello2(ByVal Name As String) As String
Return "Hello " & Name & "!"
End Function
Public Sub Hello3(ByVal Name As String)
MsgBox(Name, MsgBoxStyle.OkOnly, "Hello")
End Sub
End Class
End Namespace
'-End-------------------------------------------------------------------
'-Begin-----------------------------------------------------------------
'-Directives----------------------------------------------------------
Option Explicit
On Error Resume Next
'-Constants-----------------------------------------------------------
Const OUTPUT_BUFFER = 2
Const ForReading = 1
Const FileName = "MyLib.vb"
'-Variables-----------------------------------------------------------
Dim FSO, File, VBCode
Dim PS, PSCode, PSOutput
'-Main----------------------------------------------------------------
'-Read the VBSharp code---------------------------------------------
Set FSO = CreateObject("Scripting.FileSystemObject")
If IsObject(FSO) Then
Set File = FSO.OpenTextFile(FileName, ForReading)
VBCode = File.ReadAll
File.Close
Set FSO = Nothing
Else
MsgBox "Can't create FileSystemObject", vbOkOnly, _
"Important hint"
End If
If VBCode <> "" Then
Set PS = CreateObject("SAPIEN.ActiveXPoSH")
If IsObject(PS) Then
PS.OutputMode = OUTPUT_BUFFER
If PS.Init(vbFalse) = 0 And PS.IsPowerShellInstalled() <> 0 Then
PSCode = "$VBCode = @""" & VBCode & """@;"
PSCode = PSCode & vbCrLf
PSCode = PSCode & "Add-Type -TypeDefinition $VBCode " & _
"-Language VisualBasic"
PSCode = PSCode & vbCrLf
PSCode = PSCode & "$VB = new-Object VBCode.VB"
PSCode = PSCode & vbCrLf
'-Execute the different modules-------------------------------
PSCode = PSCode & "[VBCode.VB]::Hello1()"
PSCode = PSCode & vbCrLf
PSCode = PSCode & "$VB.Hello2(""Stefan"")"
PSCode = PSCode & vbCrLf
PSCode = PSCode & "$VB.Hello3(""Stefan"")"
PS.Execute(PSCode)
MsgBox PS.OutputString(), vbOkOnly, "VB# results"
End If
Set PS = Nothing
Else
MsgBox "Can't create ActiveXPoSH", vbOkOnly, "Important hint"
End If
End If
'-End-------------------------------------------------------------------
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
12 | |
11 | |
7 | |
5 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |