help with VB
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: help with VB

  1. #1
    Junior Member
    Join Date
    Apr 2005
    Posts
    2

    help with VB

    this is my first post here and im not sure this is where this goes but im going to put it here anyway.

    im using a book to learn VB over the summer so that when the spring semister comes around i want to be able to start C++. and in this book it tells me to add text to an event(cant think of the correct term, sorry) that will cause a text to appear in a caption once a command button is clicked. the text they said to place was lblClick.caption = "Clicked!!" and im supposed to add that to the code, but everytime i run it it get an error. i was hoping someone on here could point me in the correct direction

  2. #2
    In And Above Man Black Cluster's Avatar
    Join Date
    Feb 2005
    Posts
    912
    I bet you are placing the code in the wrong place or not naming the objects as they mention in the book. Double click on the command button and then write lblClick.caption = "Clicked!!" in its block. Then it will work pretty well. Just make sure that you have renamed the label to the proper name.

    Just make sure that you are naming correctly. Do you know how to name objects?
    \"The only truly secure system is one that is powered off, cast in a block of concrete and sealed in a lead-lined room with armed guards - and even then I have my doubts\".....Spaf
    Everytime I learn a new thing, I discover how ignorant I am.- ... Black Cluster

  3. #3
    Senior Member
    Join Date
    Apr 2004
    Posts
    1,130
    what kind of error? something like
    "lblclick is undefined" or
    "lblclick.caption is an unknown property"?
    Meu sítio

    FORMAT C: Yes ...Yes??? ...Nooooo!!! ^C ^C ^C ^C ^C
    If I die before I sleep, I pray the Lord my soul to encrypt.
    If I die before I wake, I pray the Lord my soul to brake.

  4. #4
    Ninja Code Monkey
    Join Date
    Nov 2001
    Location
    Washington State
    Posts
    1,027
    Hrm....if you are using the visual forms designer (where you drag and drop the buttons and so on) you can double click the button at design time and that will open up a code window with the appropriate event displayed. Just enter your code into that event.

    Below is what it looks like when you double click your button at design time:

    Private Sub Command1_Click()
    <enter your code here>
    End Sub
    "When I get a little money I buy books; and if any is left I buy food and clothes." - Erasmus
    "There is no programming language, no matter how structured, that will prevent programmers from writing bad programs." - L. Flon
    "Mischief my ass, you are an unethical moron." - chsh
    Blog of X

  5. #5
    Junior Member
    Join Date
    Apr 2005
    Posts
    11
    What they said, presuming your button is called Command1, and you have a caption box that you renamed lblClick, your code should look something like this, like Juridian said, just double click the button you made-

    Private Sub Command1_Click()
    lblClick.caption = "Clicked!!"
    End Sub

  6. #6
    Junior Member
    Join Date
    Apr 2005
    Posts
    2
    i havent had a chance to look at it since i posted this but i dont know how to rename labels

  7. #7
    In And Above Man Black Cluster's Avatar
    Join Date
    Feb 2005
    Posts
    912
    right click on the label you want and then click properties, In the opened box, usually at your right, click on name, at the top, and then change it to whatever you want. Use this for all objects.
    Don't get confused between the Name and caption of the label.

    See attached pic
    \"The only truly secure system is one that is powered off, cast in a block of concrete and sealed in a lead-lined room with armed guards - and even then I have my doubts\".....Spaf
    Everytime I learn a new thing, I discover how ignorant I am.- ... Black Cluster

  8. #8
    Ninja Code Monkey
    Join Date
    Nov 2001
    Location
    Washington State
    Posts
    1,027
    You open up the code view and then do a find and replace on the old name, replacing it with the new one.

    I'd recommend doing a bit of reading, this is the stuff they start teaching you from the beginning.
    "When I get a little money I buy books; and if any is left I buy food and clothes." - Erasmus
    "There is no programming language, no matter how structured, that will prevent programmers from writing bad programs." - L. Flon
    "Mischief my ass, you are an unethical moron." - chsh
    Blog of X

  9. #9
    Junior Member
    Join Date
    Apr 2005
    Posts
    11
    when you select an obiect on the form layout, the command button you created for instance, on the right side, you will see the properties of the object, such as what it says, the font style, whether or not it is hidden and such, I haven't used vb for a while, and don't remember what it is exactly, but one of the first ones should show the name of the selected object, such as lbl1, or command1, just click and change, someone correct me if I'm wrong, haven't used it for a while.

  10. #10
    Ninja Code Monkey
    Join Date
    Nov 2001
    Location
    Washington State
    Posts
    1,027
    That would start the process. But the editor does not go through and rename all references to the object for you automatically. A simple find and replace would probably be simpler.
    "When I get a little money I buy books; and if any is left I buy food and clothes." - Erasmus
    "There is no programming language, no matter how structured, that will prevent programmers from writing bad programs." - L. Flon
    "Mischief my ass, you are an unethical moron." - chsh
    Blog of X

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •