Click here to Skip to main content
12,697,801 members (27,317 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
How to change the below vb6 property into vb.net ?
note,here Let have 2 arguments as parameter


Private lAttribute As MyAutomation.AttributeMap

Public Property Let Value(pName As String, pValue As Variant)
    lAttribute.Add pName, pValue
End Property

Public Property Get Value(pName As String)
    Value = lAttribute.Item(pName)
End Property


Thanks
Posted 4-Feb-13 3:57am
Updated 4-Feb-13 4:09am
CHill60160.7K
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

When you try to add a second parameter to a Set method in VB.NET it reports
Quote:
'Set' method cannot have more than one parameter.

You would be better off having a function that sets this e.g.
Public Sub SetValue(ByVal pName as String, ByVal pValue As Variant)
    lAttribute.Add pName, pValue
End Sub


A general hint for converting VB6 properties into .net is to type
Quote:
Public Property
and then hit the tab key - then fill in the indicated fields.
  Permalink  
Comments
saurabh kumar mahto 4-Feb-13 9:57am
   
Here I tried doing this,

Private lAttribute As MyAutomation.AttributeMap

Public Function Value(ByVal pName As String, ByVal pValue As Object) As String
lAttribute.Add(pName, pValue)
Return pValue
End Function

i am getting this error prompt as below,
Argument not specified for parameter'pValue'of Public Sub Value(pName As String,pValue as Object)
in ModuleDBParam.vb
vDBSection.Value("SI::ESTEC::CommonSetup::Release") = "12A"
CHill60 4-Feb-13 10:03am
   
Is that error at compile time or run time?
saurabh kumar mahto 4-Feb-13 10:12am
   
compile time error
Mike Meinz 4-Feb-13 10:12am
   
In the call to the vDBSection.value function above, you are passing one parameter to the method but you have the method declared with two parameters.

Also, why would you have vDBSection.value return pValue, when it was one of the values passed into the function?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Properties only accept one parameter.

If you want to pass multiple parameters, pass a single Structure containing all of the values or declare a Method using Public Sub or Public Function

Below is actual code for a property from one of my DLLs that I converted from VB6 to VB .NET:

VB6
Dim strTargetFilename as String=""
Public Property Get TargetFile() As Variant
    TargetFile = strTargetFilename
End Property

Public Property Let TargetFile(ByVal vNewValue As Variant)
    strTargetFilename = vNewValue
End Property


VB .NET
Dim strTargetFilename as String=""
Public Property TargetFile() As String
    Get
        TargetFile = strTargetFilename
    End Get
    Set(value As String)
        strTargetFilename = value
    End Set
End Property
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 4 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100