Running VB subroutine from a button click...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NPela
    New Member
    • Mar 2010
    • 4

    Running VB subroutine from a button click...

    I'm an old-school programmer (real old - Fortran, Pascal, etc.) who has not written any code in 15 years or so. I got the bright idea to learn VB (2008 Express). All has been going well and I'm at the tail end of writing a fairly complex program that includes some graphic routines. I think this is a simple question, and I'm just confused because of the VB terminology.

    I have a graphic subroutine that I want to be able to call by clicking a button. The graphics routine works fine, and presents itself when I open the program. However, I need it to update as I change the data. VB will not let me call this routine. Here are the names of the two subs -

    [Private Sub Do_The_Graph(By Val sender As Object, ByVal e As System.Windows. Forms.PaintEven tArgs) Handles Me.Paint]

    [Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button3.Click]

    The question is, how do I cause "Do_The_Gra ph" to execute when I click "Button_3"? Both routines reside in the same Class (and I don't fully understand that yet, either).

    Thanks,
    Nick.
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    dear,

    If I understand your problem I think the next code will do what you want:

    Code:
    [Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click]
    
        call Do_The_Graph(.....)
    I hope this will help You.


    br,

    Comment

    • NPela
      New Member
      • Mar 2010
      • 4

      #3
      Doesn't do it...

      Thanks for your prompt reply.

      I had tried the "Call" statement, but I get an error message that says "Argument not specified for parameter of 'e' of 'Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As System.EventArg s)'.

      I've been going around in circles trying to determine what it needs for that 'e' parameter.

      Nick

      Comment

      • Guido Geurs
        Recognized Expert Contributor
        • Oct 2009
        • 767

        #4
        dear,

        Is't possible to attach your files?

        br,

        Comment

        • Guido Geurs
          Recognized Expert Contributor
          • Oct 2009
          • 767

          #5
          dear,

          Is the sub title OK ?

          normal it's=

          Code:
          Private Sub Command1_Click()
          
          End Sub
          br,

          Comment

          • NPela
            New Member
            • Mar 2010
            • 4

            #6
            I can't attach the code for contractual reasons.

            If I could just understand what the 'e' parameter is supposed to be, I might be OK.

            Nick.

            Comment

            • Guido Geurs
              Recognized Expert Contributor
              • Oct 2009
              • 767

              #7
              dear,

              Ok, no problem, we will try it by common sense.

              Q1: is the button a control not standard from MS VB6 ?
              If it's standard : which Reference is loaded ??
              If not, this is a control with his own var's !
              Is it possible to say which OCX or so you are using ?.
              In this case, you have to read the documentation of this control, in which I hope you will find an indication what the control is receiving and what are the dedicated var' to send to "Do_The_Gra ph";

              it's even possible that the "e" is a dedicated var which consist of other var's !

              br,

              Comment

              • Guido Geurs
                Recognized Expert Contributor
                • Oct 2009
                • 767

                #8
                dear,

                I have looked around and finally I'm fined out: this is VB.Net !
                Sorry but I'm a VB6 programmer and not familiar with VB.net.
                Maybe someone else can help you.

                Sorry, br,

                Comment

                • Guido Geurs
                  Recognized Expert Contributor
                  • Oct 2009
                  • 767

                  #9
                  dear,

                  This is VB.net ! (Sorry, I'm a VB6 programmer with no experience on VB.net)
                  Maybe this will help:
                  If you Google to "ByVal e As System.Windows. Forms.PaintEven tArgs" then you get Ms help on the topic. =>



                  br,

                  Comment

                  • NPela
                    New Member
                    • Mar 2010
                    • 4

                    #10
                    Thanks.

                    Thanks for trying to assist. I will do some more digging. MicroSoft's tutorials are not very good... they either assume you know nothing or assume you know everything!

                    Nick.

                    Comment

                    • funkyspiky
                      New Member
                      • Mar 2010
                      • 1

                      #11
                      Do_The_Graph is only called when the WM_PAINT message is requested (Form.Paint() event).

                      Been a while since I've done some VB but in .Net you should have a Me.Refresh() in any form controls, which should raise the Paint Event and that should call your function.

                      Comment

                      • Chris Chapman
                        New Member
                        • Oct 2010
                        • 1

                        #12
                        Call Graphics Subroutine from Button.Click

                        Hi, I have a question related to the above posts...

                        I'm trying to call a graphic subroutine from a separate button_click routine. Is this possible? I get the error message:

                        "Argument not specified for parameter 'e' of private sub ShowImage_Paint (sender as Object, e as System.Windows. Forms.PaintEven tArgs)"

                        A partial list of code is:

                        Private Sub btnSpot1_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnSpot1.Click
                        Call ShowImage_Paint ()
                        End Sub

                        Private Sub ShowImage_Paint (ByVal sender As System.Object, ByVal e As System.Windows. Forms.PaintEven tArgs) Handles MyBase.Paint
                        ' Create image.
                        Dim newImage As Image = Image.FromFile( "C:\Users\Famil y\Pictures\Blue _Counter.jpg")
                        ' Create Point for upper-left corner of image.
                        Dim ulCorner As New Point(470, 10)
                        ' Draw image to screen.
                        e.Graphics.Draw Image(newImage, ulCorner)
                        End Sub

                        Any possible solutions would be greatly appreciated!

                        Chris

                        Comment

                        Working...