|
I designed a custom attribute using the following class:
<AttributeUsage(AttributeTargets.Field, AllowMultiple:=False, Inherited:=False)> _
Public Class OutputDescriptionAttribute
Inherits Attribute
#Region "Variables"
Private _oldDescription As String
Private _newDescription As String
#End Region
#Region "Properties"
Public ReadOnly Property OldDescription As String
Get
Return Me._oldDescription
End Get
End Property
Public ReadOnly Property NewDescription As String
Get
Return Me._newDescription
End Get
End Property
#End Region
#Region "Constructor"
Public Sub New(oldDescription As String, newDescription As String)
Me._oldDescription = oldDescription
Me._newDescription = newDescription
End Sub
#End Region
End Class
And I apply the attribute to various enumerations. For example:
Public Enum ConditionType
<OutputDescription("I", "Intact")> Intact
<OutputDescription("F", "Fair")> Fair
<OutputDescription("P", "Poor")> Poor
<OutputDescription("N", "None")> None
End Enum
What I haven't be able to figure out exactly, is how to get one of the attribute's properties for a specific enumeration member.
For example, if I have a variable Dim condition As ConditionType = ConditionType.Fair and I want to retrieve either the NewDescription or OldDescription property of the attribute tag ("Fair" or "F" respectively) how can I go about doing this.
Currently I was using the following function to test out methods:
Private Sub GetAttribute(T As Type)
Dim attr As OutputDescriptionAttribute = CType(Attribute.GetCustomAttribute(T, GetType(OutputDescriptionAttribute)), OutputDescriptionAttribute)
Dim newDesc As String = attr.NewDescription
Dim oldDesc As String = attr.OldDescription
End Sub
If I call this method using GetAttribute(GetType(ConditionType)) I get no error message, however if I try doing the following:
Dim condition As ConditionType = ConditionType.Fair
GetAttribute(condition.GetType)
I get any error about ConditionType cannot be converted to a needed type. How can I go about getting the custom attribute that is applied to a specific enumeration member? Thanks in advance.
|
|
|
|
|
I've taken your class and put it in a console-application; below is the code that fetches the member, and then the attributes of said member.
Sub Main()
Dim someCondition As ConditionType = ConditionType.Fair
Dim mi As MemberInfo = GetType(ConditionType).GetMember(someCondition.ToString()).FirstOrDefault()
Dim attribute As OutputDescriptionAttribute = mi.GetCustomAttributes(GetType(OutputDescriptionAttribute)).FirstOrDefault()
Console.WriteLine(attribute.NewDescription)
Console.ReadLine()
End Sub You might want to put this into a nice little helper-method. Generics and method extensions would help in keeping above code readable.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Overlay Text, Image,animation or video on a Runing Video using visual basic 6 and direct x and how i get full screen of of a video.
Shreekanta Mohanty
|
|
|
|
|
There's some problems with your question as it is; first, you're stating requirements, and not asking a specific question on code. We don't give away completed projects.
Also, VB6 has been dead for quite some time now. It's no longer sold, nor supported. If you want "anything" in VB6, then you're basically on your own. You can download VB.NET for free if you need an alternative.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I want to select all text in a textbox, so I coded the SelectAll() method inside the GotFocus event handler.
This did not work, so I inserted a breakpoint to try to find the problem and what I found is that after the execution of the SelectAll() instruction the LostFocus event is fired and the code within the LostFocus handler executed.
The same thing hapens when using the TAB key to go to the textbox. However in this case the text remains selected
Bottom line I want to select the all text in the text box after clicking the control.
I looked around and the MouseDown event does the trick. However if I try to move the insertion point by clicking with the mouse all the text is selected again. And that is not a desirable behavior for this program.
Any ideas? Thanks In Advance!
|
|
|
|
|
Without seeing your code for these two event handles, it's impossible to tell you what you did wrong.
Either your code is wrong or your testing method and/or description of the problem is.
SelectAll will NOT change the focus to another control or remove focus from the control that you called SelectAll on.
|
|
|
|
|
Quote: I inserted a breakpoint to try to find the problem and what I found is that after the execution of the SelectAll() instruction the LostFocus event is fired You observed the LostFocus event after hitting your breakpoint in GotFocus because the breakpoint transfered the focus to the debugger. Ain't event debugging fun?
I believe that you will need a custom control to change the default handling mouse handling to get the effect that you want. Here is quick example that intercepts the left mouse button down message to achieve this behavior.
Public Class TBSelectOnEnter
Inherits TextBox
Protected Overrides Sub OnEnter(ByVal e As System.EventArgs)
SelectAll()
MyBase.OnEnter(e)
End Sub
Private Const WM_LBUTTONDOWN As Int32 = &H201
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If Not Focused AndAlso (m.Msg = WM_LBUTTONDOWN) Then
Me.Focus()
Else
MyBase.WndProc(m)
End If
End Sub
End Class Just add this to your code and do a build. It should show up in your toolbox at the top in the "YourApplicationName Components" section. Then use it as your TextBox.
|
|
|
|
|
Thanks TnTinMn! It Works fine.
And thanks for helping me understand the "LostFocus Mystery"
|
|
|
|
|
You are welcome.
Just be careful with that control. I did not put a lot of thought into the ramifications of "eating" the mouse down message, but I can not think of any.
|
|
|
|
|
I will. I know now the way. It's easier to explore.
|
|
|
|
|
hello everyone,
i am using vb.net(2003 in windows application) along with sql server 2005 i need to give display data of a sql procedure whose columns are being generated dynamicaly. The problem arise when i want to give header of flexgrid as i am not able to find out how sql column headers can be retrieved in case of it is being generated dynamicaly(for windows application)...Plz help
ashish sharma
|
|
|
|
|
Flexgrid?? The older-than-dirt-itself Flexgrid?? WHY on earth are you using that thing?
Is there something wrong with using the DataGridView??
What you want to do is a very trivial SQL operation. You're just putting the SqlCommand object together to execute a stored procedure and the resultset will come back with the column header in place by default. Well, IF your stored procedure is written correctly anyway.
|
|
|
|
|
I'm building a neural network library pretty much to see if I can do it and advance my skills in programming. I'm currently building the Neuron class, and as you may or may not know, a neuron in a neural network has what's called an activation function; however my question below does not have to do with neural networks directly, strictly with the use of Func(Of TResult) delegate So within my neural network class I have several built in activation functions:
Private Function Identity(value As Double) As Double
Return value
End Function
Private Function [Step](value As Double) As Double
If value <= 0 Then
Return 0
Else
Return 1
End If
End Function
Private Function LogarithmicSigmoid(value As Double, alpha As Double) As Double
If value < -45.0 Then
Return 0
ElseIf value > 45.0 Then
Return 1
Else
Return (1.0 / (1.0 + Exp(-alpha * value)))
End If
End Function
Private Function SymmetricSigmoid(value As Double) As Double
Return HyperbolicTangent(value)
End Function
Private Function HyperbolicTangent(value As Double) As Double
If value < -45 Then
Return -1.0
ElseIf value > 45.0 Then
Return 1.0
Else
Return Tanh(value)
End If
End Function
I also have an enumeration for the user to select which activation function they want to use for the neuron:
Public Enum ActivationFunctions
IDENTITY
[STEP]
LOGARITHMIC_SIGMOID
SYMMETRIC_SIGMOID
HYPERBOLIC_TANGENT
End Enum
The first problem I'm having is with the following methods:
Private activationFunction As Func(Of Double)
Public Sub SetActivationFunction(activationFunction As ActivationFunctions, value As Double, Optional alpha As Double = 1)
Select Case activationFunction
Case ActivationFunctions.IDENTITY
Me.activationFunction = Function(value As Double)
End Select
End Sub
Public Sub SetActivationFunction(ByVal activationFunction As Func(Of Double))
End Sub
I can't figure out how to set the instance variable activationFunction to a specific method using the AddressOf operator while passing it a parameter. Specifically in the first SetActivationFunction if the user passes the ActivationFunctions.IDENTITY enumeration, I would like to set the instance variable activationFunction to the method Identity but also pass the value parameter.
I've tried changing the line marked "PROBLEM LINE" to Me.activationFunction = AddressOf Identity but got the error message Method 'Private Function Identity(value As Double) As Double' does not have a signature compatible with delegate 'Delegate Function Func(Of Double)() As Double' .
If I changed it to Me.activationFunction = AddressOf Identity(value) the error message become 'AddressOf' operand must be the name of a method (without parentheses) , and if I change it to Me.activationFunction = AddressOf Identity()(value) I get the error message Argument not specified for parameter 'value' of 'Private Function Identity(value As Double) As Double'
Based on the varying error message it seems like what I'm trying to do can be done, I just can't figure out the proper way to specify the argument for the Identity method while using the AddressOf operator.
Any help and guidance would be greatly appreciated. I should note that this is the first time I'm trying to use the Func(Of TResult) delegate in my own code, but since I want users to be able to supply their own methods and arguments for the parameters it seemed appropriate.
Thanks in advance for any help.
|
|
|
|
|
For as function with return type Double and a parameter of type Double, use the Func(T, TResult) delegate[^].
However, in this case, a delegate solution is not feasible as you have two different function signatures:
Func(Of Double, Double)
Func(Of Double, Double, Double)
An alternative would be:
Private Function GetActivationFunctionValue(ByVal functiontype As ActivationFunctions, _
ByVal value As Double, _
Optional ByVal alpha As Double = 1) _
As Double
Select Case functiontype
Case ActivationFunctions.IDENTITY
Return Identity(value)
Case ActivationFunctions.LOGARITHMIC_SIGMOID
Return LogarithmicSigmoid(value, alpha)
' other enum cases
End Select
End Function
|
|
|
|
|
That works fine for built-in functions but how can I generalize it so that a user can supply their own activation function to use instead of just the ones I define?
|
|
|
|
|
Quote: how can I generalize it so that a user can supply their own activation function to use instead of just the ones I define? You should probably ask this question as a new question to get input from others.
The best advice that I can offer on that is to define the allowed function structure and develop an expression builder so that the user must follow a structure you define. The expression could then be processed to emit a DynamicMethod[^] that can called if selected.
This will take a fair amount of work.
|
|
|
|
|
Hello everyone! My name is Emmanuel and I new to dis site and also to programming. I am trying to write a program with vb6.0 that can be use to lock pc in a cafe. I have successfully designed d program but d problem is hw can i disable/enable d ctrl+alt+del keys so that d program cannot b quit. Also, som people might wnt to switch off d system & reboot so that they can have access. Now hw can i make the program autorun at windows startup? I know dragging d exe app into d startup folder can solve dis but d problem is that i'm not writing dis program 4 my self and i won't b there when my clients will install it. So, pls give me d code dat will add d program to d startup folder and d code to remove it if d user click on disable autorun. I am using windows 7 ultimate OS. Tnx in adv.
|
|
|
|
|
Since you're new to programming, I HIGHLY suggest you drop VB6 right now and go get VB.NET Express. It's free from here[^].
Save yourself the grief of learning a bunch of bad habits that VB6 will teach you and you'll get far more features and flexibility by using .NET instead.
Otekpo Emmanuel wrote: hw can i disable/enable d ctrl+alt+del keys
You can't trap Ctrl-Alt-Del. It's impossible to disable it.
Since you're code running AS THE USER when it starts from double-clicking it or from the Run key in the Registry, the user can terminate it any way they want and you can't stop that from happening. Users are always able to terminate an app running in their security context.
The solution is to move your code to somewhere that normal users don't have permissions to terminate, such as a Windows Service running as Local System. VB6 cannot write Windows Services (without hacking it in!), but VB.NET can.
Truthfully, a café application like this is far from trivial to write, secure, test (you ARE testing this for security, correct?!) and support.
|
|
|
|
|
Ok Dave, thanks for your advice and I promise not to use such words again. You advice me to use Vb.Net and just as I said before, I'm new to programming and I don't any knowledge about Vb.Net. So would you please give some guidelines to abide to. And a site that can give me more experience on Vb.Net. Thanks.
|
|
|
|
|
Ok Dave, thanks for your advice and I promise not to use such words again. You advice me to use Vb.Net and just as I said before, I'm new to programming and I don't any knowledge about Vb.Net. So would you please give some guidelines to abide to. And a site that can give me more experience on Vb.Net. Thanks.
|
|
|
|
|
Guidelines?? For what?? No site can give you "more experience". The only thing that's going to do that is writing code, writing more code, and finally writing even more code.
|
|
|
|
|
Less of the textspeak - we are adults here!
It's well known that if all the cat videos and porn disappeared from the internet there would be only one site left and it would be called whereareallthecatvideosandporn.com
|
|
|
|
|
There's an older article on configuring XP as a kiosk machine[^]; might still have some good clues
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello everyone! My name is Emmanuel and I'm new to programming. I designed a name dictionary with v6.0, where som1 can search 4 d meaning and origin of his name. Everytin is wrking fine. But when i make d project exe and try to run it in another system, it shows d database path is not a valid path but it will run fine in my system. Som1 out there shud hlp me plzzzzz. Tnx in adv.
|
|
|
|
|
Otekpo Emmanuel wrote: Som1 out there shud hlp me plzzzzz
This will almost certainly not happen as you are coding in a language that is DEAD , as Dave suggested get VB.Net express and start again.
Never underestimate the power of human stupidity
RAH
|
|
|
|