Parsing variable containing strings delimited by null character

Hi,

I'm using DOORS 8.1 (on Windows XP) and I was wondering if there's any way to parse a variable that contains multiple strings delimited by a null character.

I'm using OleAutomation to launch a multi-select file dialog box (specifically UserAccounts.CommonDialog) and the problem is if the user selects more than one file, the files are returned in a string where they are separated by the null character.

As far as I know as soon a null character is encountered, DXL terminates the string. So right now, the only data I can return from the dialog box is the first string which is only the filepath.

Here's my code snippet if anyone would like to give it a try...
 

Module m = current
 
 OleAutoObj objCD = null
 OleAutoArgs args = create 
 
 //array dynamically resizes, set it low to start
 Array arrFiles = create (2, 2)
 
 OleAutoObj objFSO = oleCreateAutoObject ("Scripting.FileSystemObject")
 bool doSave = false
 
 string strResult = ""
 string strLocalFiles = ""
 int intResult = 0
 int intAns = 0
 
 // Prompt user for file selection
 objCD = oleCreateAutoObject("userAccounts.CommonDialog") 
 
 //display all files in the folder
 strResult = olePut(objCD, "filter", "All files|*.*")
 if (strResult != "") then ack "filter failed: " strResult "\n"
 
 strResult = olePut(objCD, "InitialDir", "C:\\")
 if (strResult != "") then ack "InitalDir failed: " strResult " \n"
 
 int hexnum = 0X0200 | 0X80000    //200 = multi-select, 80000 = Explorer dialog box
 strResult = olePut(objCD, "Flags", hexnum)
 if (strResult != "") then ack "Flags failed: " strResult " \n"
 
// strResult = olePut(objCD, "MaxFileSize", 256)
// if (strResult != "") then ack "MaxFileSize failed: " strResult " \n"
 
 //display dialog box
 strResult = oleMethod (objCD, "showOpen", null, intAns)
 
 if (strResult != "") {
     ack "showOpen failed: " strResult " \n"
     halt
 }
  
 if (intAns != 1) {
     ack "No file selected \n"
     halt
 }
 
 //retrieve list of filenames 
 strResult = oleGet(objCD, "Filename", strLocalFiles)
 if (strResult != "") {
    ack "FileName failed: " strResult " \n"
    halt
 }
 
print strLocalFiles "\n"

dasilvaa - Wed Oct 06 17:12:19 EDT 2010

Re: Parsing variable containing strings delimited by null character
llandale - Wed Oct 06 17:48:41 EDT 2010

There is a 'fileName' type DBE that prompts for a single file, perhaps that's what you want.

  • Louie

Re: Parsing variable containing strings delimited by null character
Mathias Mamsch - Wed Oct 06 19:03:44 EDT 2010

Interesting question! Unfortunately you are out of luck with parsing, since COM will not copy the result over a null-character. Appending the below to your code, shows the tragedy.
 

print "Files:" strLocalFiles "\n"
print "Parsing:" 
int *ptr = addr_ strLocalFiles 
 
while (*ptr & 0x255 > 0) {
    print charOf(*ptr)
        ptr ++
}; ptr ++  // Skip the 0 character ...
 
print "\n" // get the second string ...
while (*ptr & 0x255 > 0) {
        print charOf(*ptr)
        ptr ++
}; ptr ++

 


The same problem exists in VBA by the way! So, what can you do? Why don't you use the old Win3.1 dialog?

 

 

 

...
int hexnum = 0X0200  // don't use fancy dialogs ...
...

 


seems to use other separators.

Regards, Mathias

 

 

 

 

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: Parsing variable containing strings delimited by null character
dasilvaa - Thu Oct 07 08:44:44 EDT 2010

Mathias Mamsch - Wed Oct 06 19:03:44 EDT 2010

Interesting question! Unfortunately you are out of luck with parsing, since COM will not copy the result over a null-character. Appending the below to your code, shows the tragedy.
 

print "Files:" strLocalFiles "\n"
print "Parsing:" 
int *ptr = addr_ strLocalFiles 
 
while (*ptr & 0x255 > 0) {
    print charOf(*ptr)
        ptr ++
}; ptr ++  // Skip the 0 character ...
 
print "\n" // get the second string ...
while (*ptr & 0x255 > 0) {
        print charOf(*ptr)
        ptr ++
}; ptr ++

 


The same problem exists in VBA by the way! So, what can you do? Why don't you use the old Win3.1 dialog?

 

 

 

...
int hexnum = 0X0200  // don't use fancy dialogs ...
...

 


seems to use other separators.

Regards, Mathias

 

 

 

 

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Louie:
Unfortunately I specifically need a multi-select dialog box, which the DBE doesn't do.

Mathias:
I was originally using the old Win3.1 dialog but the clients complained that it's rather clunky, and not very pretty :) Plus you can only see the short filenames, which sometimes makes it difficult to determine if you're selecting the correct files.

