Visual Basic help

P

Paul

Can anybody check this code for me
Private Sub CmdView_Click()
Dim extension As String
Dim returnValue

extension = UCase$(Right$(txtFile.Text, 3))

If Dir$(txtFile.Text) = "" Then 'remove the space between the quotes > MsgBox "File is not found!", vbExclamation > > > ElseIf extension = "TXT" Then > returnValue = Shell("Notepad" & txtFile.Text, 1) returnValue = Shell("Notepad " & txtFile.Text, 1) ' Added a space after Notepad to make a distinction between the application called and the parameters. > > ElseIf extension = "BMP" Then > returnValue = Shell("Pbrush" & txtFile.Text, 1) > > End If > End Sub > > It didn't work !!!! I tested it and it works. (try to indent your code and use End If even if not mandatory;-) Guy A Andrew Archibald Noticed a couple things First > If Dir$(txtFile.Text) = " " Then
should be equated to a null string "" not a space

> If Dir$(txtFile.Text) = "" Then <--(Right) T [email protected] Could you be a bit more specific? I was able to execute your code fragment and it did call up notepad with the specified file. However, in your shell script you do need a space between 'notepad' and the filename. Another problem is that the command 'Dir$' returns an empty string when no file is found and your test is looking for 'Dir$' equal to one space, Chr$(32).

[email protected]

J

John

You need to add a space between the program you are executing with the Shell function and the filename you are passing to that program as a parameter. Your line of code
returnValue = Shell("Notepad" & txtFile.Text, 1)
returnValue = Shell("Notepad " & txtFile.Text, 1)
This also applies to the line calling the Paint program.

Regards,

John Messinger

G

Greg Schiller

First of all what didntt work. Step throug your program. look at your vars in the debug window.

or use

Try fname$= Dir$(txtfile.text)
msgbox fname$Next Try if Dir$(txtfile.text) = "" then
...

Or check the length of your return value

if Len(Dir$(txtfile.text)) = 0 then ... Good luck. Greg Schiller www.autoamtica.biz H Hevelton Araujo Junior Two things: 1. The line If Dir$(txtFile.Text) = " " Then
the quotes should not have space between them

2. The program names in the Shell statement ("Notepad" and "Pbrush") should have a space after just as if written in the cmd line.

Hope it helps !

--
Hevelton Araujo Junior
Gerência de Engenharia
Tel.: +55-31-34275852
Fax.: +55-31-34912077
[email protected]

A

Arturo Martinez

returnValue = Shell("Pbrush" & txtFile.Text, 1)

Shell in VB, for Win98 and upper, need variable 'returnValue' has dimensioned for LONG. In Declare section of Basic Module you say default dimen

A

Anonymous

Hi!!
How I can close the File??

D

David

How about checking if the Directory was found, insted of a file?

Y

Yarab

You must leave spave after Notepad i.e.:

runnp = Shell("notepad.exe " & txtfile.text , vbNormalFocus)

the space is neccessary

A

Anonymous

> Hi!!
> How I can close the File?? <

go to the main visual basic program and end the sub program.