How to Open a file

Post here about scripting and programming for HaloPC (audio, network, ai, etc.)
Post Reply
User avatar
shade45




Translator Artisan Enthraller Logistician
Stylist Wave Firestorm New Age

Posts: 2270
Joined: Fri Apr 01, 2005 1:04 pm

How to Open a file

Post by shade45 »

Noob Question but...
What Code would i use in vb6 to make it so when a user clicks File->open this pops up
Image
User avatar
shade45




Translator Artisan Enthraller Logistician
Stylist Wave Firestorm New Age

Posts: 2270
Joined: Fri Apr 01, 2005 1:04 pm

Post by shade45 »

Ok i found out how to get it to work with this code

Code: Select all

    cdlCommon.CancelError = True
    cdlCommon.Flags = cdlOFNHideReadOnly ' Hides read only files
    cdlCommon.Filter = "All Files (*.*)|*.*|Halo 2 Map File" & _
    "(*.map)|*.map|"
    ' Specify default filter
    cdlCommon.FilterIndex = 2
    cdlCommon.ShowOpen
But how do i make it so there isnt an error when pressing cancle??
Onetoomanysodas





Posts: 325
Joined: Mon Mar 22, 2004 3:59 pm
Location: Everywhere but nowhere
Contact:

Post by Onetoomanysodas »

--GO TO BOTTOM OF THIS POST BEFORE READING--

If you're having trouble you can review Uber-banana's tutorial on this.

If you want to null out any errors you still may be having...

This is how to set specific tasks to perform if the process comes across any erros. At the beginning of the 'Private Sub' put the statement: 'On Error GoTo errorhandler'

errhandler is just a random name i decided to choose for the 'Goto' label. Your code should look relatively like this now:

Code: Select all

Private Sub cmd1_Click()
On Error GoTo errorhandler
After that you can put the code for the open dialog and whatever else you want. At the end of that code place the line 'Exit Sub'. This will quit the process and ignore everything beyond that line. This means if no errors occurr while the open file dialog is open then it will ignore this next line:

Code: Select all

errorhandler:
Exit Sub
This means that when an error is run upon and it goes to the line defined as 'errorhandler' it will commit the action of 'Exit Sub'.

This is what your final code should look like:

Code: Select all

Private Sub cmd1_Click()
On Error GoTo errorhandler

' (Your code here)
Exit Sub

errorhandler:
Exit Sub

End Sub

Anyways, if you meant an error that Visual Basic was giving you then I just wasted my time. Whatever, you actually probably are, add this right after '.Flags'

Code: Select all

cdlCommon.CancelError = False
:( I want to kill myself...
User avatar
shade45




Translator Artisan Enthraller Logistician
Stylist Wave Firestorm New Age

Posts: 2270
Joined: Fri Apr 01, 2005 1:04 pm

Post by shade45 »

Thanx for explaining :D
Post Reply