Solved

vb.net structure default property

Posted on 2009-07-01
6
775 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
  • 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 5

Accepted Solution

by:
prashantagarw10 earned 400 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 27

Assisted Solution

by:Ark
Ark earned 100 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now