-1

Using VS2010 C#

I am at a complete loss...

I have a vendors program to export data in a proprietary format into a CSV file.

I have about 20 disks and one of them has 255 such files...

I want to automate the process... Which was fairly straightforward until I needed to write the new file name into the file save box on the vendor's program.

I have the programs handle but can't seem to ask the right question(s).

I think I need a way to enumerate all the controls so I have a handle to use send message to.

But, as I said I am at a complete frustrating loss at this time.

Suggestions on what questions to ask would be most appreciated.

Thanks!

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
Mike Sr
  • 511
  • 1
  • 5
  • 15
  • Have you tired anything? – Jack Miller Jul 14 '17 at 15:57
  • https://stackoverflow.com/questions/37912261/how-to-get-handle-to-a-textbox-control-inside-window-in-window-10 not an answer but may help, also look at tools built for this. I used to do this kinda stfuf years ago (like 15 years ago) and I just used scripting tools that would sendtext to windows etc. – Steve Drake Jul 14 '17 at 16:00
  • @Jack Miller Yes, I spent hours trying various code samples... Most dealt with how to talk to other forms in your own project. – Mike Sr Jul 15 '17 at 00:52
  • @Steve Drake I think you've given me a lot to think about and try out. Looks very interesting. Thanks – Mike Sr Jul 15 '17 at 01:05

2 Answers2

0

.FindAll() Should be what you're looking for. This will return all UI elements under a window handle. https://msdn.microsoft.com/en-us/library/system.windows.automation.automationelement.findall(v=vs.110).aspx

Kieran Devlin
  • 1,373
  • 1
  • 12
  • 28
  • Kieran Devlin... I appreciate your taking the time to read and answer my question. But, one of the reason many of us end up asking on StackOverFlow is because Microsoft's information can be rather obfuscated. :) – Mike Sr Jul 15 '17 at 01:08
  • What are you having trouble with understanding? – Kieran Devlin Jul 17 '17 at 08:17
  • Represents a UI Automation element in the UI Automation tree, and contains values used as identifiers by UI Automation client applications. – Mike Sr Jul 18 '17 at 16:48
  • So basically for each UI there are is a tree of UI elements that can be nested. (e.g group box is a child of the form and a button is a child of the groupbox) Each element node within the tree contains attributes (values) that you can use to identify your element. Loop through the list and check the relative value i.e a button handle id or text. (e.g For each element, if the element is a button and contains the text 'Click Me' then return element). – Kieran Devlin Jul 31 '17 at 10:46
0

I decided a work-around would solve my problem and will study further later...

It's so frustrating to see how easy it is done in AutoIt and Phantom Test Driver (which is what I ended up using).

[Deleted website, has been changed.]

Basically, I had a “ton” of disks that contained .dtb files, 542 to be exact.

I know this is simplistic and I have only written out the gist of what I did to solve. These files are in a proprietary format requiring the use of Teradyne’s software, as far as I know there is no scripting or command line method for using this software.

I am not sure if I ended up using all of these assemblies, but here’s the list:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Runtime.InteropServices;

My first task was to locate all the .dtb files on the CD and transfer them to a working folder, folder structure intact. (Because there were duplicate filenames in different folders) To do this I used Beyond Compare.

This folder becomes the base folder, lblDrive.txt. It actually includes the whole path.

string[] rawInput = Directory.GetFiles(lblDrive.Text, "*.dtb*", SearchOption.AllDirectories);

//lblDTBFilesFound

int dtbCount = 0;
foreach (string s in rawInput)
{
    lstFilesList.Items.Add(s.ToString());
    dtbCount++;
}
lblDTBFilesFound.Text = "DTB Files Found: " + dtbCount.ToString();

// create a list of all .dtb files including their complete path. // file count can be used later to ensure you converted all the files.

Iterate through the list copying each entry to wrkString, which is a full path to a .dtb file

Clipboard.SetText(wrkString.Substring(0, q));

// Copy everything but the file extension to the clipboard

Process.Start(wrkString); // launching proprietary software

int maybe = 0;
while (maybe < 25)
{
    System.Threading.Thread.Sleep(10);
    maybe++;
}

// give a bit of a delay to ensure app has started

var process = Process.Start("DTB_Extraction.psc");
process.WaitForExit();

• Launches phantom.exe (.psc previously associated with phantom.exe manually) • Script executes the mouse moves and clicks to convert the file • Script includes a paste from clipboard into file save • Forces a wait until the script finishes

if(File.Exists(wrkString.Substring(0, q) + ".csv"))
{
    // Do nothing
}
else
{
    lstDisp.Items.Add(wrkString.Substring(0, q) + ".csv");
}

// In the rare case something went wrong and the .csv wasn’t created

string[] rawInput = Directory.GetFiles(lblDrive.Text, "*.csv*", SearchOption.AllDirectories);
int dtbCount = 0;
foreach (string s in rawInput)
{
    lstFilesList.Items.Add(s.ToString());
    dtbCount++;
}
lblCSVFilesFound.Text = "CSV Files Found: " + dtbCount.ToString();

// create a list of all .csv files in the working directory, so I can iterate through it and extract the data I needed. // File counts can be compared.

Mike Sr
  • 511
  • 1
  • 5
  • 15