How to use multiple Or Operator in Visual Basic 2010? - visual-studio-2010

I am trying to make a program which uses multiple OR operator in If statement..
If aryTextFile(i) = "and" Or "but" Or "or" Or "nor" Or "for" Or "yet " Or "so" Then
TextBox2.Text = aryTextFile(i) & " is a Coordinating Conjunctions"
But this gives out the error
Conversion from string "but" to type 'Boolean' is not valid.
I need help to make multiple or operator to work or even if i could replace if statement :P
Any help appreciated.
P.S - Beginner in programming !

use OrElse instead of Or (to not evaluate every instance, if the first is a match, it wont evaluate the rest of the expressions as it is not necessary)
And you have to do it like this:
If aryTextFile(i) = "and" OrElse aryTextFile(i) = "but" OrElse aryTextFile(i) = "or" Then
The string by itself is not a boolean expression
It expects "boolean expresson" OrElse "another boolean expression"

Related

Does flowgrounds JSONata expressions support regex?

I'm trying to build a fairly complex expression with a CBR where I try to identify if a string contains another string. In order to do so I need to manipulate the second string and use a little bit of regex magic but it doesn't seem to work. Could anyone confirm if the JSONata implementation of flowground support regex inside a "contains" operation? The expression I am using right now is the following:
$not($contains(elements[0].attribs.content,"/" & $replace(elasticio."step_1".body.issue.fields."customfield_22519"[0],"-"," ") &"/i"))
RegEx and $contains are working correctly in combination.
The reason for your not working expression is that the second parameter of $contains is a string (something like "/xyz/i"). This string is not being interpreted as a regex.
your expression: $contains( "abc", "/" & "X" & "/i")
to change in: $contains( "abc", $eval("/" & "B" & "/i") )

How I can treat null value in vb6 ResultSet

I have a return value from the database but I can not filter the null value.
With rs_receita
Do Until .EOF
Set noaux2 = xml.createElement("Superavit")
noaux2.Text = IIf(IsEmpty(!Superavit), "", CStr(!Superavit))
Call noaux.appendChild(noaux2)
.MoveNext
Loop
End With
Set rs_receita = Nothing
Avoid IIf for this scenario. IIf always evaluates both expressions. So when !Superavit is null, this will cause an error.
A single-line If statement, on the other hand, will only evaluate the expression to be executed. Combine that with the IsNull() function to reliably assign a database value to a variable if it's not null:
If IsNull(!Superavit) Then noaux2.Text = "" Else noaux2.Text = CStr(!Superavit)
In VB6 (I'm sorry!) you can force coercion to a string by appending an empty string to the field value.
Edit: Phew, this article is a blast from the past. It gives a bunch of NULL handling ideas for classic VB6: https://technet.microsoft.com/en-us/library/Aa175775(v=SQL.80).aspx
I believe either of the following will work:
noaux2.Text = "" & rs("Superavit")
OR
noaux2.Text = vbNullString & rs("Superavit")

If condition for VBScript on LDAP results

I'm connecting with LDAP to Active Directory for a corporate phonebook. I'm grabbing the data I want, but I need to do an If...Else statement on some of the data I'm grabbing.
I want to check if the value in AD attribute 'homePhone' begins with "01". If it does, I want to write out its value. If it begins with anything else, I want to either write "" or "Not Valid".
Here's what I've been writing, but isn't working:
Response.Write "<td>"
if objRS("homePhone") = "01*" then
Response.Write objRS("homePhone")
else
Response.Write ""
end if
Response.Write "</td>"
This seems to just go to the Else condition, and the homePhone attribute doesn't get written.
You can't use wildcards in string comparisons and, unfortunately, VBScript doesn't support the Like operator used in VBA/VB. You can use a regular expression but that's overkill for what you need here. Just strip the first two characters and perform your comparison.
If Left(objRS("homePhone"), 2) = "01" Then
If you need to perform case-insensitive string comparisons (not necessary in this situation, but may be helpful in the future), you can convert both strings to upper/lowercase before comparing or use the StrComp() function with the vbTextCompare parameter value.
If StrComp(Left(objRS("homePhone"), 2), "01", vbTextCompare) = 0 Then

VB6 - IIF (ISNULL(rs),"TRUE",Replace())

why i cannot use :
rep8_bc = IIf(IsNull(rs(8)), "null", Replace(rs(8), "'", "''"))
it say " Invalid use of Null"
but if i remove replace, it's work. And then get error because record have an apostrophe character, so i change the code into this :
rep8_bc = "null"
If IsNull(rs(8)) = False Then rep8_bc = Replace(rs(8), "'", "''")
or this :
If IsNull(rs(8)) = False Then
rep8_bc = Replace(rs(8), "'", "''")
else
rep8_bc = "null"
end if
Mostly likely compiler doesn't short circuit within IIF() statement. Compiler takes it as a whole statment (both values) before returning one. That's where you get the error. So breaking into pieces of proper conditional statemetns would be the key here. So you have any achieved that with your answer.
To further add, IIF() is much slower in execution than the IF-ELSE statments.

If statement not working - what is wrong with this syntax?

I get an "Expected Identifier" message against the if line. Any ideas why?
if ([inputA.text isEqualToString:#""]) && ([inputB.text <> isEqualToString:#""]) {
c = 1;
}
I'm trying to say it both inputs are empty...
I presume there isn't an easier way to say if the text is null in Obj C++?
An if statement requires that its condition expression be enclosed in parentheses. You have a compound expression. You've used parentheses around the subexpressions of the logical AND operation (&&), but you haven't surrounded the entire expression in parentheses. (The subexpressions don't actually require parentheses in this case, but they don't hurt.)
Next, you have a random <> in the second subexpression. What is that doing in there? In some languages that is the "not equal" operator, but a) it's not an operator in C or Objective-C, b) it wouldn't go inside a message-send expression like that, and c) you claim you were trying to check that both inputs are empty, so I wouldn't expect you to try to negate the test for equality with the empty string.
So, fixing just those problems yields:
if ([inputA.text isEqualToString:#""] && [inputB.text isEqualToString:#""]) {
c = 1;
}
That said, pie's answer is good, too. It also works if either of the inputs has a nil text property, too.
if ([inputA.text length]==0 && [inputB.text length]==0)
{
c = 1;
}

Resources