Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

Is there a solution to this

I use Powerbuilder 8.0 and I have an ole object in my application that
opens up word documents. I've been squelching my instincts for a long time
now on how I can get the current line number of an opened doc. Basically
what the application is doing is open up a template doc and write to the
doc. As the application writes, I need to check what the current line
number is. This is where I'm stuck.
I'm hoping there could be some function that can be coded as follows


Acknowledging your help, I thank you

Yours Sincerely


  • 4
  • 2
1 Solution
"As the application writes, I need to check what the current line
number is."

That means powerbuilder writing to doc, then make a proper changes to write line by line, and setting counter to count no of lines you have so far.

funkdoctorsportAuthor Commented:
Writing line by line and keeping a count of the number of lines is not going to be easy because Powerbuilder is writing to a table in the doc. The table has columns of fixed width, which basically means that when text being written to the column does not fit in the column width, it will wrap around.
you are right, and also if the user change font, or has margin setting, it will also be changed.

You could said , "no of lines is almost ... lines and it's depends on user setting of font,...etc"

In other words, number of lines for word doc could be calculated at fly, and may be it's not saved in doc object.

We can search at VB if we can know number of lines per doc

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

I found something

Dim iFir As Integer
iFir = ActiveDocument.BuiltInDocumentProperties("Number of lines")
funkdoctorsportAuthor Commented:
I could try that. Keep in mind thought that the quest is to get the current line number. Is there a function like:
iFir = ActiveDocument.BuiltInDocumentProperties("Current Line Number")
I got something that maybe will help you

String ls

OLEObject ole_WordTemplate
ole_WordTemplate = CREATE OLEObject

ole_WordTemplate.Documents.Open('C:\My File.dot')
ole_WordTemplate.Application.Visible = True

//  your code that write in the document
//  ....

Int li_current_line, i

// this calculate the number of the line on the range from begining of document up to the current line
ole_WordTemplate.Selection.HomeKey(6, 1)  // Unit:=wdStory, Extend:=wdExtend
li_current_line = ole_WordTemplate.Selection.Range.ComputeStatistics(1) // wdStatisticLines
ole_WordTemplate.Selection.Collapse(1) //Direction:=wdCollapseStart
MessageBox("Current Line", String(li_current_line) )

ole_WordTemplate.ActiveDocument.SaveAs('C:\New File.doc')



If you are at the begining of the line it counts line -1 but I think it still helps you.

By the way what are you using to write in your document?  I used to use selection.text = "My string", and you?

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now