Solved

VB frontend for PERL script - progress bar

Posted on 1998-01-19
6
289 Views
Last Modified: 2012-06-21
Currently i have a perl script that I am developing a Visual Basic frontend for.  Basically, all Visual Basic does is present forms to the user, in which data is entered, then writes that to file...  PERL waits for the VB program to terminate, then reads the data from file and processes it.  Simple stuff.  However, I have a new need... I would like to implement a nice windows progress bar for my script and for that I am guessing that I need PERL to send some kind of message to my Visual Basic Program.  I'm pretty sure that this can be done with the Win32API module.

Can somebody give me some example code of how perl might tell VB to upgrade a progress bar by a certain increment?  What I thought might be possible is for perl to figure out what the increment is (out of 100), to send that information to the VB program, then to send another message every time the progress bar is to be updated by that increment.  I have no idea how to do this.  Any help is very much appreciated.

Colin
0
Comment
Question by:colind
  • 3
  • 3
6 Comments
 
LVL 5

Accepted Solution

by:
icd earned 200 total points
Comment Utility
I assume that this is *not* a cgi script.

If the perl program is taking some time to complete, say more than two or three seconds, then the following approach would work.

Every few seconds (there is no need for a more frequent update than about once per second). The perl script writes to a file with a single value, the percentage of the process that is completed, and then closes the file. The VBScript can open and read this file periodically to find out the progress.

If you want to use inter-process communication then this depends upon the operating system (which you did not specify, but I assume is Windows NT). This is more difficult and requires a knowledge of Windows programming, rather than perl programming. If you want to take this approach then you should obtain a module to add to perl that gives access to the API functions. I am sure one exists, I can't remember the name but I will do a search for it for you.

0
 

Author Comment

by:colind
Comment Utility
I thought about doing this...  The problem I had was that I wasn't sure what would happen if PERL and VB both tried to open the file at the same time.  Would there be some kind of error?  I guess I would just have to do a test in PERL to make sure that the file was open before trying to write to it.  If I wrote to an unopen file, my progress bar would show something like 80% when the processing was actually at 100%.  How might this affect the VB side?

I knew about the perl module that interfaces with the Win32 API, it is maintained by Aldo Calpini...  It's called Win32::API and can be found at:  http://194.247.167.1/DADA/PERL/API/index.sht

I was hoping somebody could show me how to use this to pass a value from PERL to VB and then how to cause an event which the VB program could respond to.

I will try your method though and see how it pans out.

Thank you.
0
 
LVL 5

Expert Comment

by:icd
Comment Utility
There should be little chance of a conflict. VB is only reading and Perl only writing. If either VB or Perl fail to open the file then at worst there will be a small jump from (say) 80% to 82% missing out 81%. I suspect that any attempt to calculate percentage done (percentage of time?) will always be jumpy anyway. (At least all the ones I have seen so far have been anyway.).


0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:colind
Comment Utility
That's right...  I was thinking of just passing a message to VB saying update the progress bar by the increment...  If instead I say, put the progress bar at 76.8%, then the progress bar would always be right.  

Actually, the way that my program works, the progress bar thing won't be all that jumpy.  It's one huge loop which takes a fairly specific amount of time for each iteration and so time-wise, the progress bar would always be very close.

Do you have any knowledge of how to do implement a progress bar in VB?  Is it difficult?  Let's say I use your idea and perl writes 80.7% to the first line of a file.  How would VB turn that into a progress bar showing 80.7% completion?

Thanks in advance,

Colin

0
 
LVL 5

Expert Comment

by:icd
Comment Utility
I am not familar with VB although I once saw some code written in either C++ or VB, I can't remember. It is something to do with creating a couple of images, one in blue with white text, one in white with blue text (for example) and then displaying the first 80.7% of the blue image and then the final 19.3% of the white image.

I could not comment on the specifics however. The article I saw was on the Microsoft Developers Network CD-ROM's. You might find it if you do a search for progress bars on the Microsoft site.

0
 

Author Comment

by:colind
Comment Utility
I had another idea. I know that it is quite easy to use OLE through perl using the win32::ole module...  I could just control some property of some object on my VB form and then VB could read from that property and respond.  I think that that will actually turn out to be the easiest and most reliable solution.  Thanks for your help.

COlin
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now