fereforkids.blogg.se

Vb6 file functions
Vb6 file functions




vb6 file functions
  1. #VB6 FILE FUNCTIONS CODE#
  2. #VB6 FILE FUNCTIONS PLUS#
  3. #VB6 FILE FUNCTIONS WINDOWS#

#VB6 FILE FUNCTIONS CODE#

When a user clicks an item in the listbox, this code gets executed from the appropriate place in your program: x = Ĭall LoadUserFile(Me.ListView1.ListItems(x).SubItems(1)) ' Add a value to the second column to the first item on the listĬlosdb() ' this line just closes the connection Sql = "select tblDocs.docName, tblDocs.docPath, tblDocs.id from tblDocs where clientid = " & getClientID(ActiveClientName)Ĭall opnDB(Me) ' this line just opens a connection to the database. ' the next line builds the sql statement and adds the user id to the where clause so each user can only see their own documents. The path information is stored in an MS Access database: Function popList() I named my listbox "ListView1" (vb default name) The path information is stored in an MS Access table, or an sql server table, or a MySQL table, or whatever other place you might want to keep them. As is.Įlsewhere in a program I fill a listbox with the path information of the files I might want to open in their native application. The code I posted earlier goes into a module. I was going to stay out of this, but I see too many ways being described to do the same thing. MsgBox Err.Description, vbCritical, "Error" LoadMyFile = Shell(MyProgramName & Chr$(32) & MyFileName, vbNormalFocus) Private Function LoadMyFile(ByVal MyProgramName As String, ByVal MyFileName As String) As Double LoadUserFile = ShellExecute(AppHandle, "open", MyFileName, 0, 0, SW_SHOWNORMAL) Private Function LoadUserFile(ByVal AppHandle As Long, ByVal MyFileName As String) As Long MsgBox "Error # " & CStr(lngReturn), vbCritical, "Error"ĭblReturn = LoadMyFile("NotePad", vbNullString) LngReturn = LoadUserFile(Me.hwnd, "C:\Documents\My.mdb") (ByVal hwnd As Long, ByVal lpOperation As String, _īyVal lpFile As String, ByVal lpParameters As String, _īyVal lpDirectory As String, ByVal nShowCmd As Long) As Long Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _ The VB Shell function just performs a limited set of the options of the ShellExecute API. The following example uses both the ShellExecute API and the VB Shell function. You have more options, if you use the ShellExecute API. You need to use a space between the program name and the parameter hence, chr$(32).

#VB6 FILE FUNCTIONS PLUS#

If you use the VB Shell function, you then must use the actual name of the program plus any parameters that may accompany the file.

#VB6 FILE FUNCTIONS WINDOWS#

The operating system will use the program that is designated in the windows registry to open a file with that file's extension. In your case, you just want to use "open" for the operation. When you use the ShellExecute API you can just use "open", "print", or "explore" for the second parameter.

vb6 file functions

Unless the programmer's intent was to optionally change the value of the variable. So, that function probably could have been more efficiently written by using ByVal. The function can then change the value of that variable, but it does not sound like it will. To get around the error and to use the function as is, just declare a variable and give it a value before sending it to the function. When your function uses ByRef, then you need to send a variable. If the function requires a variable, then you need to send a variable that you declared in your function. You receive the error because you are sending a value i.e. I can't open " & opFile, vbInformation vbInformation + vbOKOnly, "Error occured on file open" MsgBox "The file you are trying to open apparently has no program association available" & vbCrLf & "or it is a corrupted file. OpFile = Right(FN2Load, Len(FN2Load) - x)Ĭall Shell(retassoc(opFile, opPath) & " " & Chr(34) & FN2Load & Chr(34), vbNormalFocus) ' load the file in its' native application Success = FindExecutable(fn, fpath, sResult)įunction LoadUserFile(ByVal FN2Load As String) Private Const ERROR_BAD_FORMAT As Long = 11įunction retassoc(fn As String, fpath As String) As String Private Const ERROR_FILE_SUCCESS As Long = 32 'my constant Private Const ERROR_PATH_NOT_FOUND As Long = 3 Private Const ERROR_FILE_NOT_FOUND As Long = 2 Private Const ERROR_FILE_NO_ASSOCIATION As Long = 31

vb6 file functions

I am calling the function by Call LoadUserFile("D:\MB.mdb")Ĭode function i am using by Mike Bonnell Private Declare Function FindExecutable Lib "shell32" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal sResult As String) As Long Points error to opFile in following line Call Shell(retassoc(opFile, opPath) & " " & Chr(34) & FN2Load & Chr(34), vbNormalFocus)






Vb6 file functions