Click here to Skip to main content
15,900,378 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionVB Script in word 2007 Pin
Niungareamit13-Jan-10 22:10
Niungareamit13-Jan-10 22:10 
AnswerRe: VB Script in word 2007 Pin
Dalek Dave13-Jan-10 22:32
professionalDalek Dave13-Jan-10 22:32 
GeneralRe: VB Script in word 2007 Pin
Niungareamit13-Jan-10 22:35
Niungareamit13-Jan-10 22:35 
QuestionI need to pass an array from VBScript to VB.Net COM .DLL Pin
Hrizip13-Jan-10 21:25
Hrizip13-Jan-10 21:25 
AnswerRe: I need to pass an array from VBScript to VB.Net COM .DLL Pin
DaveAuld13-Jan-10 23:38
professionalDaveAuld13-Jan-10 23:38 
GeneralRe: I need to pass an array from VBScript to VB.Net COM .DLL Pin
Hrizip14-Jan-10 2:28
Hrizip14-Jan-10 2:28 
GeneralRe: I need to pass an array from VBScript to VB.Net COM .DLL Pin
isaacchk2-Aug-10 23:12
isaacchk2-Aug-10 23:12 
GeneralRe: I need to pass an array from VBScript to VB.Net COM .DLL Pin
Hrizip3-Aug-10 2:54
Hrizip3-Aug-10 2:54 
Double bracketing is not necessary, its just that I read *somewhere* that it does something, but at this point I dont remember what, and I remember that the thing works just fine with single bracketing.

Heres a code snippet to play with;

So, make a new project of type class library, make it com visible and interoperable

Paste this

Imports System.IO
Imports System.Math
Imports System.Object
Imports System.Threading
Imports System.Runtime.InteropServices
Imports System.Reflection
Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices.RegistrationServices
Imports System.Xml
Imports System.Xml.XPath


Public Class Class1 ' Main Class, declared as *com interopable*, type of project : "type library", meaning it will need to be registered in windows, and type library will need to be exported
    ' you wlll need to make a batch file with the following commands in it, to check whether it has been introduced into the global assembly cache, browse your hard drive
    ' to windows/assembly and look for an entry named "Test", if it *is* listed there, then it will work.

    'regasm Test.dll
    'regasm Test.dll /tlb:Test.dll
    'regasm Test.dll /codebase /tlb:Test.dll 
    'gacutil /i Test.dll

    ' Put it into the folder where you already put test.dll, along with *regasm.exe* and *gacutil.exe* (obligatory) and then execute the bat file
    ' The type library is now registered and you can call its methods (the only working method is called "Method1")

    Public Shared RezultatiY   ' vb.NET array to hold our data


    Public Function MethodNumber(ByRef numberz)   ' Fetch the array of type integer or double (will be converted to double)

        RezultatiY = Nothing
        Dim Arrayzz() As Object
        Arrayzz = Nothing
        Arrayzz = numberz

        Dim NumberOfElements As Integer = UBound(numberz) - 1 ' We need to find the total number of elements
        ReDim RezultatiY(NumberOfElements) ' And then redimension our array to that number of elements

        For i As Integer = 0 To UBound(Arrayzz) - 1
            Dim Temp As Double = CDbl(Arrayzz(i))
            RezultatiY(i) = CDbl(Temp)
            My.Computer.FileSystem.WriteAllText("C:\Temp\TestingIntegersAndDoubles.txt", RezultatiY(i) & " " & i & " " & " " & RezultatiY(i).GetType.ToString & vbCrLf, True)
        Next

    End Function

    Public Function MethodString(ByRef Words)   ' Fetch the array of type string

        RezultatiY = Nothing
        Dim Arrayzz() As Object
        Arrayzz = Nothing
        Arrayzz = Words

        Dim NumberOfElements As Integer = UBound(Words) - 1
        ReDim RezultatiY(NumberOfElements)

        For i As Integer = 0 To UBound(Arrayzz) - 1
            Dim Temp As String = CStr(Arrayzz(i))
            RezultatiY(i) = CStr(Temp)
            My.Computer.FileSystem.WriteAllText("C:\Temp\TestingStrings.txt", RezultatiY(i) & " " & i & " " & " " & RezultatiY(i).GetType.ToString & vbCrLf, True)
        Next

    End Function

    Public Function MethodChars(ByRef Characters)   ' Fetch the array of type characters

        RezultatiY = Nothing
        Dim Arrayzz() As Object
        Arrayzz = Nothing
        Arrayzz = Characters

        Dim NumberOfElements As Integer = UBound(Characters) - 1
        ReDim RezultatiY(NumberOfElements)

        For i As Integer = 0 To UBound(Arrayzz) - 1
            Dim Temp As String = CChar(Arrayzz(i))
            RezultatiY(i) = CChar(Temp)
            My.Computer.FileSystem.WriteAllText("C:\Temp\TestingChars.txt", RezultatiY(i) & " " & i & " " & " " & RezultatiY(i).GetType.ToString & vbCrLf, True)
        Next

    End Function
End Class


