?
Solved

Pointers (references to value types?) in VB.NET

Posted on 2006-05-07
7
Medium Priority
?
245 Views
Last Modified: 2010-05-18
I have a class that has maybe 50 different parameters to save, load, print and initalize to default values (think of an INI file for example).
I would like to have a central ParmArrayList (say) where the name, default value, allowable range for each parameter is stored (easy so far).

I would also like this ParmArrayList to contain a pointer (or reference) to the variable that contains the actual parameter so that I may easily read/write/print all parameters by iterating through the ParmArrayList.  This will be easy with string parameters (because I can easily store a reference to a string object), but for value types such as Integer or Boolean, it does not work.

Is there any way at all to somehow store the address of an integer or boolean value (to later read or write such variables through one level of indirection)

Or any ideas how I can achieve my general idea of iterating an array rather than having 50 lines of code to initialize my parameters, another 50 lines to read them, another 50 lines to write them, you get the drift...

P.S. I understand what ByRef is (and that is just fine when you want to use the ref immediately within a method; my problem is can I store the ref (to a value type)for later use
 
0
Comment
Question by:pcad696
  • 3
  • 3
6 Comments
 

Author Comment

by:pcad696
ID: 16625917
one more thing, I don't have control over all the variables that store the parameters, so wrapping all integers and booleans in a dummy class is not really an option
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 16625948
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16625950
Haha...didn't refresh the page...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:pcad696
ID: 16626123
Your comment is interesting (I will look into it, and it will probably be worth some points :) , but as I said in my follow-on comment, I don't control all the variables, they are in three separate classes, and I would prefer not having to make yet another wrapper.

Is there any way in VB.NET to store a pointer (or reference) to a variable of value type?
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16626278
There may be...but VB.Net was specifically designed to NOT do this...so I don't know how to do it offhand...

It is possible to get the values of variables by name via Reflection but then you would be going down the same road as 50 different lines to grab each one...
0
 

Author Comment

by:pcad696
ID: 16626774
I am curious, why do you say VB is designed NOT to do this, it does after all provide the equivalent of pointers for reference types; so yes, value types are explicitly different, but are you saying that they wanted to avoid pointers to value types because they are dangerous in some sense?
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question