?
Solved

writing to file

Posted on 2003-03-17
17
Medium Priority
?
149 Views
Last Modified: 2010-05-03
I hace a Visual basic 6.0 program that calls a small C program using the Shell Command. The c program
just creates a small file. I had expected the file to be in the same folder as the visual basic program
but when I searched for it, I found it in the Program Files\Microsoft Visual Studio\VB98  folder.
Can anyone explain why and how to I get it in the folder where the visual basic program is.

Thanks
0
Comment
Question by:pentomino
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 3
  • +2
17 Comments
 
LVL 14

Expert Comment

by:aelatik
ID: 8154538
Did you run it during runtime or are we talking about a compiled executable ?
0
 
LVL 14

Expert Comment

by:aelatik
ID: 8154541
Sorry, i ment design time..
0
 
LVL 1

Expert Comment

by:tolstoyleo
ID: 8154551
this copys a text file from my c drive to my desktop


Private Sub Form_Load()

Dim fso As Object
Set fso = CreateObject("scripting.filesystemobject")
fso.copyfile "c:\test2.txt", "c:\documents and settings\mday\desktop\test2.txt"
Set fso = Nothing

End Sub
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:aelatik
ID: 8154588
If it's about copying use...

Private Sub Form_Load()
FileCopy "c:\source.ext", "c:\destination.ext"
End Sub
0
 
LVL 1

Expert Comment

by:tolstoyleo
ID: 8154642
i agree with aelatik... just like checking if a directory exists... using dir(dirname, folder) works faster because it's a shell call...

Same thing though..
0
 
LVL 1

Author Comment

by:pentomino
ID: 8154669
It was run in design time, from the visual basic IDE.
It is not copying a file.It is creating one.
0
 
LVL 1

Expert Comment

by:tolstoyleo
ID: 8154686
so you need to modify the C code, this is the vb discussion area
0
 
LVL 1

Expert Comment

by:tolstoyleo
ID: 8154690
if the C code creates the file that is
0
 
LVL 1

Expert Comment

by:tolstoyleo
ID: 8154695
plus... i take back my original comment about the shell call being faster... the file system object actually executes things faster than native vb shell calls
0
 
LVL 14

Expert Comment

by:aelatik
ID: 8154714
Compile it > copy it to the right directory and then test it. Personaly i don't think the C file is hardcoded ( nobody will do that, especialy to a VB directory )

0
 
LVL 1

Author Comment

by:pentomino
ID: 8154740
aelatik...
The C program creates the file in the current directory, which I assumed was the one where the project resides.  If
I build the executable and run it (outside the VB IDE)  the file IS created in the same directory as the VB executable..
whis is what I want... soooo I guess my question is how do I make the directory that the project is in be the working directory for the shelled program? So I can be developing
and testing without leaving the IDE.
0
 
LVL 14

Expert Comment

by:aelatik
ID: 8154758
Save the project in the Correct directory and compile it once...
0
 
LVL 1

Expert Comment

by:tolstoyleo
ID: 8154759
can you just move the whole vb project?  or .. if you can write a c function in the code that has dll_export capabilities than you could write a property that tells the vb where that file resides
0
 
LVL 14

Expert Comment

by:aelatik
ID: 8154890
If that doesn't work, open the project by doubleclicking the .vbp file from the directory ( not using File > Open project )
0
 
LVL 14

Expert Comment

by:Tommy Kinard
ID: 8155215
in the properties of the shortcut you are using, change the working directory to the one you want. This will create the file(from the c program) in the currect directory.
0
 
LVL 8

Accepted Solution

by:
bukko earned 1000 total points
ID: 8155353

Before calling the C program from VB, use the VB "ChDir" command to change the current folder.
e.g.:

ChDir "c:\my\folder\"

Regards

bukko
0
 
LVL 1

Author Comment

by:pentomino
ID: 8155468
Thanks bukko
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question