|
-
Feb 23rd, 2013, 09:15 PM
#1
Thread Starter
Addicted Member
How to send Text from TextBox only "ONCE", using a Timer! Instead of Flooding?
Hello everyone! I am going to ask newbie question....
I am creating a Text-Sender, using a Timer to send text to another window.
But It keeps flooding the page totally! I only need to send the TEXT once.
I know I can use a button, but I have to use this timer because of the method I use. I have now tried in 200 different ways, but I think, I cant make it send once.
How I can get some help. Thanks a lot for this in advance..
Miklo
-
Feb 23rd, 2013, 09:31 PM
#2
Re: How to send Text from TextBox only "ONCE", using a Timer! Instead of Flooding?
Have you tried stopping the timer ? 
Simply add code as the first line in the timer elapsed event to stop the timer. This way it fires one time and stops.
-
Feb 24th, 2013, 01:18 PM
#3
Thread Starter
Addicted Member
Re: How to send Text from TextBox only "ONCE", using a Timer! Instead of Flooding?
 Originally Posted by DataMiser
Have you tried stopping the timer ?
Simply add code as the first line in the timer elapsed event to stop the timer. This way it fires one time and stops.
Thanks Datamiser, Let me see If I got this right... You mean the timer should be still be Enabled? Right.?
And simply add my line on top?
Well i am using a "DIM" because I wanted to send to when a Window opens.. ANd every time a windows opens , for example a text editor.. Then it starts flooding badly..
I tried even create my own Chat Sending, That does the same thing, Flooding totally..
Hope I could get a bit more explanation.. And will try your way also, If I got it right.. Thanks DataMiser
Last edited by Miklogak; Feb 24th, 2013 at 01:34 PM.
-
Feb 24th, 2013, 04:04 PM
#4
Re: How to send Text from TextBox only "ONCE", using a Timer! Instead of Flooding?
 Originally Posted by Miklogak
I know I can use a button, but I have to use this timer because of the method I use. I have now tried in 200 different ways, but I think, I cant make it send once.
Miklo
Miklo, have you considered using a flag ( a Boolean variable) set it when you want a text, re-set it as part of the send code...
If Flag then
xxxxxsend.... etc
xxxxxFlag = False
End If
Poppa.
Along with the sunshine there has to be a little rain sometime.
-
Feb 24th, 2013, 04:16 PM
#5
Re: How to send Text from TextBox only "ONCE", using a Timer! Instead of Flooding?
Every time the timer reaches its interval (or 'ticks') it executes the code in the tick event handler. That's every time. So if you have it set to 100ms with the send message code in its tick, it sends the message 10 times a second. The only way to prevent that is to stop the timer or to have a conditional code which ensures that once the message is sent it can't be sent any more.
Now you say that you have to use a timer but if your latter post is more representative of your aim here ("I wanted to send to when a Window opens") but I'm not entirely sure that that's true or, at least, if you must use a timer to monitor Windows activity, it is by no means obvious that the response should also be in the timer event.
To clarify ..
To start a timer .... Timer1.Enabled = True -or- Timer1.Start()
To stop a timer .... Timer1.Enabled = False -or- Timer1.Stop()
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 3rd, 2013, 07:15 PM
#6
Thread Starter
Addicted Member
Re: How to send Text from TextBox only "ONCE", using a Timer! Instead of Flooding?
First of all sorry for late reply, but I always read my old questions on here! So thank you for answering!
@Popa Mintin thank you so much, I am going to take a look at it since I am very new in vbnet.....
@Dunfidlinn, i made a few changes, so now I am still stuck in there and I have added a "Button1.Perform.Click()" in my timer instead of the code! So I have added the complete "Send Text" code below a button, and I have also created a function called "SendText()"... But still flooding.. And how can i create the so-called "conditional code" to make it only click onces or send once!
I would be appreciated for some short explanation, Thank you very much in advance
Last edited by Miklogak; May 3rd, 2013 at 07:18 PM.
A huge thanks to all the Great Developers and Helpers on vBForums for helping me and many others! Special thanks to Dunfiddlin, Paul, TechnoGome, , JayInThe813, ident for helping me with my projects througout the years. Incl. those i forgot to mention!
-
May 4th, 2013, 02:00 PM
#7
Re: How to send Text from TextBox only "ONCE", using a Timer! Instead of Flooding?
I'm still kinda struggling to understand what you are actually doing here to be honest. It all seems a bit disconnected and I still don't really get why a timer's involved at all. Could you break it down literally step by step?
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 11th, 2013, 04:05 PM
#8
Thread Starter
Addicted Member
Re: How to send Text from TextBox only "ONCE", using a Timer! Instead of Flooding?
 Originally Posted by dunfiddlin
