BASIC+Calc: Check existing sheet

Sub IfAndOr_4
	Dim k% : k = 3
'	This Calc file has only 1 sheet, namely Sheet1.		
	If	    (ThisComponent.Sheets.hasByName("Sheet2") _
        And ThisComponent.Sheets.getByName("Sheet2").getCellRangeByName("A1").String = "") _
		Or	(k = 3)	_
		Then
			MsgBox "Hi!"
	End If
End Sub

The problem is:

If	    (ThisComponent.Sheets.hasByName("Sheet2") _
    And ThisComponent.Sheets.getByName("Sheet2").getCellRangeByName("A1").String = "")

How can I check and keep the code short as in Sub IfAndOr_4 ?

The problem is:

I’m sorry, but instead of a problem, what I see following those words is just some code. So could you please be specific: what is the problem with that code?

Possibly the problem might be that it evaluates both parts, instead of only evaluating the second part after successful check of the first part? IIRC short-circuiting of boolean expressions is not part of LibreOffice BASIC, so you might need to have the “if exist” check in own “if” statement, and “if A1 string is…” in another nested check.

Dear @mikekaganski,

Thank you so much, your comment is the thing that I really need.

The answer is in @mikekaganski’s comment.

Possibly the problem might be that it evaluates both parts, instead of only evaluating the second part after successful check of the first part? IIRC short-circuiting of boolean expressions is not part of LibreOffice BASIC, so you might need to have the “if exist” check in own “if” statement, and “if A1 string is…” in another nested check.