Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8729317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:48:46+00:00 2026-06-13T08:48:46+00:00

I have an event handler which handles its event just fine. However, I don’t

  • 0

I have an event handler which handles its event just fine. However, I don’t want to be able to call the handler directly or, more specifically, give my fellow programmers the ability to call it directly, since I want to update nudCurrent.Value only when the laser current is set.

Public Class TestClass

    Dim WithEvents myCurrentSource As New CurrentSourceClass

    Private Sub TestScript()
        'among other things, sets current to 85
        myCurrentSource.SetCurrent(85)
    End Sub

    Private Sub handleLaserCurrentSet() Handles myCurrentSource.LaserCurrentSet
        Me.nudCurrent.Value = myCurrentSource.GetCurrent()
    End Sub

End Class

Public Class CurrentSourceClass

    Public Event LaserCurrentSet()

    Private currentSet As Double = Double.NaN

    Public Sub SetCurrent(ByVal dCurrentAmps As Double)
        ' set the current on the current source here
        Me.currentSet = dCurrentAmps
        ' then raise the event
        RaiseEvent LaserCurrentSet()
    End Sub

    Public Function GetCurrent() As Double
        Return Me.currentSet
    End Function

End Class

I can’t think of a way to restrict the access to the event handler routine within its scope, so I’m looking for an alternate way of doing this. What is the best practice?

*I understand that I could just put me.nudCurrent.Value = 85 after setting the current, but I like the neatness of the event driven UI updates. Can I have my cake and eat it too?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:48:47+00:00Added an answer on June 13, 2026 at 8:48 am

    You can use an anonymous event handler

    AddHandler myCurrentSource.LaserCurrentSet,
                    Sub()
                        Me.nudCurrent.Value = myCurrentSource.GetCurrent()
                    End Sub
    

    But keep in mind that the value can be set from anywhere inside the class. You cannot restrict that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a event handler which makes two AJAX calls to the server:
I have simple SSIS package in which On Error event handler I have created
I have a click handler, which has event.preventDefault. There is whole lot of logic
Should the view have nothing event specific in its interface and call the presenter
What I have is 2 functions (edit and save), which are event handlers bound
I have a page which has many event handlers. The code now reached 1000+
I have an event handler set up using plain javascript like this: myElement.addEventListener('drop', handleDrop,
I have an event handler that needs to determine a type and execute code
I have an event handler that will remove an element from a list of
I have an event handler bound to the hover event using the .hover method,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.