I'm still kinda struggling to understand what you are actually doing here to be honest. It all seems a bit disconnected and I still don't really get why a timer's involved at all. Could you break it down literally step by step?
hi Dun, I am still strugling with that part, But i will try to explain this in other way and with another part of my project that I am having almost the same issue with the timer...
I have created an option to Welcome users into a Chat-Room by grabbing usernames and adding them into a ListBox. I am using a TEXTBOX and LISTBOX for this.
The Textbox grabs the usernames and sends it to the LISTBOX. Now my problem is that the TIMER as earlier explained, Grabs the usernames and adding it to the LISTBOX over and over again! So when I watch it, it keeps adding the same username on each line and wont stop...
How can I make the usernames be added a single time....? And the code is added below my timer. and i am assuming that there must be a way for this.....
Here is the CODE That use for my timer:
Code:
'My Grab Username Code
TextBox1.Text = GrabUser(TextBoxUser.Text)
For Each user As String In TextBox1.Lines
ListBox1.Items.Add(user)
If ListBox1.Items.Contains(TextBox1.Lines) Then
'If user is in Chat Room, Then.... Show Label
Label1.Text = "User is already in Chat Room"
Timer1.Enabled = False
Else
'If user is NOT in Chat Room, Then.... ADD USER
ListBox1.Items.Add(user)
Label1.Text = "New user has joined the Chat Room"
End If
Next
End Sub
Hope that it was easy to figure out. I am just not good with Timers, and hope I could get some help with it!
Thanks a lot in advance to everyone who have answered to this topic!
Last edited by Miklogak; May 11th, 2013 at 04:26 PM.
A huge thanks to all the Great Developers and Helpers on vBForums for helping me and many others! Special thanks to Dunfiddlin, Paul, TechnoGome, , JayInThe813, ident for helping me with my projects througout the years. Incl. those i forgot to mention!
-
May 11th, 2013, 08:37 PM
#9
Re: How to send Text from TextBox only "ONCE", using a Timer! Instead of Flooding?
Ok, add this function.
vb.net Code:
Function NoDuplicatesInList(lst As ListBox, str As String) As Boolean Dim tf As Boolean Dim x As Integer If lst.Items.Count = 0 And str <> "" Then lst.Items.Add(str) 'check to make sure no duplicate entries get into list box Else tf = False For x = 0 To lst.Items.Count - 1 If lst.Items(x) <> str Then tf = False Else tf = True Exit For End If Next x If tf = False And str <> "" Then lst.Items.Add(str) End If End If Return tf End Sub
Then revise your code ...
vb.net Code:
TextBox1.Text = GrabUser(TextBoxUser.Text) For Each user As String In TextBox1.Lines If NoDuplicatesInList(ListBox1, user) Then 'If user is in Chat Room, Then.... Show Label Label1.Text = "User is already in Chat Room" Else 'If user is NOT in Chat Room, Then.... ADD USER Label1.Text = "New user has joined the Chat Room" End If Next
That should solve your immediate problem (if my brain is still working at nearly 2.30am!) but you may also need to think about how to determine when someone leaves the room so that they can be deleted from the list.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
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
|