Results 1 to 9 of 9

Thread: Unix and VB

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Posts
    106

    Unix and VB

    I have a Unix script which generates a '.csv' file.

    I have to automate the following process :

    1. After the '.csv' file is generated, I should invoke some
    command (maybe that's a script again) which will read
    the '.csv' file and creates a '.mdb' file.

    2. Is there anyway that I can call a 'VB' program from a Unix
    script? Or

    3. how can I call a VB program from another VB program?

    Any ideas? I have the standalone VB programs running. At this point, I have to manually take the '.csv' file and generate an access DB. So, I am looking to automate this step.

    any help towards this is greatly appreciated.

  2. #2
    Addicted Member Michael Woolsey's Avatar
    Join Date
    Nov 2000
    Location
    Calgary, Alberta, Canada.
    Posts
    243
    I can answer #3:
    VB Code:
    1. Shell "c:\windows\notepad.exe", vbNormalFocus

    This will let you run another application from within Visual Basic.

    Regarding #2, I don't know how possible that is, since Visual Basic Applications are for windows only, unless you are using some sort of porting program I doubt it's possible. Though since I don't use Unix at all I could be wrong.

    Hope this helps.
    Michael Woolsey
    Application/Web Developer

    Visual Basic 6.0 SP5
    Active Server Pages
    Oracle 9i
    - I'm going to live forever, or die trying!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Posts
    106
    #3 -> I want to call another VB program from a VB program.

    So, if I write
    Shell "c:\windows\VBsample.exe", vbNormalFocus

    from the first program....it will goto VBsample program and execute it and then will it return back to the primary program(first program) or can I end it in the called program? Hey, I have never done such a thing. So, I want to understand the flow and the way it would work. Thank You.

  4. #4
    Addicted Member Michael Woolsey's Avatar
    Join Date
    Nov 2000
    Location
    Calgary, Alberta, Canada.
    Posts
    243
    I'm pretty sure Shell will start the second program and then continue what it was doing. I'm pretty sure they run seperatly.

    I'm not sure of a absolute way of killing another application from VB, though you could look for the window using the API call FindWindow and then tell it to close. The telling it to close part can have issues if you don't do it correctly and since I haven't done it before I can't advise you on that.

    I think you can send the window a constant (WM_CLOSE or something like that) using the SendMessage API. This is from my memory of some other posts here... try doing a search you should find good examples of how to do it.

    Sorry I can't be of more help.
    Michael
    Application/Web Developer

    Visual Basic 6.0 SP5
    Active Server Pages
    Oracle 9i
    - I'm going to live forever, or die trying!

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Posts
    106
    Guys.....Anyone out there????????? give it a shot....may be I can investigate on some issues......

  6. #6
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258
    So what do you want to know?

  7. #7
    Addicted Member
    Join Date
    Jul 1999
    Location
    Portland, OR.
    Posts
    226
    Hi,

    For No.: 3

    Code:
    Private Type STARTUPINFO      
      cb As Long      
      lpReserved As String      
      lpDesktop As String      
      lpTitle As String      
      dwX As Long      
      dwY As Long      
      dwXSize As Long      
      dwYSize As Long      
      dwXCountChars As Long      
      dwYCountChars As Long      
      dwFillAttribute As Long      
      dwFlags As Long      
      wShowWindow As Integer      
      cbReserved2 As Integer      
      lpReserved2 As Long      
      hStdInput As Long      
      hStdOutput As Long      
      hStdError As Long   
    End Type
    
    Private Type 
      PROCESS_INFORMATION      
      hProcess As Long      
      hThread As Long      
      dwProcessID As Long      
      dwThreadID As Long   
    End Type
    
    Private Declare Function WaitForSingleObject Lib "kernel32"   (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    
    Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
          lpApplicationName As String, ByVal lpCommandLine As String, ByVal _
          lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
          ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
          ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
          lpStartupInfo As STARTUPINFO, lpProcessInformation As _
          PROCESS_INFORMATION) As Long
    
    Private Declare Function CloseHandle Lib "kernel32" _
          (ByVal hObject As Long) As Long
       Private Declare Function GetExitCodeProcess Lib "kernel32" _
          (ByVal hProcess As Long, lpExitCode As Long) As Long
       Private Const NORMAL_PRIORITY_CLASS = &H20&
       Private Const INFINITE = -1&
       Public Function ExecCmd(cmdline$)
          Dim proc As PROCESS_INFORMATION
          Dim start As STARTUPINFO
          ' Initialize the STARTUPINFO structure:
          start.cb = Len(start)
          ' Start the shelled application:
          ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
             NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
          ' Wait for the shelled application to finish:
             ret& = WaitForSingleObject(proc.hProcess, INFINITE)
             Call GetExitCodeProcess(proc.hProcess, ret&)
             Call CloseHandle(proc.hThread)
             Call CloseHandle(proc.hProcess)
             ExecCmd = ret&
       End Function
    
    Sub Command1_Click()
          Dim retval As Long
          retval = ExecCmd("notepad.exe")  ''  The shelled program
          MsgBox "Process Finished, Exit Code " & retval
    End Sub
    
    'NOTE: The MsgBox statement following the ExecCmd() function is not executed because the
    'WaitForSingleObject() function prevents it. The message box does not appear until Notepad
    'is closed when the user chooses Exit from Notepad's File menu (ALT, F, X).
    Good Luck.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Posts
    106

    Talking

    Hi Lyla,
    I have not understood most of the statements that you have written here. That's b'cos I have never used such things. But, I guess this is the time to learn. But, could you give me some heads-up on the code that you have written, maybe just a line on each of them. I REALLY am thankful for taking time to do this.

  9. #9
    Addicted Member
    Join Date
    Jul 1999
    Location
    Portland, OR.
    Posts
    226
    Hi neyyi,

    That's Ok.

    Check this link. That's where i got the code, It might help.

    http://support.microsoft.com/support.../Q129/7/96.asp


    Good Luck.

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