Hi,
I'll use a really simple example to describe what I want to do. Say I have a Class Person, with members being Name, Height, Age, Sex. I want to be able to call a function say person.NextValue, and it will return the value of one of the member variables. So if it is called the first time, it will return the value assigned to Name. The second time the value assigned to Height and etc... Any ideas on how to do this I have had a crack at it and have done the following. In my class I have created an arraylist containing the names of each member as a string. When .NextValue is called it steps to the next string in my arraylist and returns the Name of the member. For my approach to work what I need to do now is return the Value associated with the Name of the member. Is there a way of making the Name of the member map to its Value in a return statement What I mean by this is say I have strName = "m_Name". I want to return the Value of m_Name, not the actual string value "m_Name". I hope that made sense. Any help or ideas would be greatly appreciated.
cheers.

map string value to a variable name dynamically?
imanish11111
thanks Dick, but I wanted to avoid a conditional statement as I have 38 members in my class. I agree that my idea needs reviewing, but this is just a temporary measure to get my programme working until I can figure out how the hell to create a stored procedure in MS Access! ! Any ideas The very scarce code I can find on the internet doesn't work and throws an error (can't remember what that error is as Access 2003 is at work and my 2000 version here at home throws a different error altogether). If anyone out there could show me some code that works I would be over the moon. So I'll propose a simple example: I want to create a stored procedure on MS Access 2003 that performs an SQL Update. It will accept 3 parameters, say Name, Age, and Sex. Any advice on how to write the procedure and then how to create it in my database would be greatly appreciated.
By the way, I solved the dynamic mapping thing. Here's what I did:
Oops....wrong code. Here's what I actually did:
Dim type As Type = GetType(Record)
Dim prop As Reflection.PropertyInfo = type.GetProperty("SomeMemberName")
Dim objMemberValue As Object = prop.GetValue(Me, Nothing)
GS80
Hi
I think you should perhaps review your approach .. but in the meantime here is some code that will achieve what you want ...
Public Function NextValue() As Object Static n As Integer : n += 1 Select Case n Case 1 : Return mName Case 2 : Return mAge Case 3 : Return mIsMale Case 4 : Return mHeight Case Is > 4n = 1 :
Return mName End Select End FunctionHope you find it helpful
Richard
Meher
Hi
Reflection is a good approach assuming you can run your application with the relevant privileges.
With regard to Access, heres a link to a good article on creating stored procedures http://www.devcity.net/Articles/18/msaccess_sp.aspx
Richard