Is there a solution to this

Posted on 2003-03-19
Medium Priority
Last Modified: 2013-12-26
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


Question by:funkdoctorsport
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2

Expert Comment

ID: 8197465
"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.


Author Comment

ID: 8198186
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.

Expert Comment

ID: 8199605
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 8199630
I found something

Dim iFir As Integer
iFir = ActiveDocument.BuiltInDocumentProperties("Number of lines")

Author Comment

ID: 8202936
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")

Expert Comment

ID: 8203731

Accepted Solution

berXpert earned 900 total points
ID: 8205225
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question