Converting C# to VB.net

ninel

Active member
Joined
Mar 23, 2005
Messages
32
Location
Land O Lakes, Florida
Programming Experience
3-5
I have samples of C# code that I need to use to instantiate an object. I need to convert it to VB.net.
I have a dll called ProjectUtilities. It is referenced in .net as "InteractiveSoftworks.VoiceNet.ProjectUtilities"
I need to instantiate the ProjectManager object of the dll, but in order to do that it requires certain values to be passed.
Here is the C# code:
VB.NET:
(Class Constructor):
Public ProjectManager(string sSystemDatabase, ScriptModel[] arrScm, IScriptModelFactory objScmFactory)
(Actual instantiation):
ProjectManager pm = new ProjectManager("Voicenet", new ScriptModel [] {scriptmodel.AgentScriptModel, ScriptModel.IVRScriptModel}, new ScriptModelFactory());
The constructor requires 3 arguments
1. A string
2. An array of constants
3. An object
Here is my code in VB.NET:
VB.NET:
Dim oScriptModelFactory As New InteractiveSoftworks.VoiceNet.ProjectUtilities.ScriptModelFactory
Dim oScriptModel As New InteractiveSoftworks.VoiceNet.ProjectUtilities.ScriptModel
Dim arrScriptModel(,)
'I am setting the constants here
Dim sAgentScriptModel = InteractiveSoftworks.VoiceNet.ProjectUtilities.ScriptModel.AgentScriptModel
Dim sIVRScriptModel = InteractiveSoftworks.VoiceNet.ProjectUtilities.ScriptModel.IVRScriptModel
'Now trying to pass them
Dim oProjectManager As New InteractiveSoftworks.VoiceNet.ProjectUtilities.ProjectManager("NG2468", arrScriptModel(sAgentScriptModel, sIVRScriptModel), oScriptModelFactory)

I'm getting Object Refernce Not Set to Instance of Object
Am I passing the array incorrectly?
I would appreciate any help,
Ninel
 
It looks like you are trying to pass an array that has not been created yet.

Try this...

Imports InteractiveSoftworks.VoiceNet.ProjectUtilities

Dim oProjectManager As New ProjectManager("NG2468", New ScriptModel(){ScriptModel.AgentScriptModel, ScriptModel.IVRScriptModel}, New ScriptModelFactory)​

when creating a new array of objects in VB.Net you can pass the initial objects in curly braces after the clesing brackets.​

for example...
dim o as object() {"object1","object2"}​
 
the c# syntax is directly translatable to VB. Review this document:

http://www.harding.edu/USER/fmccown/WWW/vbnet_csharp_comparison.html

I used it to convert my C# understandings to VB when the company I work for decided to undertake a new development in VBN instead of C#. Understanding C# syntax will help you greatly as many of the code sample we come across on the web, that do useful things, are written in C#

Bear in mind that it really is a matter of syntax, and not of semantics; any VBN programmer has the ability to understand C# just by jigging some words and concepts round in their head..



VB.NET:
c#:
[B][COLOR=red]ProjectManager[/COLOR] [COLOR=magenta]pm[/COLOR] = [COLOR=blue]new[/COLOR] [COLOR=red]ProjectManager[/COLOR]("Voicenet", [COLOR=blue]new[/COLOR] ScriptModel[COLOR=lime] [][/COLOR] {scriptmodel.AgentScriptModel, ScriptModel.IVRScriptModel}, [COLOR=blue]new[/COLOR] ScriptModelFactory());[/B]
 
vbn:
[B]Dim [COLOR=magenta]pm[/COLOR] as [COLOR=blue]New[/COLOR] [COLOR=red]ProjectManager[/COLOR]("Voicenet", [COLOR=blue]N[/COLOR][COLOR=blue]ew[/COLOR] ScriptModel[COLOR=lime]() [/COLOR]{scriptmodel.AgentScriptModel, ScriptModel.IVRScriptModel}, [COLOR=blue]New[/COLOR] ScriptModelFactory);[/B]
 
Back
Top