Results 1 to 3 of 3

Thread: [RESOLVED] Adding unique tag after adding component

  1. #1

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Resolved [RESOLVED] Adding unique tag after adding component

    Ola,

    I'm adding labels at runtime to my form with a tag.

    Let's say I have 3 labels with the tags, "1", "2" and "3". I'm adding the tags by counting the labels + 1.

    When I remove a label with tag "2" from the form there are only 2 left. When I add a new label it will add a new tag "3", but that one already exist.
    So my "solution" isn't a very good one

    Although tag "2" is free, I want to give it "4".

    Any thoughts on how to code this properly?


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Adding unique tag after adding component

    Use a variable to store the next tag and method to get the next tag. The method will get the current value of the variable and increment it. So you're always guaranteed to get increasing values.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Adding unique tag after adding component

    Great tip John. Thanks.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

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