Converting Able 5 vb object code to Able 7 C# code

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Converting Able 5 vb object code to Able 7 C# code

Post by jmestep » Tue Dec 30, 2008 5:49 pm

I'm working on implementing the old Able 5 cross sell webpages, categories function. (I see pluggables posted an add-on for some of this, but I need the cross linking to work both ways and also be able to distribute the code)
I've got most of it done, but I'm stumped on some code in the cbObjectLinkCollection.vb, which is the collection that is used to show the links at the bottom of the product page, for example. Can anyone translate this into C#? I've tried a couuple of places online and it hasn't worked for this section

Code: Select all

''' -----------------------------------------------------------------------------
		''' <summary>
		''' Gets or sets the Object_ID property.
		''' </summary>
		''' <value>The ID of the primary object.</value>
		''' <remarks>
		''' </remarks>
		''' <history>
		''' 	[loganr]	1/5/2004	Created
		''' </history>
		''' -----------------------------------------------------------------------------
		Public Property Object_ID() As Integer
			Get
				Object_ID = m_Object_ID
			End Get
			Set(ByVal Value As Integer)
				Dim i As Integer
				If m_Object_ID <> Value Then
					m_Object_ID = Value
					For i = 0 To Count - 1
						Item(i).Object_ID1 = Value
					Next
				End If
			End Set
		End Property
Here is what the translator does and it won't build because of the Item and the Count

Code: Select all

 public int ObjectType
            {
                get { ObjectType = _ObjectType; }
                set
                {
                    int i;
                    if (_ObjectType != value)
                    {
                        _ObjectType = value;
                        for (i = 0; i <= count - 1; i++)
                        {
                            item(i).ObjectType1 = value;
                        }
                    }
                }
            }
Thanks
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
sohaib
Developer
Developer
Posts: 1079
Joined: Fri Jan 23, 2004 1:38 am

Re: Converting Able 5 vb object code to Able 7 C# code

Post by sohaib » Wed Dec 31, 2008 6:11 am

The converted code seems correct ... except may be you need to change item(i) to this if you are doing this in a collection class

Code: Select all

public int ObjectType
            {
                get { ObjectType = _ObjectType; }
                set
                {                    
                    if (_ObjectType != value)
                    {
                        _ObjectType = value;
                        for (int i = 0; i <= this.Count - 1; i++)
                        {
                            this[i].ObjectType1 = value;
                        }
                    }
                }
            }

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Converting Able 5 vb object code to Able 7 C# code

Post by jmestep » Wed Dec 31, 2008 8:58 am

I've changed it and added an inheritance to a persistable collection to the class, so that took care of the this.Count problem. On the following code, I'm getting an error
'W2MCustomClasses.RelatedObjectLinks.W2MRelatedObjectLinkCollection.ObjectType.get': not all code paths return a value
I've tried putting return i; in at various places and I can't seem to get it right.

Code: Select all

 public Int32 ObjectType
            {
                get { ObjectType = _ObjectType; }
                set
                {
                    if (_ObjectType != value)
                    {
                        _ObjectType = value;
                        for (int i = 0; i < this.Count; i++)
                        {
                             this[i].ObjectType1 = value;
                         
                        }                      
                    }
                   
                }
            }
Thanks for your help.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Converting Able 5 vb object code to Able 7 C# code

Post by mazhar » Wed Dec 31, 2008 9:03 am

The get part must have a return statement. The correct code should be

Code: Select all

public Int32 ObjectType
            {
                get { return _ObjectType; }
                set
                {
                    if (_ObjectType != value)
                    {
                        _ObjectType = value;
                        for (int i = 0; i < this.Count; i++)
                        {
                             this[i].ObjectType1 = value;
                         
                        }                     
                    }
                   
                }
            }


User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Converting Able 5 vb object code to Able 7 C# code

Post by jmestep » Mon Jan 26, 2009 8:41 am

I'm back to converting this code now after creating and using other custom classes. I've made the corrections above and it's working OK.
I've translated this:

Code: Select all

Public Overloads Function IndexOf(ByVal intObjectID As Integer, ByVal intObjectType As Integer) As Integer
			Dim i As Integer = 0
			Dim intIndexOf As Integer = -1
			Dim objObjectLink As cbObjectLink
			While intIndexOf < 0 And i < Count
				objObjectLink = Item(i)
				If objObjectLink.ObjectType2 = intObjectType AndAlso objObjectLink.Object_ID2 = intObjectID Then
					intIndexOf = i
				Else
					i = i + 1
				End If
			End While
			objObjectLink = Nothing
			IndexOf = intIndexOf
		End Function
int this:

Code: Select all

 public  int IndexOf(Int32 objectId, Int32 objectType)

            {

                for (int i = 0; i < this.Count; i++)
                {
                    if ((this[i].ObjectType2 == objectType && this[i].ObjectId2 == objectId)) return i;
                }
               return -1;
                
            }
and it is OK.
The next section needs to get the object at a specific index and the VB to C# translator didn't do well on it. What is the equivalent in C# of:

Code: Select all

Public Function Item(ByVal intIndex As Integer) As cbObjectLink
			Return CType(InnerList.Item(intIndex), cbObjectLink)
		End Function
The translator does:

Code: Select all

public W2MRelatedObjectLink Item(int index)
           {

               return (W2MRelatedObjectLink)InnerList.Item(index);
            }
Thanks
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
nickc
Captain (CAPT)
Captain (CAPT)
Posts: 276
Joined: Thu Nov 29, 2007 3:48 pm

Re: Converting Able 5 vb object code to Able 7 C# code

Post by nickc » Mon Jan 26, 2009 12:45 pm

The translators I've used invariably have problems distinguishing between method arguments and array elements - In VB, they're the same symbols "()" in C#, array is "[]" but "()" is still valid.
That's likely your issue, i.e. return (W2MRelatedObjectLink)InnerList.Item[index];

I'd also recommend "Object as Type" over (Type)Object for casting, unless there is some implicit conversion required - "as" has a great benefit in returning null instead of throwing an exception.

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Converting Able 5 vb object code to Able 7 C# code

Post by jmestep » Mon Jan 26, 2009 1:38 pm

Thanks. I'm beginning to think that at this point I need to quit trying to translate and go with new code. I've done DALs for 8 other custom objects and I understand more how the whole thing works. Now I'm back to being confused with translating from VB.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

Post Reply