locked
calling an event RRS feed

  • Question

  • For example i have a numeric updown:

    Private Sub NumericUpDown1_ValueChanged(sender As System.Object, e As System.EventArgs) Handles NumericUpDown_xxx.ValueChanged

    program lines .............

    end

    if i want to execute these lines again, how can i call this event?

    Tuesday, August 18, 2020 2:33 PM

All replies

  • Hi

    Put the ' .......... program lines' into another Sub and call that Sub from the NumericUpDown_xxx.ValueChanged and from wherever else you need to execute these lines.


    Regards Les, Livingston, Scotland


    • Edited by leshay Tuesday, August 18, 2020 2:35 PM
    Tuesday, August 18, 2020 2:35 PM
  • Change this

        Private Sub NumericUpDown1_ValueChanged(sender As System.Object,
                                                e As System.EventArgs) Handles NumericUpDown_xxx.ValueChanged
    
            'program lines .............
    
        End Sub
    

    to this

        Private Sub NumericUpDown1_ValueChanged(sender As System.Object,
                                                e As System.EventArgs) Handles NumericUpDown_xxx.ValueChanged
    
            ProgramLines()
        End Sub
    
        Private Sub ProgramLines()
            'program lines .............
        End Sub
    

    This way the code can be called outside of the event also.


    Search Documentation

    SerialPort Info

    Multics - An OS ahead of its time.

     "Those who use Application.DoEvents have no idea what it does

        and those who know what it does never use it."    former MSDN User JohnWein

    Tuesday, August 18, 2020 2:39 PM
  • Hello,

    In this case I'm passing the actual NumericUpDown control (as object) to another method/sub.

    Public Class Form1
        Private Sub InvokeEventButton_Click(sender As Object, e As EventArgs) _
            Handles InvokeEventButton.Click
    
            WorkForNumericUpDown(NumericUpDown1)
    
        End Sub
    
        Private Sub NumericUpDown1_ValueChanged(sender As Object, e As EventArgs) _
            Handles NumericUpDown1.ValueChanged
    
            WorkForNumericUpDown(sender)
    
        End Sub
    
        Private Sub WorkForNumericUpDown(sender As Object)
    
            Dim nud = CType(sender, NumericUpDown)
            Console.WriteLine(nud.Value)
            '
            ' Do what you need to do here
            '
        End Sub
    End Class
    


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, August 18, 2020 2:55 PM
  • You can not call an event, you can call the method which handles the event. 

    NumericUpDown1_Valuechanged(me,nothing)



    Success
    Cor


    Tuesday, August 18, 2020 7:30 PM