-
Mar 14th, 2015, 12:55 AM
#1
Thread Starter
Enjoy the moment
[RESOLVED] How to check if a Word in a TextBox contains "+" Dosnt work For me
i want to check if a text box contains "+" but what ever i wright in the code it just passes straight to end if
Code:
If ChkProcess.Value = True Then
If InStr(TxtServiceName.Text, "+") <> 0 Then
TxtServiceName.SetFocus
MsgBox "the text Must Contain This Character before proceeding", vbInformation
Exit Sub
End If
End If
tnx for any help
salsa31
-
Mar 14th, 2015, 01:05 AM
#2
Thread Starter
Enjoy the moment
Re: How to check if a Word in a TextBox contains "+" Dosnt work For me
i think i got it
Code:
If Not InStr(TxtServiceName.Text, "+") > 0 Then
-
Mar 14th, 2015, 01:27 AM
#3
Re: How to check if a Word in a TextBox contains "+" Dosnt work For me
InStr(TxtServiceName.Text, "+") <> 0 is correct. So is InStr(TxtServiceName.Text, "+") > 0
If Not InStr(TxtServiceName.Text, "+") > 0 is to check for the absence of the + mark
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Mar 14th, 2015, 01:33 AM
#4
Thread Starter
Enjoy the moment
Re: How to check if a Word in a TextBox contains "+" Dosnt work For me
hey james i didnt quite understand what you said
to use if not <> 0 or If Not InStr(TxtServiceName.Text, "+") > 0?
-
Mar 14th, 2015, 04:42 AM
#5
Hyperactive Member
Re: How to check if a Word in a TextBox contains "+" Dosnt work For me
I wonder why InStr(TxtServiceName.Text, "+") <> 0 or InStr(TxtServiceName.Text, "+") > 0 or If Not InStr(TxtServiceName.Text, "+") > 0 when InStr(TxtServiceName.Text, "+") = 0 does the same thing directly?
-
Mar 14th, 2015, 05:34 AM
#6
Member
Re: How to check if a Word in a TextBox contains "+" Dosnt work For me
if instr(1,Text1.Text,"+") then
'Your code
else
'Your code
end if
-
Mar 14th, 2015, 08:26 AM
#7
Re: How to check if a Word in a TextBox contains "+" Dosnt work For me
Originally Posted by salsa31
i want to check if a text box contains "+" but what ever i wright in the code it just passes straight to end if
Code:
If ChkProcess.Value = True Then
If InStr(TxtServiceName.Text, "+") <> 0 Then
TxtServiceName.SetFocus
MsgBox "the text Must Contain This Character before proceeding", vbInformation
Exit Sub
End If
End If
tnx for any help
salsa31
Basically you are telling it the opposite of what you want
Code:
If InStr(TxtServiceName.Text, "+") <> 0 Then
Is the same as saying
If + exists in the string then do this
The value will be 0 if it does not exist and will be >0 if it does
Code:
If Not InStr(TxtServiceName.Text, "+") > 0 Then
This is functional but not how I would do it
I would use either
Code:
If Not InStr(TxtServiceName.Text, "+") Then
or
Code:
If InStr(TxtServiceName.Text, "+")=0 Then
I wonder why InStr(TxtServiceName.Text, "+") <> 0 or InStr(TxtServiceName.Text, "+") > 0 or If Not InStr(TxtServiceName.Text, "+") > 0 when InStr(TxtServiceName.Text, "+") = 0 does the same thing directly?
They do not all do the same thing 1 and 2 will be true if the + exists in the string 3 and 4 will be false if it exists
-
Mar 14th, 2015, 08:46 AM
#8
Re: How to check if a Word in a TextBox contains "+" Dosnt work For me
Just to butt in and help simplify (although DM did a good job) furthur....
the function Instr() returns the location (integer) where the search string (in your case "+") starts.
If the string is not found, it returns zero (0).
If you have a textbox with "HairDry + Manicure" you could did this:
Code:
if instr(text1.text,"+") = 0 then
'code here would NOT run because instr() returned a 9 (9th character, including the space)
else
'code here WOULD run because 9 is not equal to 0
end if
OR
Code:
if NOT instr(text1.text,"+") then 'same as if instr(text1,text,"+") <> 0
'run code here
end if
Last edited by SamOscarBrown; Mar 14th, 2015 at 08:49 AM.
-
Mar 14th, 2015, 08:52 AM
#9
Re: How to check if a Word in a TextBox contains "+" Dosnt work For me
...and, for example, if you are searching for a longer string, like "salsa"..
In this example, you tell me what value would be returned to x:
Dim x as integer
x=instr("Where in the world is salsa sandiego?","salsa")
-
Mar 14th, 2015, 08:57 AM
#10
Thread Starter
Enjoy the moment
Re: How to check if a Word in a TextBox contains "+" Dosnt work For me
i see your point the problem is if i have 3 + then what?
i mean like this
Code:
HairdDry + Manicure + HairCut
i will get a error again and again
the combobox can contain up to 3 names in 1 line
-
Mar 14th, 2015, 09:07 AM
#11
Re: How to check if a Word in a TextBox contains "+" Dosnt work For me
It returns the FIRST occurrence.
Let me ask you...why are you now trying to use Instr()....the Split() command all have described to you is more applicable for your issue.
Dim strParts() as String
strParts = Split(combobox.text,"+")
then, just check for ubound of strParts to find out how many treatments there are
in this case, strParts(0) would equal HairDry
strParts(1) would equal Manicure
and strParts(2) would equal Haircut
and ubound of strParts would be 2...so number of treatments would be 3 (0 plus 1 plus 2)
YOu don't need instr() function at all here.
-
Mar 14th, 2015, 09:17 AM
#12
Thread Starter
Enjoy the moment
Re: How to check if a Word in a TextBox contains "+" Dosnt work For me
Let me ask you...why are you now trying to use Instr()....the Split() command all have described to you is more
beacuse i am making inserts if the combobox contains then 1 more name
e.x
if combobox has 1 name only with out this + then i use only 1 insert
if combobox has 2 names [name1+name2] then i insert twice
if combobox has 3 names[name1+name2+name3] then insert 3 times
-
Mar 14th, 2015, 09:19 AM
#13
Re: How to check if a Word in a TextBox contains "+" Dosnt work For me
I showed you how to use a loop on the Ubound.
You do not need to know how many are there.
You do not need to use Instr() at all
You need to follow instructions and ask questions if you do not understand
-
Mar 14th, 2015, 09:26 AM
#14
Thread Starter
Enjoy the moment
Re: How to check if a Word in a TextBox contains "+" Dosnt work For me
You need to follow instructions and ask questions if you do not understand
i did sir and i dont understand
i am trying to learn from you amigos but what seems to you easy is hard for me with lack of experience i have
self learning is very hard then school learning sir
-
Mar 14th, 2015, 09:36 AM
#15
Re: How to check if a Word in a TextBox contains "+" Dosnt work For me
Originally Posted by salsa31
i did sir and i dont understand
What don't you understand? As I said you need to ask questions if you do not understand.
i am trying to learn from you amigos but what seems to you easy is hard for me with lack of experience i have
self learning is very hard then school learning sir
Trust me I know what it is like to learn from self study. This is how I learned to do what I do and I did it when there was no internet to search and no one to ask questions. I literally learned by myself using just the book that came with the PC and a lot of trial and error or at least that is how I started. Later I did buy additional books and newer versions of languages came with online help and then eventually I got a job where there were other experienced programmers that I could talk to and of course the internet came to be a great resource.
Learning is much easier if you pay close attention to examples and make sure you understand them before moving on. If someone gives you code that works but you do not understand and you just move on then when you face the same issue again you still will not know how to deal with it.
Ask direct, detailed questions when you do not understand something. Give full detailed answers when someone asks you a question.
-
Mar 14th, 2015, 09:37 AM
#16
Re: How to check if a Word in a TextBox contains "+" Dosnt work For me
Look at this simple program....
Attachment 124701
-
Mar 14th, 2015, 09:50 AM
#17
Thread Starter
Enjoy the moment
Re: How to check if a Word in a TextBox contains "+" Dosnt work For me
tnk you very much sami
Learning is much easier if you pay close attention to examples and make sure you understand them before moving on. If someone gives you code that works but you do not understand and you just move on then when you face the same issue again you still will not know how to deal with it.
you are right DM sir i need to pay more attention i appreciate your help and time
-
Mar 14th, 2015, 10:36 AM
#18
Re: How to check if a Word in a TextBox contains "+" Dosnt work For me
Originally Posted by Daniel Duta
I wonder why InStr(TxtServiceName.Text, "+") <> 0 or InStr(TxtServiceName.Text, "+") > 0 or If Not InStr(TxtServiceName.Text, "+") > 0 when InStr(TxtServiceName.Text, "+") = 0 does the same thing directly?
You might want to re-think this
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Mar 14th, 2015, 01:46 PM
#19
Hyperactive Member
Re: How to check if a Word in a TextBox contains "+" Dosnt work For me
Originally Posted by jmsrickland
You might want to re-think this
What should I re-think? Let's take the string s="One+two". If InStr(s, "+")=0 then my text doesn't contain the "+" character. The question was simply "How to check if a Word in a TextBox contains "+". Sorry but I cannot get other meaning.
-
Mar 14th, 2015, 02:02 PM
#20
Re: [RESOLVED] How to check if a Word in a TextBox contains "+" Dosnt work For me
I wonder why
InStr(TxtServiceName.Text, "+") <> 0 or
InStr(TxtServiceName.Text, "+") > 0 or
Not InStr(TxtServiceName.Text, "+") > 0 when
InStr(TxtServiceName.Text, "+") = 0 does the same thing directly?
Because you are making it sound like the last statement does the same thing as the first three statements and that is not correct. Actually, the first two are the same and the last two are the same
Also, since the question was "How to check if a Word in a TextBox contains "+" then you should use <> 0 or > 0 to see if the word contains a + sign where you do just the opposite using = 0 otherwise OP's If statement will not be executed and OP wants to enter the If clause if it does where your InStr using = 0 will not enter the If clause.
Last edited by jmsrickland; Mar 14th, 2015 at 02:09 PM.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Mar 14th, 2015, 02:12 PM
#21
Re: [RESOLVED] How to check if a Word in a TextBox contains "+" Dosnt work For me
Actually in the OP it is entering the IF clause when the + exists where it then tells the user it does not exist
In post 2 it enters when it does not exist
-
Mar 14th, 2015, 02:57 PM
#22
Re: [RESOLVED] How to check if a Word in a TextBox contains "+" Dosnt work For me
I went by the If statement; not what was in the clause although I would say OP wants to test if + does not exists and tell user
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Mar 14th, 2015, 04:33 PM
#23
Hyperactive Member
Re: [RESOLVED] How to check if a Word in a TextBox contains "+" Dosnt work For me
Originally Posted by jmsrickland
Actually, the first two are the same and the last two are the same
That is true. But as Datamiser has noted, in the second post Salsa has hinted he actually wants to find out if that character is missing from that string
i think i got it Code: If Not InStr(TxtServiceName.Text, "+") > 0 Then
that is the same thing with If InStr(TxtServiceName.Text, "+") = 0 Then . I thought there is no confusion about it. On the other hand, it is sufficient to prove any value of a boolean variable even you are interested of other because of its dichotomy : False= nonTrue and vice versa. Finally, let's avoid a debate on such a trivial matter.
Last edited by Daniel Duta; Mar 14th, 2015 at 04:53 PM.
-
Mar 14th, 2015, 05:26 PM
#24
Re: [RESOLVED] How to check if a Word in a TextBox contains "+" Dosnt work For me
OK, but that's not what it appears that you posted
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Mar 14th, 2015, 05:49 PM
#25
Hyperactive Member
Re: [RESOLVED] How to check if a Word in a TextBox contains "+" Dosnt work For me
James, you are a valuable poster of this forum. It is obvious it was just a little misunderstanding. Sorry for any inconvenience caused.
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
|