Public Class Method2  ' This is used for strings ( completely untested at this point )
    Public Shared RezultatiYP() = Nothing
    Dim NoviArray = Nothing
    Dim intColumns As Integer, intCnt As Integer, intPos As Integer
    Dim i As Integer, j As Integer, n As Integer
    Public vntTemp As Object
    Dim strTemp As String, chrTemp As String
    Const vectorSize As Integer = 10


    Public Function ConvertToArray(ByVal strParse As String, ByVal strDelimiter As String, ByVal intDimensions As Integer, ByRef vntArray As Object) As Integer
        ' Metoda za preuzimanje stringa iz VBS-a, delimitacija po znaku ",", stvaranje novog arraya, punjenje istog clanovima starog array-a.

        ' loop for number of instances of the delimiter and store it in an array for later use.
        ReDim vntTemp(vectorSize)
        n = 0
        For intPos = 1 To Len(strParse)
            chrTemp = Mid$(strParse, intPos, 1)
            If Mid$(strParse, intPos, 1) = strDelimiter Then
                intCnt = intCnt + 1
                FillAndSize(n, strTemp, vntTemp)
                strTemp = ""
                n = n + 1
            Else
                strTemp = strTemp & chrTemp
            End If
        Next
        FillAndSize(n, strTemp, vntTemp)
        ReDim Preserve vntTemp(n)

        ' redim the array (deprecating by 1 for base zero array) by row and column
        intColumns = (intCnt + 1) / intDimensions
        intDimensions = intDimensions - 1
        intColumns = intColumns - 1
        ReDim vntArray(intDimensions, intColumns)

        ' populate the newly redimensioned array
        n = 0
        For j = 0 To intColumns
            For i = 0 To intDimensions
                vntArray(i, j) = vntTemp(n)
                RezultatiYP(n) = vntTemp(n)
                n = n + 1
            Next
        Next
    End Function

    Private Sub FillAndSize(ByVal intCount As Integer, ByVal strTemp As String, ByRef vntInput As Object)
        Const vectorSize As Integer = 10
        Dim i As Integer
        i = intCount Mod vectorSize
        If i = 0 And intCount >= vectorSize Then
            ReDim Preserve vntInput(intCount + vectorSize)
        End If
        vntInput(intCount) = strTemp
    End Sub
End Class


Compile it, you will get a dll, then regasm and gacutil it to enter it into GAC

Start IIS, point it to a default document test.asp and paste the following into it:

<% @Language="VBScript" %>
<% Option Explicit %>
<%

dim cta 
set cta = Server.CreateObject("Test.Class1")

dim arrayz(8)
arrayz(0) = 5
arrayz(1) = 6
arrayz(2) = 7
arrayz(3) = 8
arrayz(4) = 9
arrayz(5) = 8
arrayz(6) = 7
arrayz(7) = 6

dim arrayz3(8)
arrayz3(0) = "C"
arrayz3(1) = "H"
arrayz3(2) = "A"
arrayz3(3) = "R"
arrayz3(4) = "a"
arrayz3(5) = "c"
arrayz3(6) = "t"
arrayz3(7) = "r"

dim arrayz2(8)
arrayz2(0) = "Today"
arrayz2(1) = "is"
arrayz2(2) = "A good Day"
arrayz2(3) = "To Die"
arrayz2(4) = "Tomorrow"
arrayz2(5) = "Glad"
arrayz2(6) = "Nothing"
arrayz2(7) = "Testing"

cta.MethodNumber(arrayz)
cta.MethodString(arrayz2)
Cta.MethodChars(arrayz3)

Response.Write Server.HTMLEncode("()")
%>



Browse it, and in the folder C:\temp\ you will find 3 files showing that arrays were successfully received from VBS into vb.NET
GeneralRe: I need to pass an array from VBScript to VB.Net COM .DLL Pin
isaacchk3-Aug-10 23:23
isaacchk3-Aug-10 23:23 
GeneralRe: I need to pass an array from VBScript to VB.Net COM .DLL Pin
Hrizip3-Aug-10 23:48
Hrizip3-Aug-10 23:48 
GeneralRe: I need to pass an array from VBScript to VB.Net COM .DLL Pin
Hrizip4-Aug-10 0:11
Hrizip4-Aug-10 0:11 
QuestionMouse Move on Label Pin
Tufail Ahmad13-Jan-10 20:00
Tufail Ahmad13-Jan-10 20:00 
AnswerRe: Mouse Move on Label Pin
DaveAuld13-Jan-10 23:28
professionalDaveAuld13-Jan-10 23:28 
GeneralRe: Mouse Move on Label Pin
Tufail Ahmad14-Jan-10 0:33
Tufail Ahmad14-Jan-10 0:33 
GeneralRe: Mouse Move on Label Pin
Dave Kreskowiak14-Jan-10 1:36
mveDave Kreskowiak14-Jan-10 1:36 
GeneralRe: Mouse Move on Label Pin
DaveAuld14-Jan-10 2:47
professionalDaveAuld14-Jan-10 2:47 
GeneralRe: Mouse Move on Label Pin
Eddy Vluggen14-Jan-10 3:40
professionalEddy Vluggen14-Jan-10 3:40 
QuestionGeneric code for updating business object from dataset - feedback requested Pin
Lee Ludden13-Jan-10 9:37
Lee Ludden13-Jan-10 9:37 
AnswerWow, way to complicated ... Pin
David Mujica13-Jan-10 9:57
David Mujica13-Jan-10 9:57 
QuestionHow to generate a check sum string? Pin
azusakt12-Jan-10 18:02
azusakt12-Jan-10 18:02 
AnswerRe: How to generate a check sum string? Pin
Abhinav S12-Jan-10 18:37
Abhinav S12-Jan-10 18:37 
GeneralRe: How to generate a check sum string? Pin
azusakt12-Jan-10 19:14
azusakt12-Jan-10 19:14 
GeneralRe: How to generate a check sum string? Pin
Johan Hakkesteegt12-Jan-10 22:05
Johan Hakkesteegt12-Jan-10 22:05 
AnswerRe: How to generate a check sum string? Pin
Luc Pattyn12-Jan-10 23:23
sitebuilderLuc Pattyn12-Jan-10 23:23 
QuestionError inserting a date into an SqlCe DataTable Pin
Paul Hasler12-Jan-10 13:47
Paul Hasler12-Jan-10 13:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.