Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb_dotnet thread: using vb.net assembly in C#


Message #1 by "dirk neethling" <dirk.neethling@g...> on Mon, 26 Nov 2001 10:35:28
Hello 
I succ. compiled some vb.net code like below, and also managed to acces 
this from c# with the using namespace instruction. But when I run the 
compiler it tells me it cannot instantiate the object. What must I do to 
be able to use vb.net code in c#. Very frustrating since I thought MS 
wanted cross-language useability.
dirk

vb.net code:
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports System.Data.Common

Namespace vbFuncs

    Public Class controlsText

        Private pageControlsArr(2, 500) As String
        Private language As String
        Private lingoStr As String
        Private page As String

        Sub New()

        End Sub

        Public Function getLanguage(ByVal HTTP_ACCEPT_LANGUAGE As String, 
ByVal lang As String) As String
            Try
                language = lang.Replace("'", "").ToString()

                'select language
                If language <> "" Then
                    lingoStr = HTTP_ACCEPT_LANGUAGE.Substring(0, 
2).ToString()
                    Select Case lingoStr
                        Case "en"
                            language = "English"
                            page = "start"
                        Case "de"
                            language = "Deutsch"
                            page = "start"
                    End Select
                End If
            Catch
            End Try
        End Function

        Public Function getPage(ByVal pag As String) As String
            Try
                If page.Length = 0 Then
                    page = "intro"
                Else
                    page = pag
                End If

            Catch
            End Try
        End Function

        Public Function fetchControlText(ByVal currentPage As String, 
ByVal currentLanguage As String, ByVal connStr As String) As String(,)

            'active connection
            Dim connPage As OleDbConnection
            connPage.ConnectionString = connStr
            connPage.Open()

            'sp generics
            Dim objPage As OleDbCommand
            objPage.Connection = connPage

            Dim recControlsText As OleDbDataReader
            Dim objParamPage, objParamLanguage As OleDbParameter

            objParamPage = New OleDbParameter("page_", OleDbType.VarChar, 
255)
            objParamLanguage = New OleDbParameter("language_", 
OleDbType.VarChar, 255)

            objPage.Parameters.Add(objParamPage)
            objPage.Parameters.Add(objParamLanguage)

            objPage.Parameters("page_").Value = currentPage.ToString()
            objPage.Parameters("language_").Value = 
currentLanguage.ToString()
            objPage.CommandText = "getPageControlsText"
            recControlsText = objPage.ExecuteReader()

            Dim countPage As Integer
            countPage = 1
            While recControlsText.Read()
                pageControlsArr(1, countPage) = recControlsText.GetValue
(5).value
                pageControlsArr(2, countPage) = recControlsText.GetValue
(6).value
                countPage = countPage + 1
            End While
            recControlsText.Close()

            connPage.Close()
            recControlsText = Nothing
            connPage = Nothing

            fetchControlText = pageControlsArr
        End Function

    End Class
End Namespace

C# code
public controlsText ct;
ct = new controlsText();

//this is where the bug comes up: compiler message is "Value null was 
found where an instance of an object was required. "
actualPage = ct.getPage(currentPage).ToString();


  Return to Index