VBScript - IF something equals something
FIXED- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Other forums
- :
- Tech Help - Software/Hardware etc
- :
- Re: VBScript - IF something equals something
02-05-2017 11:51 AM - edited 02-05-2017 11:51 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
i have a simple IF THEN ELSE
IF variable1 = "A" AND variable2 = "B" THEN ELSE END IF
and that works but appears to be case sensitive.
so if variable2 = "b" then it fails.
is there any way to make it so that it'll pass if variable2 is B or b?
(this is just a simplifed version, but variable2 could be a word and not just a letter.
Fixed! Go to the fix.
Re: VBScript - IF something equals something
02-05-2017 12:00 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Re: VBScript - IF something equals something
02-05-2017 12:05 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
this gives two solutions - the one above and the other using string comparison
Re: VBScript - IF something equals something
02-05-2017 12:05 PM - edited 02-05-2017 12:06 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
how is converting the variable to uppercase going to help?
that would only help if both items being compared were in upper case, which they might not be.
the IF statement needs to be case insensitive.
Re: VBScript - IF something equals something
02-05-2017 12:07 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
@Oldjim wrote:
this gives two solutions - the one above and the other using string comparison
i actually looked at that very page, but came to the conclusion that StrComp may not work 100% of the time.
02-05-2017 12:09 PM - edited 02-05-2017 12:12 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
You can always use :
IF (strcomp(Var2, "B", vbTextCompare) == 0) THEN ... END IF
When the value returned by the function is < 0 then the Var2 is less than "B" (i.e. A -v- B) when its > than 0 then Var2 is greater than "B" (C -v- B) but when it's 0 then both string are deemed the same regardless of case.
Edit:- Correct type and added this:
Why do you say it won't work 100% of the time?
Re: VBScript - IF something equals something
02-05-2017 12:11 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Re: VBScript - IF something equals something
02-05-2017 12:14 PM - edited 02-05-2017 12:14 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
@Anonymous wrote:
You can always use :
IF (strcomp(Var2, "B", vbTextCompare) == 0) THEN ... END IFWhen the value returned by the function is < 0 then the Var2 is less than "B" (i.e. A -v- B) when its > than 0 then Var2 is greater than "B" (C -v- B) but when it's 0 then both string are deemed the same regardless of case.
Edit:- Correct type and added this:
Why do you say it won't work 100% of the time?
what if it is "b" though (as opposed to "B") ?
or what if Var2 is "SomeThing" and it's comparing it against "something" or "someThing" or "somethinG" ? etc etc
Re: VBScript - IF something equals something
02-05-2017 12:23 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Well due to the way the function works an implied case conversion is done to the input parameters, so it can always guarantee you consistent results. By using this method you don’t have to worry about the case of either input as the functions will apply its own logic to deal with that. So take that into consideration when or if you use it.
If Var2 is ‘SomeThing’ then comparing it against ‘something’ or ‘someTHing’ will produce a 0. However if you compare it against ‘somethings’ then you’d get value > that 0.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Other forums
- :
- Tech Help - Software/Hardware etc
- :
- Re: VBScript - IF something equals something