Discussion Locked

Shell Function in VB6

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hey. I'm updating a QBasic program to VB6. I'm trying to update a certain piece of code that works fine in Qbasic, but isn't working correctly in VB6. Here is the code written in Qbasic:
"Shell sort /+1 < c:\pb\wrk\mac.wrk > c:\pb\wrk\mac.srt"
in VB6:
RetVal = Shell("sort /+1 < p:\pb\wrk\mac.wrk > p:\pb\wrk\mac.srt")

The mac.wrk file is created earlier in the program and all I want this piece to do is sort the file and place it in mac.srt. For some reason the mac.srt file isn't getting created in VB6 and the whole program fails. Can anyone help me?

8 replies

by vinnyd

There are a few reasons why it will not work.

1. It has to find the sort.exe program.

If sort.exe is not found it will not work.

2. Is the P: drive accessible?

if there is no p: drive it will not work

3. Does the p:\pb\wrk\mac.wrk whole path exist?

You can also try this:

RetVal = Shell("sort /+1 < p:\pb\wrk\mac.wrk > p:\pb\wrk\mac.srt", vbMaximizedFocus)

In VB this will maximize the DOS window so you can see the command execute. If you have a fast computer you maynot be able to see it.

Last

Put the command "sort /+1 < p:\pb\wrk\mac.wrk > p:\pb\wrk\mac.srt" in a batch file and try and see if it works from the DOS prompt.

What happens is any error at all and the command fails.

by shanghai sam

1. It does find the sort program.
2. P drive does indeed exist
3. The 'p:\pb\wrk\mac.wrk' path exists
4. It does work from the dos prompt

by andrew

The VB Shell is designed to run an executable file, not a set of statements.

Create a batch file (macsort.bat) that has the sinlge line

sort /+1 < p:\pb\wrk\mac.wrk > p:\pb\wrk\mac.srt

in it.

Call this with the shell:

retval = Shell("p:\pb\wrk\macsort.bat")

by magicdress

hi paespi0,

the only problem i can see is the < > around your .wrk filename. it works fine from vb6 with .txt files.

hth,
becky

This discussion is closed to new replies.