By the way, were you able to get the MaxFileSize property to work (it's commented out in the code above)? I've tried but I keep getting an error: Problem with OLE Argument names. Any thoughts?

Re: Parsing variable containing strings delimited by null character
Mathias Mamsch - Fri Oct 08 07:23:40 EDT 2010

dasilvaa - Thu Oct 07 08:44:44 EDT 2010
Louie:
Unfortunately I specifically need a multi-select dialog box, which the DBE doesn't do.

Mathias:
I was originally using the old Win3.1 dialog but the clients complained that it's rather clunky, and not very pretty :) Plus you can only see the short filenames, which sometimes makes it difficult to determine if you're selecting the correct files.

By the way, were you able to get the MaxFileSize property to work (it's commented out in the code above)? I've tried but I keep getting an error: Problem with OLE Argument names. Any thoughts?

I googled a bit. Multi-Select File Dialogs that are native to Windows over COM seem to be a common (unsolved) problem. Would it be possible for you to install another COM component, that contains a suitable dialog? Or do IT restrictions prevent that.

Regards, Mathias

Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: Parsing variable containing strings delimited by null character
dasilvaa - Fri Oct 08 10:30:04 EDT 2010

Mathias Mamsch - Fri Oct 08 07:23:40 EDT 2010
I googled a bit. Multi-Select File Dialogs that are native to Windows over COM seem to be a common (unsolved) problem. Would it be possible for you to install another COM component, that contains a suitable dialog? Or do IT restrictions prevent that.

Regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Unfortunately our desktops are locked down tighter than Fort Knox. There's no chance I can install another COM component. Even if I could get it for my machine, I'd have to distribute it to all our clients and that's also a dead-end.
Agustine

Re: Parsing variable containing strings delimited by null character
Mathias Mamsch - Sat Oct 09 14:05:23 EDT 2010

dasilvaa - Fri Oct 08 10:30:04 EDT 2010
Unfortunately our desktops are locked down tighter than Fort Knox. There's no chance I can install another COM component. Even if I could get it for my machine, I'd have to distribute it to all our clients and that's also a dead-end.
Agustine

Hmm ... then it might be the best, if you help yourself another way, for example, doing a select one file dialog, coupled with an "add" button and a listview.

One chance that you could have is, to automate Internet Explorer (provided you have Internet Explorer 7.0+), which supports HTML 5 and with it multiple file dialogs.

You can translate the following VB Code. Note that you might have other COM components which support Multi-File-Browsers (e.g. Excels 'GetOpenFilename') - unfortunately if they return a string array (like the mentioned GetOpenFilename), you cannot process its results with DOORS (since IBM/Rational/Telelogic did not come around to support COM array types).

I guess that is all I can do, regards, Mathias
 

Function ChooseFile()
    ChooseFile = ""
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = False
    IE.Navigate ("about:blank")
    Do Until IE.ReadyState = 4
    Loop
    IE.Document.Write "<HTML><BODY><INPUT ID=""Fil"" name=""files[]"" Type=""file"" multiple=""""></BODY></HTML>"
    IE.Height = "0"
    IE.Width = "0"
    IE.Visible = True
    With IE.Document.all.Fil
        .Focus
        .Click
        ChooseFile = .Value
    End With
    IE.Quit
    Set IE = Nothing
End Function

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: Parsing variable containing strings delimited by null character
dasilvaa - Wed Oct 13 09:19:39 EDT 2010

Mathias Mamsch - Sat Oct 09 14:05:23 EDT 2010

Hmm ... then it might be the best, if you help yourself another way, for example, doing a select one file dialog, coupled with an "add" button and a listview.

One chance that you could have is, to automate Internet Explorer (provided you have Internet Explorer 7.0+), which supports HTML 5 and with it multiple file dialogs.

You can translate the following VB Code. Note that you might have other COM components which support Multi-File-Browsers (e.g. Excels 'GetOpenFilename') - unfortunately if they return a string array (like the mentioned GetOpenFilename), you cannot process its results with DOORS (since IBM/Rational/Telelogic did not come around to support COM array types).

I guess that is all I can do, regards, Mathias
 

Function ChooseFile()
    ChooseFile = ""
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = False
    IE.Navigate ("about:blank")
    Do Until IE.ReadyState = 4
    Loop
    IE.Document.Write "<HTML><BODY><INPUT ID=""Fil"" name=""files[]"" Type=""file"" multiple=""""></BODY></HTML>"
    IE.Height = "0"
    IE.Width = "0"
    IE.Visible = True
    With IE.Document.all.Fil
        .Focus
        .Click
        ChooseFile = .Value
    End With
    IE.Quit
    Set IE = Nothing
End Function

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Interesting idea, I'll try it out.

Thanks Mathias.