We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

dealing with substrings in vb6

hi.
uhm. im having a problem with coding such conditional statement that would check if a certain input contains a certain subs tring.
for example. i have a text box that is used for the user to input a string. (0,1)
then i have a command button to determine if the string inputted contains a sub string of '1' on the 3rd position. if the inputted string includes '1' at the third position then a label would display "accepted!" if not, "not accepted"

eg.
input | output
000101 not accepted
001001 accepted
011010 accepted
11001 not accepted

thankyou so much for the help :)

4
Contributors
7
Replies
2 Days
Discussion Span
1 Year Ago
Last Updated
8
Views
Question
Answered
yeeitsneo
Light Poster
37 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

Post your code. So we can fix it.

Jx_Man
Senior Poster
3,520 posts since Nov 2007
Reputation Points: 1,468
Solved Threads: 514
Skill Endorsements: 64

Look up the MID, LEFT, RIGHT and INSTR commands.

WaltP
Posting Sage w/ dash of thyme
Team Colleague
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 36

Waltp is exactly right. You have to use MID command.

Such as an example with this:

Private Sub Command1_Click()
if Mid(text1.text, 3, 1) = 1 then
label1.caption = "Accepted!"
else
label1.caption = "Not accepted!"
end if
end sub


"The number "3" on the right side of the text1.text pertains to the position of the input text(3rd position)

Sam367
Light Poster
42 posts since Jan 2012
Reputation Points: 10
Solved Threads: 2
Skill Endorsements: 0

Waltp is exactly right. You have to use MID command.

Such as an example with this:

Private Sub Command1_Click()
if Mid(text1.text, 3, 1) = 1 then
label1.caption = "Accepted!"
else
label1.caption = "Not accepted!"
end if
end sub


"The number "3" on the right side of the text1.text pertains to the position of the input text(3rd position)

thanks.but what happens is here is that the conditions waiting for an input of 1 before it says not accepted. it would be better if the labels caption of not accepted would change as soon as the 3rd sub string of 0 is inputted.

yeeitsneo
Light Poster
37 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

thanks.but what happens is here is that the conditions waiting for an input of 1 before it says not accepted. it would be better if the labels caption of not accepted would change as soon as the 3rd sub string of 0 is inputted.

Ohh i see, then you have to put the code instead in the textbox itself and not with the command button.

For example:

Private Sub Text1_Change()
if Mid(text1.text, 3, 1) = 1 then
label1.caption = "Accepted!"
else
label1.caption = "Not accepted!"
end if
end sub

Try it! :)

Sam367
Light Poster
42 posts since Jan 2012
Reputation Points: 10
Solved Threads: 2
Skill Endorsements: 0
Question Answered as of 1 Year Ago by Sam367, WaltP and Jx_Man

Ohh i see, then you have to put the code instead in the textbox itself and not with the command button.

For example:

Private Sub Text1_Change()
if Mid(text1.text, 3, 1) = 1 then
label1.caption = "Accepted!"
else
label1.caption = "Not accepted!"
end if
end sub

Try it! :)

thanks!!

yeeitsneo
Light Poster
37 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

You're welcome! :)

Sam367
Light Poster
42 posts since Jan 2012
Reputation Points: 10
Solved Threads: 2
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0850 seconds using 2.71MB