?
Solved

vb.net structure default property

Posted on 2009-07-01
6
Medium Priority
?
803 Views
Last Modified: 2012-05-07
I am trying to use the vb.net upgrade wizard in vs5 to upgrade an old application.
But the IDE shows some errors that I don't now how to fix.

To explain further: I have a type that the wizard has converted into a structure, I have an array of that type, but I pass just the value of the array that I want to work on at that moment.
See my example:



 


Normal      UPGRADE_WARNING: Couldn't resolve default property of object tmpClient. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'      C:\Clients\Net\....\clsClientSort.vb      84

Public Structure typCliSelect
   Dim ID As String
   Dim ClientName As String
End Structure
 
Dim Aray() as typCliSelect
Redim aray(10) as typClient
 
for I = 1 to 10
  ProcessClient(Aray(i))
next
 
public function ProcessClient(MyClient as typCliSelect) as long
' Do some stuff ...
end function

Open in new window

0
Comment
Question by:sidwelle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:prashantagarw10
ID: 24756295
You have two options but u will need to explore a bit on each of these to see which one suits you better

1. Define an indexer on class. this will behave like a default property. Search on google for dotnet class indexer and you shd. see some relevant info.

2. Define a class's default property just above the class declaration like :
<DefaultProperty("MyProperty")> _
Public Class typCliSelect
    ...
    Public Property MyProperty() As String
        ...
    End Property
    ...
End Class

Do not use the default keyword within property itself.

this should solve your problem.

Cheers!
Prashant
0
 

Author Comment

by:sidwelle
ID: 24756519
Not sure, I don't really care about the default property.
I want to pass 1 component of the array, not one property of the structure/type.
I want to pass the whole structure.
0
 

Author Comment

by:sidwelle
ID: 24772272
From what I have read, the correct way to assign one user defined structure to another is exactly as I di
it:
Dim A as MyStruct
Dim B as MyStruct
A = B
Its just the conversion wizard that throws an error, right ?

0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 5

Accepted Solution

by:
prashantagarw10 earned 1600 total points
ID: 24773685
yes your code is right and thats y i was wondering what your question actually is.
i thought you were asking a work around for the error thrown by conversion wizard so what i had told was a resolution to that. otherwise your code looks fine. Even though you might need to defien a default property if you have used it some where in your code so there my answer will help you.

Cheers!
Prashant
0
 
LVL 28

Assisted Solution

by:Ark
Ark earned 400 total points
ID: 24811199
1. Not sure, but VB.net default declaration is ByVal while vb6 is ByRef.
Probably
public function ProcessClient(ByRef MyClient as typCliSelect) as long 'integer?
do the trick?
2. Try use Classes instead of structures with explicit 'New' keyword
Public Class typCliSelect
   Dim ID As String
   Dim ClientName As String
'Public Sub New()
'Initialize some properties
'End Sub
End Class
Dim Aray() as typCliSelect
Redim aray(10) as typClient
 
for I = 1 to 10
  Aray(i)=New typClient
  ProcessClient(Aray(i))
next
0
 

Author Closing Comment

by:sidwelle
ID: 31598826
thanks for the help.
0

Featured Post

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question