Results 1 to 14 of 14

Thread: Changing code at runtime.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    95
    Is there a way to add code to a control's event at run time? For example. I have 2 commandbuttons on my form and when i press the first one, I want it to place MsgBox("Hi") in the second one's click event.

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    No is the short answer.

    what are you trying to do, there may be a way round it.

  3. #3
    Guest

    no. exe's are effectively read-only

    trying to do this would be a MONUMENTAL WASTE OF TIME.

    declare a boolean variable and change it to true when you click the first button. then in the second button's click event, put an if then else block to only show the "HI" message if the variable is TRUE.


  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    95
    what i'm trying to do is create an exe completey from code.
    i just add the controls with code, set the properties with code, and code everything with code.

  5. #5
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Leavenworth KS USA
    Posts
    482
    This thread my give you some ideas.
    http://forums.vb-world.net/showthrea...threadid=15757
    You might also explore scripting options, though, what with the "I love you" & Herbie screw-ups, scripting may soon take a less accessable, open route.

  6. #6
    Guest

    Thumbs up

    There is actually a way:

    Create a label. And in the command button, put this:

    Code:
    Label1.caption = Label1.caption + 1
    If Label1.caption = "2" Then
    Msgbox "Hi"
    End If
    It won't display a msgbox until the command is pushed twice.
    Hope you get the idea.

  7. #7
    Guest
    But he'll get some problems when he does complex code with IF THEN statements. I think it's best to use Mongo's method.

  8. #8
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    There is kind of a way, you need to break all the code you might want to write into smalll functions and put them as public functions in a standard module and have a big array with their addresses, then you can call them with the callwindowproc API, they all need the same interface though, and it's not an easy thing to do, but running actual VB code is impossible.

  9. #9
    Guest

    Mathew Gates

    if you convince your father to give me a billion $$ or so I will tell you whats wrong with your code...
    oh well, I'll tell ya anyway..
    thats not CHANGING the code at runtime, what you have is using DIFFERENT code at runtime.

  10. #10
    Guest
    also, to be safe, you should do this


    Code:
    Label1.caption = Clng(Label1.caption) + 1
    If Label1.caption = "2" Then
    Msgbox "Hi"
    End If
    
    
    OR
    
    Label1.caption = Val(Label1.caption) + 1
    If Label1.caption = "2" Then
    Msgbox "Hi"
    End If

  11. #11
    Hyperactive Member Zaphod64831's Avatar
    Join Date
    Mar 2000
    Posts
    268
    Are you trying to get it to add another line of code for each time they click on the first button? If so you could get around it by placing the following line of code in the first button click event:
    Code:
    MsgNumber=MsgNumber+1
    and this in the second one:
    Code:
    For I = 1 To MsgNumber
        MsgBox("Hi")
    Next I
    Email: [email protected]

    Home Page: www.olemac.net/~hutch

    I'm bored, VERY bored, and I got bored with my sig. So I changed it to this.

  12. #12
    Hyperactive Member Zaphod64831's Avatar
    Join Date
    Mar 2000
    Posts
    268

    Or..

    Or if you're wanting it to execute one line of code before pressing the first button, another after then you could insert the following code in the first button's click event:

    Code:
    Clicked = True
    and this in the second's:
    Code:
    If Clicked = False Then
      'Do this
    Else
      MsgBox("Hi")
    End If
    I bet I really just don't know what you're talking about, but I thought I'd just throw in my two cents worth.
    Email: [email protected]

    Home Page: www.olemac.net/~hutch

    I'm bored, VERY bored, and I got bored with my sig. So I changed it to this.

  13. #13
    Guest
    If you want to create a program from scratch, keep in mind that there are some things that you just can't do. for example, you cannot change Read-Only values. Also, you cannot have access to some events like the Change event in the TextBox.

  14. #14
    Guest

    It's two t's! "Matthew Gates"

    Ah yes, forgot about the Val function. Sorry!
    But remember, i had the idea of doing this first!
    Sorry, I don't think I can spare dad's money.

    [Edited by Matthew Gates on 05-27-2000 at 08:40 PM]

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