Results 1 to 9 of 9

Thread: How to send Text from TextBox only "ONCE", using a Timer! Instead of Flooding?

  1. #1

    Thread Starter
    Addicted Member Miklogak's Avatar
    Join Date
    Jan 2013
    Posts
    203

    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

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    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.

  3. #3

    Thread Starter
    Addicted Member Miklogak's Avatar
    Join Date
    Jan 2013
    Posts
    203

    Re: How to send Text from TextBox only "ONCE", using a Timer! Instead of Flooding?

    Quote Originally Posted by DataMiser View Post
    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.

  4. #4
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,500

    Re: How to send Text from TextBox only "ONCE", using a Timer! Instead of Flooding?

    Quote Originally Posted by Miklogak View Post
    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.

  5. #5
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  6. #6

    Thread Starter
    Addicted Member Miklogak's Avatar
    Join Date
    Jan 2013
    Posts
    203

    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!

  7. #7
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  8. #8

    Thread Starter
    Addicted Member Miklogak's Avatar
    Join Date
    Jan 2013
    Posts
    203

    Re: How to send Text from TextBox only "ONCE", using a Timer! Instead of Flooding?

    Quote Originally Posted by dunfiddlin View Post
    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!

  9. #9
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: How to send Text from TextBox only "ONCE", using a Timer! Instead of Flooding?

    Ok, add this function.

    vb.net Code:
    1. Function NoDuplicatesInList(lst As ListBox, str As String) As Boolean
    2.  
    3.         Dim tf As Boolean
    4.         Dim x As Integer
    5.  
    6.  
    7.         If lst.Items.Count = 0 And str <> "" Then
    8.             lst.Items.Add(str)
    9.             'check to make sure no duplicate entries get into list box
    10.         Else
    11.             tf = False
    12.             For x = 0 To lst.Items.Count - 1
    13.                 If lst.Items(x) <> str Then
    14.                     tf = False
    15.                 Else
    16.                     tf = True
    17.                     Exit For
    18.                 End If
    19.             Next x
    20.             If tf = False And str <> "" Then
    21.                 lst.Items.Add(str)
    22.             End If
    23.         End If
    24.         Return tf
    25.     End Sub

    Then revise your code ...
    vb.net Code:
    1. TextBox1.Text = GrabUser(TextBoxUser.Text)
    2.                      For Each user As String In TextBox1.Lines
    3.            If NoDuplicatesInList(ListBox1, user) Then
    4.                 'If user is in Chat Room, Then.... Show Label
    5.                  Label1.Text = "User is already in Chat Room"
    6.             Else
    7.                'If user is NOT in Chat Room, Then.... ADD USER
    8.                Label1.Text = "New user has joined the Chat Room"
    9.             End If
    10.  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
  •  



Click Here to Expand Forum to Full Width