Exclamation[Help] Open a file automatically [VB6] [solved]

Posts 1–15 of 39 · Page 1 of 3
[Help] Open a file automatically [VB6] [solved]
Hello, I am trying to find a way that when I push a button in Visual Basic, a file will open.
I have tried this code ( Dim RetVal
RetVal = Shell("C:\Users\User\Desktop\Mp3cyprusmaniacs_cont est\ini.bat", vbWindowState) ) and it works fine, but it is with a path..and when the file is not there, a message pops up with "error 53 - file not found"..
I would like to know if there is a way to open that file without using any path..
Thanks
uh just add a openfiledialog and add a button and double click on the button and type:


OpenFileDialog1.showdialog




its that simple lol
can you tell me what to do in more details because it is my first day in vb6? :P @justiman
So you want to select a file and open it?
Its easy! You need a CommonDialogControl

Code:
With CommonDialog1
    .FileName = ""
    .ShowOpen
    
    If .FileName <> "" Then
        RetVal = Shell("CommonDialog1.FileName", vbWindowState)
    End If
End With
Quote Originally Posted by edub18 View Post
So you want to select a file and open it?
Its easy! You need a CommonDialogControl

Code:
With CommonDialog1
    .FileName = ""
    .ShowOpen
    
    If .FileName <> "" Then
        RetVal = Shell("CommonDialog1.FileName", vbWindowState)
    End If
End With
my way is easier...
vb6? the code i have dont work for vb6... get vb 2010 its ALOT better. then do what i said and there you go... or i could make it for you and send it to you
Quote Originally Posted by lelelololele View Post
will this work for vb6? @edub18
i can just make one for you in like 30 seconds and send it to you
do you mean make a form in VB6 with a button which opens a file?
Quote Originally Posted by justiman View Post
i can just make one for you in like 30 seconds and send it to you
He wants to learn himself, he doesn't want to just take something he didn't make
Quote Originally Posted by lelelololele View Post
will this work for vb6? @edub18
Of course. My snippet is VB6
Quote Originally Posted by lelelololele View Post
do you mean make a form in VB6 with a button which opens a file?
yea thats what you do o.0
hmmm...I don't know..something is wrong here -.-
Code:
Private Sub Command1_Click()
With CommonDialog1
    .FileName = "ini.bat"
    .ShowOpen
    
    If .FileName <> "ini.bat" Then
        RetVal = Shell("CommonDialog1.FileName", vbWindowState)
    End If
End With
End Sub
what did I do wrong?
sry for being so annoying, but, I am a newbie in vb6
so, i just create a button and put this code?
Code:
rivate Sub Command1_Click()
With CommonDialog1
    .FileName = ""
    .ShowOpen
    
    If .FileName <> "" Then
        RetVal = Shell("CommonDialog1.FileName", vbWindowState)
    End If
End With
End Sub
if yes, there is an error..
Dont change the filename. You can use the code as i posted it.

Code:
.Filename = ""
Posts 1–15 of 39 · Page 1 of 3
This thread is closed for replies.

Tags for this Thread

None

Talk with us