2 VB6 Coding Questions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #16
    Originally posted by Killer42
    Bit of an understatement, really - it's about 5 days now.

    I'll go back over this thread now, as I've forgotten what it's about.
    Ok, the situation is still a little vague. But for the sake of discussion, let's assume that you have a command button called Command1, and a textbox called Text1. That's the default name VB gives them when you create them.

    VB is an event-driven language. When the user clicks on the button control, it fires an event procedure called Command1_Click. That's where you would place the code to do something when the button is clicked. (Note that a "click" on the button can also be triggered by the keyboard, but that's not really relevant to this discussion.)

    So, let's further assume that when the button is clicked, you want to take the text which is displayed on the button (it's .Caption property) and place it in the textbox. You do this by setting the .Text property of the textbox.

    The entire code required to do this would look something like this...

    [CODE=vb]Option Explicit

    Private Sub Command1_Click( )
    Text1.Text = Command1.Captio n
    End Sub[/CODE]However, you won't need to enter all of that. You just double-click on the button in the form design window, and it will create the Command1_Click routine - then you simply fill in what to do.

    Let me know whether this is what you're after.

    However, I'd recommend you have a look on the web for VB tutorials - there are plenty of them around. TheScripts is not really a getting-started site, so much. We're more geared toward helping programmers who run into specific problems in their code.

    You might also want to consider downloading a free copy of VB 2005 Express Edition from Microsoft's website. While I love VB6, it is almost 10 years old, so it would seem to make more sense to learn the newer version.

    Comment

    • Filter2700
      New Member
      • May 2007
      • 10

      #17
      Thanks for the help, that's exactly what I'm talking about. One more final question, how do I choose what the text will appear like instead of "text". For example, how would I make it appear "hi" in the text box?

      Code:
      Option Explicit
       
      Private Sub Command1_Click()
        Text1.Text = Command1.[B]Caption[/B]
      End Sub
      Would I make "Caption" say what I want to appear in the text box?

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #18
        Originally posted by Filter2700
        Thanks for the help, that's exactly what I'm talking about. One more final question, how do I choose what the text will appear like instead of "text". For example, how would I make it appear "hi" in the text box?
        Code:
        Option Explicit
         Private Sub Command1_Click()
          Text1.Text = Command1.[B]Caption[/B]
        End Sub
        Would I make "Caption" say what I want to appear in the text box?
        Simply place on the right-hand sifde of the "=" sign whatever you want to assign to the variable or property that's on the left. In other words, replace Command1.Captio n with whatever you want to place in the textbox.

        You really should play around with the code, and have a look at some beginner VB tutorials. There are plenty of them around on the web.

        Comment

        • Filter2700
          New Member
          • May 2007
          • 10

          #19
          Definately, this was a very simple code that I probably could have figured out on my own by messing around and searching. I am going to find some good tutorials. Thanks for the help man, really. I appreciate it, thanks again.

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #20
            Originally posted by Filter2700
            Definately, this was a very simple code that I probably could have figured out on my own by messing around and searching. I am going to find some good tutorials. Thanks for the help man, really. I appreciate it, thanks again.
            Glad we could help. But a good tutorial will lead you through the basics (no pun intended) much better than we can do in a few messages here.

            Hope we'll see you again as you progress, though. :)

            Comment

            Working...