OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 13-04-2015, 00:51
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 434
Default Count none blank lines in paragraph text?

I have some paragraph text copied from a text file. It contains blank lines (just returns). How can I find the total number of lines that contain text or punctuation, oe not blank. Thanks.
Reply With Quote
  #2  
Old 13-04-2015, 06:05
shark shark is offline
Senior Member
 
Join Date: Aug 2010
Location: Russia, Belgorod
Posts: 146
Default

Code:
Sub test_text()
Dim s As Shape, z&, lc&
    Set s = ActiveShape
    If s Is Nothing Then Exit Sub
    If s.Type <> cdrTextShape Then Exit Sub

    lc = 0  ' line's counter
    For z = 1 To s.Text.Story.Lines.Count
        If Len(s.Text.Story.Lines(z).Text) > 1 Then lc = lc + 1
        ' or
        ' If s.Text.Story.Lines(z).Characters.Count > 1 Then lc = lc + 1
    Next

    MsgBox lc & " non-empty lines"
End Sub
you may need to use function Trim to ignore lines like "spaces" + "returns"

Last edited by shark; 13-04-2015 at 06:40.
Reply With Quote
  #3  
Old 13-04-2015, 20:45
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 434
Default

Thanks for the suggestion. I had tried something similar but the problem is that a line with just one character is ignored. Trim doesn't help with returns being counted. I also tried lenB but it appears an empty line and a line with 1 character have the same number of bytes as well. Looks like I will need to make a copy convert to artistic text break apart and count the number of lines that way.
Reply With Quote
  #4  
Old 13-04-2015, 21:30
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 434
Default

I figured it out. I got some inspiration from reading your post. This works

Code:
Sub TestLines()

Dim z As Shape
Dim t As text
Dim LN As Long

If ActiveSelection.Shapes.Count = 0 Then Exit Sub

Set z = ActiveShape
If z.Type <> cdrTextShape Then Exit Sub
Set t = z.text

LN = 0

For i = 1 To CStr(t.Story.Lines.Count)
If z.text.Story.Lines(i).text <> Chr(10) And z.text.Story.Lines(i).text <> Chr(13) _
And Len(z.text.Story.Lines(i).Characters.all) >= 1 Then LN = LN + 1
Next i

MsgBox LN & " lines containing text"

End Sub
Thanks again.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Small Text Character Count Bug X4 SP2 runflacruiser CorelDRAW/Corel DESIGNER VBA 4 24-05-2011 09:55
Remove blank space in Paragraph text runflacruiser CorelDRAW/Corel DESIGNER VBA 8 20-10-2010 19:01
Convert Paragraph to Artistic - error on blank Paragraph Text Field gorgo2 Macros/Add-ons 3 14-09-2010 06:53
Macro - loading a blank template file *.cdt for Grahic and Text styles gorgo2 Macros/Add-ons 5 28-04-2010 00:25
Identifying specific lines of paragraph text knowbodynow CorelDRAW/Corel DESIGNER VBA 3 06-12-2007 03:58


All times are GMT -5. The time now is 02:16.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com