Results 1 to 21 of 21

Thread: shell and datagrid problems (newbie needs help)

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    54

    shell and datagrid problems (newbie needs help)

    I have been given the dubious task of writing a front end to a data processing tool, basicly the front end needs to write a text file, it should then call the data processor(dos based fortran) the data processor then produces two output files.

    I have used shell ("d:\matt\matt.exe", appwinstyle.maximisedfocus) this appears to call the dos based processor but it then closes down straight away without processing the file. If I double click the data processor, through windows explorer, it processes the file correctly.

    Couple of questions:

    What am I doing wrong - why does the dos file processor see the text file when manually started but not when started via VB?

    What is the correct way of starting the dos file and then when the dos program returns control to the calling program, it continuing on it's merry way?

    datagrids:

    I am having a total brain fart with this...

    I have a form with 22 datagrid controls on it, they are populated from an Access database. I am wanting to read the data from the datagrid controls, the access data provides base data that the user may want to modify, but I can't for the life of me think how to do it. I know in VB6B you could set up a control array, but can this be done in .net 2003?

    regards,

    Matt

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: shell and datagrid problems (newbie needs help)

    1. Don't use Shell() in .NET apps. Use Process.Start().

    2. Where is this input data file located and how does the data processor know how to find it if you aren't specifying its path in the commandline? Is it because it is located in the same folder as the EXE? In that case it's probably using the current directory. If you run the EXE from Windows Explorer then the current directory will be the folder containing that executable. If you run the EXE by calling Shell() the current directory will be the folder containing YOUR executable. If you want the process you start to use a specific working directory then you have to set it, e.g.
    vb Code:
    1. Dim exePath As String = "D:\Matt\Matt.exe"
    2. Dim psi As New ProcessStartInfo(exePath)
    3.  
    4. psi.WindowStyle = ProcessWindowStyle.Maximized
    5. psi.WorkingDirectory = IO.Path.GetDirectoryName(exePath)
    6.  
    7. Process.Start(psi)
    As for your DataGrid question, can you please ask unrelated questions in separate threads?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    54

    Re: shell and datagrid problems (newbie needs help)

    Thanks for the reply, will try that later.

    Sorry about dual question single posting will start a new post, reason for doing it was the two questions are for the same project.

    regards,

    Matt

  4. #4

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    54

    Re: shell and datagrid problems (newbie needs help)

    I have tried what was suggested above but all it does is open a dos box which then closes down - same as shell("d:\matt\matt.exe"), appwinstyle.maximisedfocus)

    It doesn't appear to be running the dos app as nothing appears in the dos box, however, when using the same code but deliberately pointing it to an incorect file or location the program throws an exception. Also if I point the code to cmd.exe or notepad.exe it opens up the command prompt and notepad perfectly.

    Any help would be appreciated.

    regards,

    Matt

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: shell and datagrid problems (newbie needs help)

    If there is an error with the Matt.exe file then it will close right away. Does it need a certain working directory or passed in arguments?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    54

    Re: shell and datagrid problems (newbie needs help)

    The program is a compiled fortran application, you run it and it prompts for a filename to process after receiving the filename it goes and produces a couple of results files.

    If I double click the exe file in explorer it opens up and runs fine.

    If I call it using the shell command of VB6 it works fine - well it opens up it just won't accept the input file.

    It just seems that VB.NET is doing something differnt and I aint got a clue as to what?

    regards,

    Matt

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: shell and datagrid problems (newbie needs help)

    Isnt it expecting a file as an argument then? Are you setting the working directory as shown?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    54

    Re: shell and datagrid problems (newbie needs help)

    I have set the working directory as shown above, also tried it in a test directory, on the c drive, on the d drive, etc, etc and it still just brings up a black screen which opens then closes immediately.

    My first instinct is that for some reason it isn't being allowed to open the fortran exe file, because if I point the exe to one that doesn't exist it throws up an error - therefore it must see a file as such but just can't open it.

    As I said I am novice to this so...

    regards,

    Matt

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: shell and datagrid problems (newbie needs help)

    The code seems fine but perhaps try adding ...

    psi.UseShellExecute = True
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    54

    Re: shell and datagrid problems (newbie needs help)

    Will give it a go tommorow - I don't have the source code at home..
    regards,

    Matt

  11. #11

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    54

    Re: shell and datagrid problems (newbie needs help)

    I have managed to do a work around with this by writing a one line batch file that calls the exe. I then get vb.net to run the batch file and it works - don't know why but....


    regards,

    Matt

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: shell and datagrid problems (newbie needs help)

    I guess as long as it works

    Ps, dont forget to Resove your thread from the Thread Tools menu so other members will know its been solved.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    54

    Re: shell and datagrid problems (newbie needs help)

    I have just found one other thing...

    when the dos program is run it wants the user to input the name of the file and press enter for it then to be processed - can this be done? If so how.

    I have tried alterring the batch file to see if it'll accept command line arguments but it doesn't seem to, so any ideas?

    Bat file example:

    matt.exe matt.txt

    This doesn't work, it only runs the program and it then waits for the user to enter the filename.

    regards,

    Matt

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: shell and datagrid problems (newbie needs help)

    Can you post the batch file text?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  15. #15

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    54

    Re: shell and datagrid problems (newbie needs help)

    The batch file is just one line as shown in the example.

    Matt.exe


    I have tried

    Matt.exe matt.txt

    but the program, matt.exe, just loads and asks for the name of the txt file to be processed.

    regards,

    Matt

  16. #16
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: shell and datagrid problems (newbie needs help)

    It may be needing you to pass the path too? How are you parsing or expecting to receive the file in your matt.exe program?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  17. #17

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    54

    Re: shell and datagrid problems (newbie needs help)

    Rob,

    When the exe file runs using the following bat file at the top of the screen it shows matt.exe matt.txt and the program matt.exe runs and asks for a file name to process.

    bat file

    matt.exe matt.txt


    Is it possible to pass a command to the started process???

    regards,

    Matt

  18. #18

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    54

    Re: shell and datagrid problems (newbie needs help)

    Anyone have any ideas???

    regards,

    Matt

  19. #19
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: shell and datagrid problems (newbie needs help)

    Yes, you can passit it the .Arguments parameter of either the Process or the ProcessStartInfo class
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  20. #20

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    54

    Re: shell and datagrid problems (newbie needs help)

    Rob,

    This will only work if the program accepts command line arguments, which mine doesn't.

    Had a brief conversation with a VB6 programmer and he said to do it via API calls - Would this be possible?

    regards,

    Matt

  21. #21

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    54

    Re: shell and datagrid problems (newbie needs help)

    Sorry for resurrecting this, but have found a problem when running the program via it's exe as opposed to running it through Visual Studio

    dim opsi as new processStartInfo(exepath)
    dim oprocess as New Process

    opsi.useshellexecute = false
    opsi.redirectstandardinput = true
    opsi.workingdirectory = IO.Path.GetdirectoryName(exepath)

    oprocess = process.start(opsi)
    oprocess.standardinput.writeline(inpfile)
    oprocess.waitforexit()

    Now when I run this in Visual Studio, all is well and the file gets processed, however, now I have come to distribute the app I run into the following problems:

    * When using any of the .exe files created in the bin directory it appears that the Dos program either isn't called ( a dos box appears briefly then shuts down) or the dos box doesn't receive the file name I am sending. This happens if I also run my programs exe from obj/debug and obj/release directories.

    * If I change the redirectstandardinput to use shellexecute then the dos program is called and appears on screen waiting for the name of the file to be processed, but I can't seem to work out how to send the filename this way as the dos program doesn't accept arguments.


    Initially I thought it was a problem with the machine I am passing the executable to but it also does the same on my development machine. What am I doing wrong?

    regards,

    Matt

Posting Permissions

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



Click Here to Expand Forum to Full Width