473,467 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dynamic mapping string to function

Hello,

What is the best way of mapping a string to function/sub? See ex bellow -
probably not the best way - especially when it comes to maintenance ;)

Does anybody have a better way of doing this?
Ex,

class A
Private mA as Integer

Public Sub SetFunc(byval func as string, byval value as integer)
Select Case value.ToUpper
Case "funcA".ToUpper
'do funcA
mA = value
Case "funcB".ToUpper
'do funcB
end select
end Sub

Public Function GetA() as Integer
return mA
end function
end class

class Test
Dim myA as new A
myA.SetFunc("funcA", 42)

Dim tmp as integer
tmp = myA.GetA()

end class
Oct 6 '06 #1
4 1102
Hello Vemund,

This question is asked repeatedly in the NG. Each time I am forced to question
the sanity of the questioner. In 15 years of programming I've only ever
run across 2 problems that required this kind of solution. So in answer
to your question I ask: What are you trying to do?

-Boo
Hello,

What is the best way of mapping a string to function/sub? See ex
bellow - probably not the best way - especially when it comes to
maintenance ;)

Does anybody have a better way of doing this?

Ex,

class A
Private mA as Integer
Public Sub SetFunc(byval func as string, byval value as integer)
Select Case value.ToUpper
Case "funcA".ToUpper
'do funcA
mA = value
Case "funcB".ToUpper
'do funcB
end select
end Sub
Public Function GetA() as Integer
return mA
end function
end class
class Test
Dim myA as new A
myA.SetFunc("funcA", 42)
Dim tmp as integer
tmp = myA.GetA()
end class

Oct 6 '06 #2
Vemund,

You could use a Hashtable or Dictionary to store string-delegate pairs.
But, like Boo, I also question the reasoning behind doing something
like that.

Brian

On Oct 6, 2:54 am, Vemund Halvorsen <j...@mail.comwrote:
Hello,

What is the best way of mapping a string to function/sub? See ex bellow -
probably not the best way - especially when it comes to maintenance ;)

Does anybody have a better way of doing this?

Ex,

class A
Private mA as Integer

Public Sub SetFunc(byval func as string, byval value as integer)
Select Case value.ToUpper
Case "funcA".ToUpper
'do funcA
mA = value
Case "funcB".ToUpper
'do funcB
end select
end Sub

Public Function GetA() as Integer
return mA
end function
end class

class Test
Dim myA as new A
myA.SetFunc("funcA", 42)

Dim tmp as integer
tmp = myA.GetA()

end class
Oct 6 '06 #3
On 6 Oct 2006 15:15:33 -0700, Brian Gideon wrote:
Vemund,

You could use a Hashtable or Dictionary to store string-delegate pairs.
But, like Boo, I also question the reasoning behind doing something
like that.

Brian
Im trying to set configuration properties using a ini file as storage. I
know that XML is a better (to store config settings), but due to historical
reasons ini is the storage used.

So what is the best way of applying default values to (and maybe from) an
object to an ini file?

/Vemund
Oct 9 '06 #4
Vermund,

I would store them in a Hashtable or Dictionary as string-value pairs.
The property name would be the key into the collection. Just read the
file line-by-line and starting adding the properties to the collection.
Similarly, enumerator the collection and write the contents back to a
file line-by-line.

Brian

On Oct 9, 8:37 am, Vemund Halvorsen <j...@mail.comwrote:
Brian Im trying to set configuration properties using a ini file as storage. I
know that XML is a better (to store config settings), but due to historical
reasons ini is the storage used.

So what is the best way of applying default values to (and maybe from) an
object to an ini file?

/Vemund
Oct 10 '06 #5

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

Similar topics

4
by: Scott Lyons | last post by:
Hey all, Can someone help me figure out how to pass a dynamic array into a function? Its been giving me some trouble, and my textbook of course doesnt cover the issue. Its probably something...
7
by: mittal.pradeep | last post by:
What is the better table design for a data collection application. 1. Vertical model (pk, attributeName, AttributeValue) 2. Custom columns (pk, custom1, custom2, custom3...custom50) Since the...
3
by: JDPope | last post by:
I have a situation which I cannot get a good lead on how to resolve. One of the applications I support uses the Hibernate software to generate SQL. The app is JAVA with JDBC. In testing the users...
5
by: swarsa | last post by:
Hi All, I realize this is not a Palm OS development forum, however, even though my question is about a Palm C program I'm writing, I believe the topics are relevant here. This is because I...
5
by: Kevin C | last post by:
I was curious to know what some developers out in the industry are doing when it comes to exposing Data access logic, specifically persistence. This is assuming that your not using an O/R framework...
0
by: Bill | last post by:
By dynamic mapping, I meant that before the records are transferred from one table to the other(source to target), the xml file which will have the field names of the two tables mapped, is to be...
5
by: Sakcee | last post by:
python provides a great way of dynamically creating fuctions calls and class names from string a function/class name can be stored as string and called/initilzed e.g def foo(a,b): return...
8
by: tonFrere | last post by:
Hello all, I did a lot of research on the subject and came to the conclusion that what I want to do might not be "good practice". I created a set of table to manage user rights to forms in my...
5
by: alan | last post by:
Hello world, I'm wondering if it's possible to implement some sort of class/object that can perform mapping from class types to strings? I will know the class type at compile time, like so:...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.