|
-
Feb 2nd, 2015, 05:46 AM
#1
Thread Starter
Member
[RESOLVED] How to make a variable to act on events like Textbox.TextChanged
Hello again!
As stated in the title, I'm wondering if there is a method to create a variable which will act on events like Textbox.TextChanged?
I've done some research on the web, but I don't seem to get anywhere. However, as also mentioned in my other thread,
(http://www.vbforums.com/showthread.p...21#post4828321)
Niya's multi threading article has a working method, but I'm not sure how to make it all clean. Like just a sub which will react on the TextChanged event.
I hope anyone with this knowledge is willing to give me the answer 
Kind regards,
- Frek
-
Feb 2nd, 2015, 08:04 AM
#2
Re: How to make a variable to act on events like Textbox.TextChanged
Your request doesn't actually make sense. Variables don't act on events. A variable is just a place to store some data. You put data in and get that data out. That's it. As for events, they get raised and then any methods registered to handle them are executed. That's it. Perhaps you could provide a FULL and CLEAR explanation of the problem.
-
Feb 2nd, 2015, 08:08 AM
#3
Thread Starter
Member
Re: How to make a variable to act on events like Textbox.TextChanged
I read through my post a couple of times, and I got an idea. It worked. I feel very sorry for asking this question now, but it might be useful for other new people. The code was as simple as this:
Code:
'Variable
Private WithEvents myTextChanged As New TextBox
'Sub
Private Sub myTextChanged_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles myTextChanged.TextChanged
MsgBox(myTextChanged.Text) 'Displays the message given.
End Sub
'Call method
myTextChanged.Text = "My new string"
I don't really think this belongs in this forum, but maybe the code bank?
Anyway, have a nice day guys!
- Frek
-
Feb 2nd, 2015, 08:17 AM
#4
Thread Starter
Member
Re: How to make a variable to act on events like Textbox.TextChanged
 Originally Posted by jmcilhinney
Your request doesn't actually make sense. Variables don't act on events. A variable is just a place to store some data. You put data in and get that data out. That's it. As for events, they get raised and then any methods registered to handle them are executed. That's it. Perhaps you could provide a FULL and CLEAR explanation of the problem.
Thanks for showing interest in my request! I'm sorry my request didn't make sense, and I will try to be more accurate in the future. I simply wanted a variable to act like a textbox. Like when the textbox's text was changed, an event would happen (TextChanged). I was looking for the same feature with variables. I though about this a couple of times, and why not use a textbox with no UI instead? I guess there is a reason why it works this way, and my request was probably that reason. There is no need for an event to happen when a variables content is changed, as you can use other objects, such as a textbox. Then as you said, a variable is just there to input or output stored information.
- Frek
Last edited by Frekvens1; Feb 2nd, 2015 at 08:22 AM.
Reason: Spellings
-
Feb 2nd, 2015, 08:51 AM
#5
Fanatic Member
Re: [RESOLVED] How to make a variable to act on events like Textbox.TextChanged
I'm glad you were able to find a solution by using a textbox, but just to expand on the subject a bit, if the textbox class didn't exist, the way to achieve the result you were after would have been by creating a class that would store your variable, and adding a custom event to react when that variable is changed through a class property.
Here is how you can create custom events: http://www.codeproject.com/Articles/...lass-in-VB-Net
Hope this helps.
Don't ask why, just reboot!
-
Feb 2nd, 2015, 09:43 AM
#6
Re: [RESOLVED] How to make a variable to act on events like Textbox.TextChanged
Just to expand on Alains post, it could be a simple as this....
VB Code:
Private _myProp As String Public Event myProp_Changed() Public Property myProp() As String Get Return _myProp End Get Set(ByVal value As String) If value <> _myProp Then value = _myProp RaiseEvent myProp_Changed() End If End Set End Property
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Feb 2nd, 2015, 11:11 AM
#7
Thread Starter
Member
Re: [RESOLVED] How to make a variable to act on events like Textbox.TextChanged
 Originally Posted by Alain
I'm glad you were able to find a solution by using a textbox, but just to expand on the subject a bit, if the textbox class didn't exist, the way to achieve the result you were after would have been by creating a class that would store your variable, and adding a custom event to react when that variable is changed through a class property.
Here is how you can create custom events: http://www.codeproject.com/Articles/...lass-in-VB-Net
Hope this helps.
 Originally Posted by kebo
Just to expand on Alains post, it could be a simple as this....
VB Code:
Private _myProp As String Public Event myProp_Changed() Public Property myProp() As String Get Return _myProp End Get Set(ByVal value As String) If value <> _myProp Then value = _myProp RaiseEvent myProp_Changed() End If End Set End Property
I can't thank you guys enough! This is exactly what I was looking for. No, seriously, I really mean it. I can say you guys just improved the performance of my software! You have my respect 
- Frek
-
Feb 2nd, 2015, 11:51 AM
#8
Re: [RESOLVED] How to make a variable to act on events like Textbox.TextChanged
I had already shown you this in your last thread how to raise events. Events should only ever be raised in One place. Read JMC's blog above in his signature that has a detailed tutorial on events.
-
Feb 2nd, 2015, 07:42 PM
#9
Re: [RESOLVED] How to make a variable to act on events like Textbox.TextChanged
 Originally Posted by ident
I had already shown you this in your last thread how to raise events. Events should only ever be raised in One place. Read JMC's blog above in his signature that has a detailed tutorial on events.
Specifically here:
http://jmcilhinney.blogspot.com.au/2...om-events.html
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|