473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Call a property using a string

I have a class with 50 properties sp01 .. sp50 is there a way to call a
property using a string?
ex. o.sp & "01"

Chad
Nov 20 '05 #1
3 1374
"Chad Miller" <ch**@predictiveconcepts.com> schrieb
I have a class with 50 properties sp01 .. sp50 is there a way to call
a property using a string?
ex. o.sp & "01"


You can, but be careful, the compiler won't complain if a name is missing:
see the CallByName statment and the topic "Reflection":
http://msdn.microsoft.com/library/en...natruntime.asp

especially sub topic "Dynamically Loading and Using Types"
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
Thanks, that worked great! It also taught me allot about the reflection
class.

"Charlie Williams" <an*******@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com...
You can accoplish this easily using reflection.

Imports System.Reflection

Public Function GetPropertyValueByName(ByVal num As String) As String
Dim t As Type = Me.GetType()
Dim pi As PropertyInfo = t.GetProperty("sp" & num)
Return CType(pi.GetValue(Me, Nothing), String)
End Function

Charlie

Nov 20 '05 #3
Thanks, that worked great! It also taught me allot about the reflection
class.

"Charlie Williams" <an*******@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com...
You can accoplish this easily using reflection.

Imports System.Reflection

Public Function GetPropertyValueByName(ByVal num As String) As String
Dim t As Type = Me.GetType()
Dim pi As PropertyInfo = t.GetProperty("sp" & num)
Return CType(pi.GetValue(Me, Nothing), String)
End Function

Charlie

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one...
7
by: Tim ffitch | last post by:
Hi I have created a VB dll file that contains common functions I use across various projects in VB, Access and Excel. Rather than have to code the functions in each I decided to use the dll...
6
by: Jeff Frederick | last post by:
Hello all, I am interested in using the value from a field to call a function. For example I have a table and one of the field names is "Function." So for each record I input the name of the...
7
by: M | last post by:
Is there any way to modify the following code so I can run it with any number of paramNames as well as any number of paramValues? So far it works with an array of paramValues, but since you can...
27
by: Jason Shohet | last post by:
I have an ascx control, and it needs a value called 'orgID' which the parent page will have. I want to avoid the parent page setting values in fields on the ascx control since this violates...
3
by: Patrick.O.Ige | last post by:
I created a USERCONTROL and i want to call a LABEL from an ASPX page. The USERCONTROL is in the ASPX page I have the label :- Label lblstr = new Label(); And displaying using:-...
5
by: Amaryllis | last post by:
I'm trying to call a CL which is located on our AS400 from a Windows application. I've tried to code it in different ways, but I seem to get the same error every time. Does anyone have any clue...
33
by: Partha Protim Roy | last post by:
Hello, I have a Customer form say A to enter/update customer details. In the Form A I have a button which opens another form say B. In the Form B, I am providing user with a option to search...
1
by: momo | last post by:
Okay guys, I have this one problem and I admitted I am a novice at this. This is a Code Behind in an aspx page. You will see where I have the plus signs below in SecureQueryString2.vb where I am...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.