[.net] Passing parameters to a dll written in C# from vb script?

Started by
2 comments, last by ernow 18 years ago
I wrote a dll in C# looking like this:
public void Start()
		{
			m_tkWriter = new Toolkit();
			m_tkWriter.OpenOutputFile( "c://test_pdf//test.pdf" );
		}

		public void End()
		{
			
			m_tkWriter.CloseOutputFile();
			m_tkWriter = null;
		}
		
		public void PrintTextBlock( string font, float fontsize, float length, float width, string text, short justification )
		{			
			y_current -= m_tkWriter.HeightPrinted;
			m_tkWriter.PrintMultilineText( font, fontsize, (x_current+LeftMargin), y_current-fontsize, A4X-(RightMargin+LeftMargin), (A4Y-(TopMargin+BottomMargin)), text, justification );
			
			while( m_tkWriter.ClipText != "" )
			{
				y_current = A4Y;
				m_tkWriter.NewPage();	
				m_tkWriter.PrintMultilineText( font, fontsize, (x_current+LeftMargin), (y_current-TopMargin)-(fontsize), A4X-(RightMargin+LeftMargin), (A4Y-(TopMargin)), m_tkWriter.ClipText, justification );
				
				if( m_tkWriter.ClipText == "" )
					y_current -= TopMargin;
			}
		}


and I am using it (or should be using it) in a regular asp website, like this:

PDF.Start
PDF.PrintTextBlock CStr(vcharFontNameText), CDbl(intFontSizeText), 500.0, 500.0, CStr(vcharQuestion2), 0  
PDF.End

PDF.Start runs ok, so it can't be that it does not find the dll, but the PrintTextBlock function gives me an error that reads roughly translated to invalid procedure or method. Where am I doing wrong?
Advertisement
PDF.PrintTextBlock CStr(vcharFontNameText), CDbl(intFontSizeText), 500.0, 500.0, CStr(vcharQuestion2), 0

From the days of my VB6 coding time (hell, 5 years ago), I remember that in VB there are two types of calls, Subs and Functions. Subs have no parameters and no return type, they are like "void func(void)" methods from C#. You can call a sub without using the parameter list parentheses. However, if you want parameters you write a Function in VB, which requires a special syntax for calling.

IIRC, it would be

PDF.PrintTextBlock(CStr(vcharFontNameText, CDbl(intFontSizeText), 500.0, 500.0, CStr(vcharQuestion2), 0)

edit:
Forgot, the call keyword is if you want to call a sub with a (empty) parameter list.

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

Thank you, this was driving me insane... :P
To be more exact: the only difference between Sub and Function is that a Sub does not return anything whereas a Function will.

The Call keyword allows you to call a Function (or Sub) while specifying the brackets.

VB6 has some bad things going on regarding these brackets. Consider this:

Sub Foo(ByRef bar As Integer)
bar = bar + 1
End Sub

Sub Main()
Dim i As Integer
i = 5
Foo i
Foo(i)
Call Foo(i)
Call Foo((i))
End Sub


All four calls are valid but the results might differ.

The first one works as expected i changes.
The second one does NOT change i because the parameter is not i but (i). (i) is evaluated to a value and Foo will be called with a ByVal parameter
The thrid is equal to the first.
The last one has the same efect as the second!!! The outer brackets are related to the Call keyword but the inner have the same effect as the brackets in the second call.

Long live VB.NET! (Compared to VB6)

Cheers

This topic is closed to new replies.

Advertisement