Results 1 to 7 of 7

Thread: [RESOLVED] Simple Question

  1. #1

    Thread Starter
    Addicted Member cc2^^'s Avatar
    Join Date
    Apr 2008
    Location
    Right behind you.
    Posts
    165

    Resolved [RESOLVED] Simple Question

    My goal is to make a label have a caption of a textbox, but it's not that simple... It would be easier to explain with examples.

    Example: text1.text has the text:

    00000000000`cc2`00000000000000

    And then label1.caption will be:

    cc2

    Is there a code that makes the label have the caption of the textbox between the two ``? Note that sometimes there are more characters before the "``".

    (sorry for my bad english, i hope you still understand)
    I think I am, therefore, I am. I think.

  2. #2
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Simple Question

    you can place code in the textbox's text_changed event that updates the labels with code. Then manually extract whatever is between the '' with instr and mid.
    code similar to this:
    Code:
    a = instr("'", text1.text)'get location of first apostrophe
    'if not found exit sub...
    if a = 0 then label1.text = "": exit sub
    b = instr(a + 1, "'", text1.text) 'search for 2nd apostrophe 
    c = b - a -1'get lengh of string between them
    label1.text = mid(text1.text, a, c) 'should return a string starting at postition a length c
    keep in ind i did this from memory as i dont use vb6 any more so my syntax on the instr may be backwards but i am sure you can work it out.

    As a side note: non-descriptive post titles are frowned upon. People aren't goiing to know if they have any relevant data towards answering your post just by reading the title unless you make it relevant.

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Simple Question

    Use InStr() to locate the tick mark, then use it again to locate the 2nd tick mark. Now that you have those 2 positions, use Mid$() to return the text btwn those two positions.

    Or as Lord Orwell proposes, who beat me to the punch.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    Addicted Member cc2^^'s Avatar
    Join Date
    Apr 2008
    Location
    Right behind you.
    Posts
    165

    Re: [RESOLVED] Simple Question

    I think i marked the thread resolved to early, the code lord orwell gave me didn't do anything...
    Last edited by cc2^^; Jun 20th, 2009 at 11:04 AM.
    I think I am, therefore, I am. I think.

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [RESOLVED] Simple Question

    He transposed the InStr() parameters and his final calc was off just a tad; I added the +1 in the final line of code. Try this but ensure you use the correct tick symbol, in the code below ' is used by in your example you used `. Just make sure you are parsing on the correct character

    Code:
    Dim A As Long, B As Long, C As Long
    A = InStr(TEXT1.Text, "'") 'get location of first apostrophe
    'if not found exit sub...
    If A = 0 Then LABEL1.Text = "": Exit Sub
    B = InStr(A + 1, TEXT1.Text, "'") 'search for 2nd apostrophe
    C = B - A - 1 'get lengh of string between them
    LABEL1.Text = Mid(TEXT1.Text, A + 1, C) 'should return a string starting at postition a length c
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6

    Thread Starter
    Addicted Member cc2^^'s Avatar
    Join Date
    Apr 2008
    Location
    Right behind you.
    Posts
    165

    Re: [RESOLVED] Simple Question

    Ok it works now Thanks Alot!
    I think I am, therefore, I am. I think.

  7. #7
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: [RESOLVED] Simple Question

    Quote Originally Posted by LaVolpe View Post
    He transposed the InStr() parameters and his final calc was off just a tad; I added the +1 in the final line of code. Try this but ensure you use the correct tick symbol, in the code below ' is used by in your example you used `. Just make sure you are parsing on the correct character

    Code:
    Dim A As Long, B As Long, C As Long
    A = InStr(TEXT1.Text, "'") 'get location of first apostrophe
    'if not found exit sub...
    If A = 0 Then LABEL1.Text = "": Exit Sub
    B = InStr(A + 1, TEXT1.Text, "'") 'search for 2nd apostrophe
    C = B - A - 1 'get lengh of string between them
    LABEL1.Text = Mid(TEXT1.Text, A + 1, C) 'should return a string starting at postition a length c
    hehe i clearly stated they might be backwards

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