Operation is not allowed in this context

ict-torquilclark
ict-torquilclark used Ask the Experts™
on
Can anybody explain why I am getting the error in the title on the last lnie of the code below?

                    If datagridviewClients.Item(2, x).Value.ToString.ToUpper.Contains("HEATH") Then
                        Heath = True
                    Else
                        Heath = False
                    End If

                If Heath = True Then


It has baffled me....
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Meir RivkinFull stack Software Engineer

Commented:
which line is it?
can u post more code, like what Heat is? property?
did u implement asynchronous operations?

Author

Commented:
That is all the code that there is - apart from the "End If"

heath is just defined in the code abover as a boolean

Dim Heath as Boolean

The if then sets it to true or false

and then i get the error on the next if...
Meir RivkinFull stack Software Engineer

Commented:
try this:

dim value as string
value = datagridviewClients.Item(2, x).Value.ToString()

  If value.ToUpper().Contains("HEATH") Then
                        Heath = True
                    Else
                        Heath = False
                    End If

                If Heath = True Then

Open in new window

Author

Commented:
I still get the same error.

The code is fine at assigning the true/false value to Heath. The error comes when evaluating it for the "If Health = True" line.
Martin Liss"Life would be infinitely happier if we could only be born at the age of eighty and gradually approach eighteen." - Mark Twain
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Do you have anything else in your program called 'Heath' like perhaps a procedure?

What exactly is the error message?
GrahamSkanRetired
Top Expert 2012

Commented:
Doesn't solve the mystery, but you could just try
If Heath Then
Full stack Software Engineer
Commented:
Try restart visual studio
Theo KouwenhovenApplication Consultant

Commented:
If Heath = True Then (Then what??) this is a syntax error I assume
Top Expert 2009

Commented:
Simply change the variable "Heath" to "booHeath" in your routine and try it again. Then you can rule out most of the suggestions above.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial