NEW EDITS:
This is what I am trying to avoid:
ViewDetail1.strFirstName = assignValue("strFirstName")
ViewDetail1.strLastName = assignValue("strLastName")
ViewDetail1.strStreet = assignValue("strStreet")
ViewDetail1.strCompany = assignValue("strCompany")
I would rather have the code to this instead, where ?? is the magical way to know the string name:
ViewDetail1.strFirstName = assignValue(??)
ViewDetail1.strLastName = assignValue(??)
ViewDetail1.strStreet = assignValue(??)
ViewDetail1.strCompany = assignValue(?)
And then my function would return value based on my string name that I am trying to assign.
My string names are already defined in my user control like so:
Public Property strFirstName() As String
Get
Return Me._strFirstName
End Get
Set(ByVal value As String)
Me._strFirstName = value
End Set
End Property
Public Property strLastName() As String
Get
Return Me._strLastName
End Get
Set(ByVal value As String)
Me._strLastName = value
End Set
End Property
' Fields
Private _strFirstName As String
Private _strLastName As String
Where as my function would be something like:
Function assignValue(strValue as string)
Dim myColumn as string = strValue.Remove(3,0)
'make call to database
strSQL = "SELECT " & myColumn & " FROM myTable WHERE ...."
database connections...
myValue = myReader(myColumn)
assignValue = myValue
End Function
.
Forgive me if this is a stupid question or if I've used wrong terminology but I'm hoping there is a way to do this. I'm looking for a way to reference the name of the string I am trying to assign value to without having to retype string name.
I am wanting to use a function that will use the name of the string as a variable in function to determine the final value. My string names correlate with datafield column names. I am populating a user control. I'd like to put in the name of string where question marks are below in this function call. Any way to do this without having to retype the string name?
ViewDetail1.myStringNameDataColumnA = assignValue(??)
My string names are already defined in my user control. So in above scenario, I would take the name of the string and run a function that checks that string name and assigns its value based on the actual name of the string (since it correlates to a pre-existing datacolumn name)