|
Hey Gideon,
Thanks for the response. I def. need method #1 (Of TKey, TValue). When I try this:
Public Class KeyValuePair_Generic(Of TKey, TValue)
Inherits KeyValuePair(Of TKey, TValue)
End Class
I get "Classes can only inherit from other classes."
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
KeyValuePair(Of TKey, TValue) is not a Class but rather a Structure (struct) which means you can't inherit from it. You would need to create your own equivalent Structure (and I would recommend using a Structure rather than a class) and using that instead.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Roger that. I'll give that a go.
Thanks.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
I looked in the code behind file but I don't see any code for adding event handlers for controls such as: AddHandler ..., Addressof....
How is this possible if the event handler does not even have the Handles xxx.event at the end of the event handler?
CodingYoshi
Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
|
|
|
|
|
Did you notice the "WithEvents" clause on those Dim statements?? Did you also notice the "Handles" clause on the end of the event handler headers?? Read this[^] and you'll know how it works.
Dim WithEvents someVariable As New Button
.
.
.
Private Sub ButtonClickHander(..., ...) Handles someVariable.Click
|
|
|
|
|
All this inconsistency between C# and VB.NET makes things more confusing. It has never helped me.
CodingYoshi
Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
|
|
|
|
|
That's starting to change...
|
|
|
|
|
Hello, all.
Is it possible to get the name of a local variable from a reference to the variable? For example, I can get the names and values of a calling function's parameters like this:
Dim frame As New StackFrame(1)
Dim pInfos() As ParameterInfo = frame.GetMethod().GetParameters()
Is there some way to get the same information for a calling function's local variables? This is kind of what I have in mind:
Sub SomeSub()
Dim count As Integer = 10
Dim average As Single = 45.67
LogLocalVariables(count, average)
End Sub
Sub LogLocalVariables(ByVal var1 As Object, ByVal var2 As Object)
' I can get each variable's type like this:
Dim mBody As MethodBody = GetType(Form1).GetMethod _
("SomeSub").GetMethodBody()
Dim varList As ObjectModel.ReadOnlyCollection(Of LocalVariableInfo) = _
mBody.LocalVariables
' But what I really want is info like this:
' count = 10
' average = 45.67
End Sub
Thanks.
--Clay
|
|
|
|
|
Hi Clay,
AFAIK names of local variables are not available.
names of parameters (method arguments) are available, although I am not sure why that is.
the only thing that needs to be available (for reflection to work as intended) is the public
class members, nothing local.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Yeah, I was afraid of that. Thanks.
--Clay
|
|
|
|
|
Luc Pattyn wrote: names of parameters (method arguments) are available, although I am not sure why that is.
The names of parameters are available because they make using an API orders of magnitude easier. Otherwise Intellisense would not be able to provide you with the parameter names and you would just have to know which parameter is which. If the XML documentation is included, you could argue that Intellisense could determine the names from there, but libraries do not always have that documentation.
|
|
|
|
|
Clay Walnum wrote: LogLocalVariables(count, average)
Well, since you're passing the local variable in already, what's the point of going back to the method that called it to figure them out??
Really, you're not the first person to try this. There are easier methods of logging values. One major problem you'll run into attempting to do this is variable scope. For example, you can have a variable that only exists inside a loop in a method, but is out of scope in the rest of the method, either before or after the loop. You can't get the value of a variable that doesn't exist yet or is already dead.
Another problem is Reflection's performance. Reflection is notoriously slow. If you end up trying to log variable values inside of a loop, you'll find that your app's performance may be quite unacceptable.
And yet another issue is what happens when you go from a Debug build to a Release build?? All of this logging code will still be in the release build. How are you going to remove all this code so you don't take a performance hit in the final release? If you use the Debug class, these calls are automatically removed from the Release build. Trace method calls are converted to call equivilent Debug methods (weird!) and are NOT removed from the Release build.
So, pretty much, the best method to use with the least maintenance is directly calling Debug.WriteLine in your code where needed.
|
|
|
|
|
Thanks for the input. I'm doing this more to experiment with Reflection than actually creating a custom debugging system. It just seems that there ought be be a way to get the name of a variable, as well as the value, other than passing them both as arguments, like this:
LogVariable("VarName", VarName)
But I guess not.
--Clay
|
|
|
|
|
Yes, I fully agree, in C# that is the one thing I miss most from C's pre-processor,
where you could create a one-argument macro that uses it twice, once for the name, once
for the value.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
One major problem with that approach is that the LogLocalVariables method doesn't get references to the local variables at all. What it gets is references to two newly created objects on the heap, that contains copies of the values that the local variables had when calling the method. There is no association at all between those object and the local variables, so it's impossible to use the references to get any information at all about the actual variables.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
One major problem with that approach is that the LogLocalVariables method doesn't get references to the local variables at all.
Yes, I understand that the arguments should have at least been passed as ByRef, which would have given the called sub at least access to the same memory location. Just an oversight. But even if the args are ByRef, there's no way to get the names of the passed variables.
Thanks for your comments.
--Clay
|
|
|
|
|
If I Understand your request clearly, here is how I did this
Dim objDict
objDict = CreateObject("scripting.dictionary")
Dim Var1 As String = "ABC"
Dim Var2 As Integer = 1000
objDict.Add("var1", Var1.ToString)
objDict.Add("var2", Var2.ToString)
Dim I As Integer
For I = 1 To objDict.Count
Debug.WriteLine(objDict.Keys(I - 1) & "=" & objDict.Items(I - 1))
Next
hth
Samir R. Ibrahim
|
|
|
|
|
Hi, Samir.
Thanks for the code. You're still kind of doing what I was trying to get around, though, which is having to pass both a variable name and its value to a method. I'd like to be able to get the variable name from the variable itself, much as you can do using Reflection on a method's parameters.
Still, I appreciate your efforts. I'm amazed at the number of quick and intelligent responses I've gotten to my question. This has been my favorite site for sample code for a long time, and now I see that the forum is just as good.
Thank you all!
--Clay
|
|
|
|
|
Hi Clay,
You are very welcome.
I don't know if your question is being answered, I am still don't know how to consider a post is solved.
but any way, check this, which is being considered as a answer to a problem similar to yours. in C#
http://www.west-wind.com/Weblog/posts/256.aspx[^]
Samir R. Ibrahim
|
|
|
|
|
Hello friends,
In my MS Access, one of my form having a combobox whose row source is a query data. How can i delete all items from comboBox
Thanks and regards
Jishith
|
|
|
|
|
combobox1.DataSource=Nothing
|
|
|
|
|
ComboBox1.Datasource is not showing in my access.
In ComboBox1 properties, rowsource type is Query/table and row source is my query. its not value list
|
|
|
|
|
So your Combo box is in access not in VB.Net? Is this a VBA question or an Access question or...
perhaps you can be just slightly more specific??
|
|
|
|
|
Ya . Its in MS Access.
In properties
CmbFromDate.RowSource type = Table/Query
CmbFromDate.RowSource = "Query Created On"
The query is getting for the dates from Access Table
The combo box i used for the user to select the date.
After quitting the application the .mdb file showing huge size . The previous query data is still in the combo Box
|
|
|
|
|