• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Cell.Contents incorrectly resolve to empty Strings if in Overset Condition… Is this a Bug or Me?

Engaged ,
Apr 06, 2014 Apr 06, 2014

Copy link to clipboard

Copied

Greetings, Folks.

This is driving me nuts. I can replicate the problem over and over again. Am I missing a reason why cell.contents would be evaluated differently if in overset condition than not? I don't get it…

Here's the scenario. CS6, Win7, VB.Net (but the logic is easy so stay with me…).

Object in question is a 3 cell row containing values in the respective cells: Text value, double value, double value.

Here's the problem code. (gitc=1 in all these test cases)

If Not HasValue(curRow.Cells(gitc + 1).Contents) Then

Here's the simple function called by the line above:

Private Function HasValue(value As Object) As Boolean

   If IsDBNull(value) OrElse value = "" Then Return False Else Return True

End Function

Here's the problem. The code works as intended provided that the referenced row is not in overset condition, the object resolves to a text value and two double values, from which the function returns the proper evaluation. But if the row is in overset condition, the object resolves to three empty Strings ("") and consequently the function returns the wrong evaluation.

Here the rub. If I take lengthen (or shorten) the column which puts a DIFFERENT row in the overset place, the same result occurs to that different row, so I know that it is not the values.

Sorry for the long explaination, but I felt that it is important to give as much info as possible when asking for help.

Thank you very much for any help and/or insight.

TT

TOPICS
Scripting

Views

428

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Apr 06, 2014 Apr 06, 2014

Ah, I'm a JavaScripter but the advice is right even if the syntax is wrong.

The point is that if the cell is overset then its contents are indeed empty. What's not empty is the text object of the cell. You probably should be looking at it. In JavaScript that's:

myCell.texts[0].contents

Dave

Votes

Translate

Translate
Advocate ,
Apr 06, 2014 Apr 06, 2014

Copy link to clipboard

Copied

Ah, I'm a JavaScripter but the advice is right even if the syntax is wrong.

The point is that if the cell is overset then its contents are indeed empty. What's not empty is the text object of the cell. You probably should be looking at it. In JavaScript that's:

myCell.texts[0].contents

Dave

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 06, 2014 Apr 06, 2014

Copy link to clipboard

Copied

LATEST

Howdy Dave!

You are correct... I found a work around in the interim and was getting around to posting it, but I am glad that I waited because it makes sense. I think that I just need to slow down... 🙂

Here's the syntax (for anyone who needs it) on your suggestion that works:

If Not HasValue(curRow.Cells(gitc + 1).Texts(1).Contents)...

Of course you need the function from my OP. Note that .NET COM refs use base 1 instead of base 0.

My workaround was kind of similar, using a new function just for Cells:

 

If  Not CellHasValue(curRow.Cells(gitc + 1)) Then...

Private Function CellHasValue(chkCell As Cell, Optional textIndex As Integer = 1) As Boolean

   If chkCell.Texts(textIndex).Length = 0 Then Return False Else Return True

End Function

Maybe this will help someone. Thanks kindly for your assistance.

Best regards,

TT

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines