hexagon logo

VBScript Dir command returning incomplete results

Dear experts,

I have a PC-DMIS form with a ComboBox (named fd_ifoname) which I'm trying to populate with results from a Dir() file system call by means of the following super simple VBScript in the window's initialize event:

file = Dir(".\*")
While file <> ""
    fd_ifoname.AddString file
    file = Dir()
Wend​


It's working in principle, but the thing is that the results are incomplete. In particular, I'm trying to read out the contents of a subfolder of PC-DMIS's own routines, but it's only returning two *.MiniRoutines.xml files of the 21 non-hidden files (including *.prg, *.cad, and some more *.MiniRoutines.xml files). I'm having similar issues with almost every folder on our C and D drives (two partitions of the same SSD) with most folders appearing completely empty, but on the other hand, the Dir() function seems to be working just fine when listing files from a network drive. That's all the drives I was able to test with on our cleanroom PC and, in case you're wondering, the SSD is working perfectly fine. Also, I modified the above code to force the loop to go beyond the case of file == "" just to see what might still be coming, but the results stay empty.

Has anyone of you encountered this strange behavior and know a way around it? If not, can you think of another (preferably convenient) way to read out a list of files from within a form?

Thanks everyone!
  • I would probably look at the FileSystemObject instead of trigging a DIR() command.

    Google it for more info.
  • Thanks for your quick reply, vpt.se!

    I actually tried that at some point but forgot to mention it here. Even putting something as simple as the following into the initialize even handler fails with an unsupported scripting operation error:

    objFS = CreateObject("Scripting.FileSystemObject")
    objFolder = objFS.GetFolder("D:\PC-DMIS Data\Routines\")
    MsgBox objFolder.DateCreated​


    So I figured (maybe incorrectly) that the FileSystemObject is not supported in PC-DMIS. BTW, we're using PC-DMIS 2020 R2 SP1 in case this is relevant.
  • Well, your thread title is VBScript... ;P

    Anyway, you could make a VBS that dumps the folder contents into a textfile that you then read from your form.

    Form -> Call dumpfolder.vbs
    Dumpfolder.vbs creates a textfile with the folder content
    Form -> read the textfile to get the folder content
  • Am I missing something here? My understanding was PC-DMIS won't run a VBS. I end up always having to shell it with a BAT file. ex.

    @echo off
    cscript //nologo c:\cmm\scripts\script.vbs %1 %2



    Is there a simple way to run a VBS from within PC-DMIS?
  • I chose the thread title because it was my understanding that form events use the VBScript language. So, I take it that form event handlers have only a limited set of VBScript features available to them? Anyway, thanks a lot for your suggestion! I'll give it a try and report back if it'll work.

    In the manual I saw a way to trigger "BASIC scripts" from PC-DMIS directly. I don't know if this is the same thing as a VBScript (maybe without GUI-related stuff) or not. As far as I can tell from my very limited VBScript experience, the BASIC script example code in the manual looks an awful lot like it even though the file extension is different (*.bas). If I cannot get it to work through the BASIC script mechanism, you already provided me with an alternative triggering mechanism. Thanks you very much!
  • Thanks for your quick reply, vpt.se!

    I actually tried that at some point but forgot to mention it here. Even putting something as simple as the following into the initialize even handler fails with an unsupported scripting operation error:

    objFS = CreateObject("Scripting.FileSystemObject")
    objFolder = objFS.GetFolder("D:\PC-DMIS Data\Routines\")
    MsgBox objFolder.DateCreated​


    So I figured (maybe incorrectly) that the FileSystemObject is not supported in PC-DMIS. BTW, we're using PC-DMIS 2020 R2 SP1 in case this is relevant.




    So the file scripting object is an object, which in old vb (vb6, vbscripts etc) needs to use the SET keyword to differentiate it from a standard variable.



    Form with:
    List box (lstFiles)
    Edit box (txtPath)
    Button (cmdGo)

    This will list all the file for the given path.


    
    Dim objfso As Object
    Set objfso = CreateObject("scripting.filesystemobject")
    
    Dim mypath
    mypath = txtPath.Text
    
    Dim objfolder As Object
    
    Set objfolder = objfso.getfolder(mypath)
    
    Dim objf As Object
    
    For Each objf In objfolder.files
    lstfiles.AddString objf.name
    
    next​
    
    

  • Ah, I see, that was the problem. Thank you very much! :-)
  • One more question to which I can't seem to find an answer despite an extensive search: Is there a method to add entries to a combobox in a way that also includes the index number and not just the string? I believe I would need that to preselect a certain entry and, in addition to that, it would make communicating with PC-DMIS so much easier.
  • i think you can use this
    ComboBox1.Selection 'activ entry as integer / read and write (you can here pre-select an entry)
  • Perfect, that does the trick. Thank you very much, ! :-)