dcsimg
Results 1 to 11 of 11

Thread: Can Visual Basic.Net be used on Windows software applications

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2019
    Posts
    3

    Can Visual Basic.Net be used on Windows software applications

    Hi, I'm new to programming and I have an existing Windows application which I use to carry out tests on a school project, but everytime when I carry out one test, the application will have a pop up screen showing the test results and I need to manually record the data produced from the existing application into my Excel Sheet, hence I am searching for a way to automate this task. Does anyone know if VisualBasic may be able to help in this regard? Thank you and any reply is greatly appreciated. An example of the screenshot is attached below

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,979

    Re: Can Visual Basic.Net be used on Windows software applications

    Quote Originally Posted by DanAspar View Post
    Does anyone know if VisualBasic may be able to help in this regard?
    Yes it can.
    Quote Originally Posted by DanAspar View Post
    An example of the screenshot is attached below
    No it isn't, but that doesn't really matter. You can use VB to do what you want to do so you should learn what you need to learn in order to do it, then do it, then post a new thread if you run into a specific issue in doing so.

  3. #3
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,192

    Re: Can Visual Basic.Net be used on Windows software applications

    What programming language is the current application written in? Do you have the source code? There are lots of examples of writing data to an Excel file from Visual Basic available .

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2019
    Posts
    3

    Re: Can Visual Basic.Net be used on Windows software applications

    Apologies for the late reply, I'm not sure what the language is as I don't have access to the source code, and I've attached the image of the data needed to be captured here, Name:  Capture.PNG
Views: 75
Size:  149.8 KB , most examples I've come across seem to be only reading from text files, could you point me in the direction of the other examples of writing data if possible? Thank you!

  5. #5
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,192

    Re: Can Visual Basic.Net be used on Windows software applications

    So your talking about writing a new program that does the same thing as the program you use now but also stores the data, is that correct?? As for how to store the data, thats up to you. Text file, xml file, Excel file or Database. If it's a small amount of records, then any of these choices would be fine. Personally I always use a database, if this is a single user system (only one person at a time using it) then SQLite is a good choice.

    But if your talking about capturing what your current program displays on the screen and storing it, then I don't know if that can even be done. Except for maybe capturing the entire image and storing it in some type of image file.

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,093

    Re: Can Visual Basic.Net be used on Windows software applications

    Yeah, it can be done if that's a Windows application, because all of the elements on the screen are windows. You can get the text from each of them in turn, and do with it what you want. The difficult part is finding the correct window from the form. That takes a certain amount of investigation, usually using Spy++ (which is part of VS) and a few API calls. If you want to go that route, then the first step is to figure out the layout using Spy++. You'd need to identify the form in question, then look at the sequence of windows within the form. Each checkbox would be at least one, and whatever is on the right will either be a series of labels (also windows) in a container, or they may be only one item, which would be pretty awkward.

    I'll leave it there because I'm not clear on where you want to go with this. If I made it sound like it's a bit of a chore to read off of a form, that's because it is. Once you get it working, it will keep working, but it can take a bit of test and re-test to identify all the elements that you want (getting their contents is relatively easy, it's finding the element that is bothersome). Therefore, if there is some other alternative aside from picking the pockets of the form on the screen, then it would likely be easier to do. If no other alternative exists, that's when you get to dive into FindWindowEx and the other API calls necessary to pluck the data from a form.
    My usual boring signature: Nothing

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2019
    Posts
    3

    Re: Can Visual Basic.Net be used on Windows software applications

    Yes indeed I am trying to capture the elements and values of what is on the screen and output it into an excel file as there are up to a few hundred repeated tests that I need to carry out that I need to capture values for each of them. Thank you for the detailed explanation ShaggyHiker, will look further into Spy++!

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,093

    Re: Can Visual Basic.Net be used on Windows software applications

    Spy++ is an interesting tool. There are two main elements. The first is the crosshairs tool, which is really cool, and mostly useless. You can move the crosshairs over any window and see some information. The odds that the information is all that useful is pretty low, though. Far more useful is the form that shows the heirarchy of all windows currently visible on the screen. To use this, open as little as possible, which probably means just the program you are interested in and Spy++. What you will see is a rather crude tree. The root element of the tree would be the form itself, with the windows (all controls, including invisible containers like panels) on the form descending from there.

    It may be worth closing and opening the program you are interested in to see whether the heirarchy changes from one time to the next, though it's been well over a decade since I've used Spy++ for this kind of thing.

    The basic objective is to get the windows handle of the control you want. Getting the handle for the form is relatively easy. Getting the handle of the controls may not be. FindWindowEx can get you the handle for the form, because that can find a form by the title text, which is pretty convenient. Once you have that handle, then you can use GetWindows to get children of that window. From there it is a matter of drilling down through the controls by calling GetWindows to get the handle of a child, then calling it again to get a the handle of a child or sibling of that, and so on until you reach the control that has the information you want. It's a nuisance, but once you know the hierarchy of windows on the form, at least it won't change when you have it working right.

    Once you have the handle of the control, there's a different method to get values from it...but I forget what method that is. If you look for examples of using FindWindowEx and GetWindow, you'll likely encounter it.
    My usual boring signature: Nothing

  9. #9
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,979

    Re: Can Visual Basic.Net be used on Windows software applications

    @Shaggy, I think you may have mixed up some names there. FindWindow is used to get the top-level window handle and FindWindowEx is then used to get child window handles. FindWindowEx may be called multiple times to account for multiple levels of hierarchy as well as sibling controls. For instance, if you wanted to get the third button in the first panel, you'd call FindWindow to get the handle of the form, call FindWindowEx once for the panel with the form as the parent, then FindWindowEx three times with the panel as the parent. Of those last three calls, the first one would not specify a sibling and the last two would specify the previous button as the sibling. That amounts to:

    1. Get the form.
    2. Get the first child of the form of type panel.
    3. Get the first child of the panel of type button.
    4. Get the next child of the panel of type button after the first button.
    5. Get the next child of the panel of type button after the second button.

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,093

    Re: Can Visual Basic.Net be used on Windows software applications

    Well, it has been over a decade....so, yeah. I was thinking that GetWindow was the way to get siblings. The documentation suggests that, and I seem to remember using that instead of FindWindowEx for that task, but it has been a long time.
    My usual boring signature: Nothing

  11. #11
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,979

    Re: Can Visual Basic.Net be used on Windows software applications

    Hmmm... never used GetWindow before and never seen it used, but just read the documentation and it does certainly seem like it would be used for that. By the looks of it, you'd still need the same number of calls to get to the same window in most cases although it looks like you can go from last to first amongst siblings rather then just first to last, so getting windows in the second half of a group of siblings could take fewer calls.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width