|
-
Jun 20th, 2009, 08:47 AM
#1
Thread Starter
Addicted Member
[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.
-
Jun 20th, 2009, 09:21 AM
#2
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.
-
Jun 20th, 2009, 09:23 AM
#3
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.
-
Jun 20th, 2009, 10:39 AM
#4
Thread Starter
Addicted Member
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.
-
Jun 20th, 2009, 12:09 PM
#5
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
-
Jun 20th, 2009, 01:08 PM
#6
Thread Starter
Addicted Member
Re: [RESOLVED] Simple Question
Ok it works now Thanks Alot!
I think I am, therefore, I am. I think.
-
Jun 20th, 2009, 05:35 PM
#7
Re: [RESOLVED] Simple Question
 Originally Posted by LaVolpe
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|