Do you like this page? Check [Yes] or [No]

In the distant era of the late 90s, Jens he worked for a small software store that made tools for business users. It was a small shop, and most projects were quite small – usually enough for one developer to finish.

A contributor has created a VB4 (latest version available) tool that connects to an Oracle database. That colleague quit his job, and that meant that this tool was Jens’ job. The fact that Jens had never touched Visual Basic before meant nothing.

Since the original developer had left, Jens had to return to the customer for knowledge transfer. “Walk me through how you use the app?”

“The main thing we do is print reports,” the user said. They navigated through several screens worth of menus to the report and previewed it. It was a simple report with five records displayed on each page. The user pressed “Print” and then a dialog box appeared: "Print Page 1? [Yes] [No]". The user clicked “Yes”. "Print Page 2? [Yes] [No]". The user started clicking “no”, because the demo was over and there was no reason to burn a bunch of printer paper.

“Wait, is this like this?” – Jens asked, not believing his eyes.

“Yes, it’s great because we can decide which pages we want to print,” said the user.

"Print Page 57? [Yes] [No]".

With each page, the dialog took longer and longer to appear, the program was obviously stuck.

Now the code is long lost, and Jens quickly forgot everything they learned about VB4 after this project ended (honestly), so instead of a clean code sample, here’s a little pseudocode to demonstrate the flow:

for k = 1 to runQuery("SELECT MAX(PAGENO) FROM ReportTable WHERE ReportNumber = :?", iRptNmbr)
	dataset = runQuery("SELECT * FROM ReportTable WHERE ReportNumber = :?", iRptNmbr)
	for i = 0 to dataset.count - 1
	  if dataset.pageNo = k then
	    useRecord(dataset)
		dataset.MoveNext
	  end
	next
	if MsgBox("Do you want to print page k?", vbYesNo) = vbYes then
		print(records)
	end
next

"Print Page 128? [Yes] [No]"

The bottom line is that we are asking about the number of pages every time we perform a loop. Then we get all lines for the report and check each line to see if they should be on the page we print. if they are, useRecord prepares them for printing. After they are set, we ask the user if they should be printed.

“Why doesn’t it just give you a page selector like Word does?” Jens asked.

“The last guy said it wasn’t possible.”

"Print Page 170? [Yes] [No]"

Jens, who didn’t know about VB, worried that he had stepped on a landmine and had just promised the customer something that the tool didn’t support. He returned the statement and said, “I’ll look into it, see if we can improve it.”

It wasn’t hard for Jens to improve it: not running a query for each page and repeating rows from previous pages on each page increased performance.

"Print Page 201? [Yes] [No]"

Adding a word processor-style page selector wasn’t much more difficult. If it weren’t for that change, that poor user might still be clicking “No” to this day.

"Print Page 215? [Yes] [No]"

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *