Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

VB annoying problem!!!!

Options
  • 14-02-2002 9:25pm
    #1
    Closed Accounts Posts: 5


    How do you call up text outputted by a c executed program onto a label on a form in vb6?

    The following is the code we used to send information entered into a text box on a vb form to input into a c executable program.

    Private Sub Command1_Click()
    Open "c:\input.txt" For Output As #1
    Print #1, txtSign.Text
    Print #1, txtHeight.Text
    Print #1, txtName.Text
    Print #1, vbCrLf
    Close #1

    Shell "c:\generate.exe < c:\input.txt "
    End Sub

    After clicking the command button this code sends the information entered into the text boxes to a text file called input.txt it then runs the generate.exe program entering the information in the text boxes to the program.

    What we would like to know using a similar program how we would receive text outputed by a program called commun.exe to a label in the vb form.

    Note this program does not require information to be entered into it, when run it just outputs the following text "no communication" or "there is communication".

    Does anybody know?


Comments

  • Registered Users Posts: 1,842 ✭✭✭phaxx


    Have the C program write it's output to a file, and then have VB read it. The only other way I know of would be DDE, or sockets, but using a file would be the easiest.


  • Closed Accounts Posts: 5 The bearded one


    We don't have access to the c files, we just have the executables.
    Anyway have you the code for what you suggest? we would be interested in seeing it


  • Registered Users Posts: 1,842 ✭✭✭phaxx


    Redirect the output to a file.

    Modify this line:

    Shell "c:\generate.exe < c:\input.txt "

    to be

    Shell "c:\generate.exe < c:\input.txt > c:\output.txt"

    Then open c:\output.txt, and off you go.

    [edit] Oh, and put some error handling in there. :) [/edit]


  • Closed Accounts Posts: 5 The bearded one


    Thanks, I think that may solve the problem. But I am a beginner in VB and I would be greatful If you could give the full code including reading the output from the text file in VB.


  • Registered Users Posts: 1,842 ✭✭✭phaxx


    Yeah sure no problem, but I'll need an example of the output the C program produces.


  • Advertisement
  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    Private Sub Command1_Click() 
    Const stdoutFile = "c:\input.txt"
    Const stdinFile = "c:\output.txt"
    Const GenerateEXE = "c:\generate.exe"
    Const PIPEfrom = " < " 
    Const PIPEto = " > "
    
    ff = Freefile
    Open  stdoutFile For Output As #ff
        Print #ff, txtSign.Text 
        Print #ff, txtHeight.Text 
        Print #ff, txtName.Text 
        Print #ff, vbCrLf 
    Close #ff 
    
    cmdline$ = GenerateEXE + PIPEfrom + stdoutFile + PIPEto + stdinFile 
    Shell cmdline$
    
    ff = freefile
    open stdinFile for input as #ff
      do while not eof(ff) 
          line input #ff, a$
    
          ' Add code to process lines here.  
          ' If it's a fixed set of lines, just use line inputs and remove
          ' do while/loop 
      loop
    close #ff
    
    End Sub 
    
    

    (you can see I'm bored. :/ )


  • Closed Accounts Posts: 5 The bearded one


    Thanks Hobbes it worked the finest!


Advertisement