Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

writing to file

Posted on 2003-03-17
17
Medium Priority
?
154 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month12 days, 8 hours left to enroll

580 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