Wrox Programmer Forums
|
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 2nd, 2007, 08:38 AM
Registered User
 
Join Date: Mar 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default C# to VB.Net

The below code is in C#

this._AdRoot = new DirectoryEntry("LDAP://" + (string)this._AdRootDSE.Properties["defaultNamingContext"].Value);

I am converting it into VB.NEt

Me._AdRoot = New DirectoryEntry("LDAP://" + Convert.ToString(Me._AdRootDSE.Properties("default NamingContext").Value))

 Is my conversion from C# to VB.NEt correct? i am getting the correct output with C# code above but not with VB.NET





 
Old April 2nd, 2007, 08:50 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Does it compile, does it run? That's how we would tell if it's right.

You could probably shorten it a little:

Me._AdRootDSE.Properties("defaultNamingContext").V alue.ToString()

-Peter
 
Old April 2nd, 2007, 09:06 AM
Registered User
 
Join Date: Mar 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i have to display all the Organisational units in my firm.
in the C# it is declared as
 private void myInitializeComponent()
        {
            lvwColumnSorter = new ListViewColumnSorter();
            this.listView_ad.ListViewItemSorter = lvwColumnSorter;

            try
            {
                this._AdRootDSE = new DirectoryEntry("LDAP://rootDSE");
                this._AdRoot = new DirectoryEntry("LDAP://" + (string)this._AdRootDSE.Properties["defaultNamingContext"].Value);

                /*
                foreach(string property in this._AdRoot.Properties.PropertyNames)
                {
                    MessageBox.Show(property + " = " + this._AdRoot.Properties[property].Value);
                }*/

                TreeNode root = new TreeNode((string)this._AdRootDSE.Properties["defaultNamingContext"].Value,(int)AdImages.AdRoot,(int)AdImages.AdRoot);

                root.Tag = this._AdRoot;
                this.treeView_ad.Nodes.Clear();
                this.treeView_ad.Nodes.Add(root);
            }
            catch
            {
                throw new Exception("Error connecting to AD");
            }
        }

and I have converted it to vb.net as
Private Sub AdBrowserForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            lvwColumnSorter = New ListViewColumnSorter
            Me.listview_ad.ListViewItemSorter = lvwColumnSorter

            Try

                Me._AdRootDSE = New DirectoryEntry("LDAP://rootDSE")
                Me._AdRoot = New DirectoryEntry("LDAP://" + Convert.ToString(Me._AdRootDSE.Properties("default NamingContext").Value))

                'for each(string property in this._AdRoot.Properties.PropertyNames)
                '{
                'MessageBox.Show(property + " = " + this._AdRoot.Properties[property].Value);
                '}*/
                Dim root As TreeNode
                root = New TreeNode(CType(Me._AdRootDSE.Properties("defaultNa mingContext").Value, String), CType(AdImages.AdRoot, Integer), CType(AdImages.AdRoot, Integer))

                root.Tag = Me._AdRoot
                Me.treeview_ad.Nodes.Clear()
                Me.treeview_ad.Nodes.Add(root)
                MsgBox("connection established")

            Catch

                Throw New Exception("Error connecting to AD")
            End Try
which when i compile i get an error"Object reference not set to an object"
 for the line"lvwColumnSorter = New ListViewColumnSorter". when i comment this line , connection to the AD is established but it is not retirving any details.

 
Old April 2nd, 2007, 09:13 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I don't see where lvwColumnSorter is declared in either the C# or VB. However can't see all the code so it might be declared globally in the class, which I can only assume from the lack of declaration in the C#.

However, I believe that the "Object reference not set to an object" error is only a runtime error. The compiler won't know that a variable hasn't been set to a value until it tries to actually do something with it at runtime.

One of the differences between C# and VB (at least up till 1.1) is that the VB compiled will allow you to code the use of an unassigned variable while C# will choke and tell you you're using a variable that hasn't been assigned a value yet.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
vb.net 2008 re: VB.NET databases book bigbearjeff VB.NET 0 June 2nd, 2008 01:22 PM
convert dsr file from vb to vb.net Shashi001 VB Components 1 September 22nd, 2006 12:24 PM
VB.Net question on Windows VB.Net datagrids dmsousa VS.NET 2002/2003 1 January 19th, 2005 02:45 PM
vb.net 2002 OR vb.net 2003 metalaaron VB.NET 2002/2003 Basics 0 August 5th, 2003 10:00 AM
vb.net 2002 - vb.net 2003 book metalaaron Wrox Book Feedback 0 August 2nd, 2003 10:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.