|
-
Jul 9th, 2008, 12:51 AM
#1
Thread Starter
Addicted Member
[RESOLVED] how can i load txt file to list box without common dailog Control...?
how can i load & Save txt file to/from list box without common dailog Control...?
i know this can be done.... i have seen tutorial.... but cant find on the site... ??
help plz !! thnx
●════════════════════════════◄►═════════════════════════●
___itš bεttεг tΘ bε απ Θρεπ šiππεг, thαπ α ƒαlšε šαiπt___
●════════════════════════════◄►═════════════════════════●
гαj
-
Jul 9th, 2008, 01:03 AM
#2
Re: how can i load txt file to list box without common dailog Control...?
Not sure why you'd even need a common dialog, but here's a utility module that has functions for using the Open and Save common dialogs without needing a common dialog control, as well as reading and writing text files to/from string variables.
Code:
Option Explicit
Private Enum FlagsEnum
feOpen
feSaveAs
End Enum
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
' Common Dialog - Open
Public Function ShowOpenDialog(pstrInitialPath As String, pstrFilter As String, pstrDefaultExt As String) As String
Dim typFileName As OPENFILENAME
typFileName = GetStructure(pstrInitialPath, "", pstrFilter, pstrDefaultExt, feOpen)
If GetOpenFileName(typFileName) Then ShowOpenDialog = Left$(typFileName.lpstrFile, InStr(typFileName.lpstrFile, Chr$(0)) - 1)
End Function
' Common Dialog - SaveAs
Public Function ShowSaveAsDialog(pstrInitialPath As String, pstrFile As String, pstrFilter As String, pstrDefaultExt As String) As String
Dim typFileName As OPENFILENAME
typFileName = GetStructure(pstrInitialPath, pstrFile, pstrFilter, pstrDefaultExt, feSaveAs)
If GetSaveFileName(typFileName) Then ShowSaveAsDialog = Left$(typFileName.lpstrFile, InStr(typFileName.lpstrFile, Chr$(0)) - 1)
End Function
Public Function LoadFileToString(pstrFile As String) As String
Dim bytArray() As Byte
Dim FileNumber As Long
FileNumber = FreeFile
Open pstrFile For Binary Access Read As #FileNumber
ReDim bytArray(LOF(FileNumber) - 1)
Get #FileNumber, 1, bytArray
Close #FileNumber
LoadFileToString = StrConv(bytArray, vbUnicode)
Erase bytArray
End Function
Public Sub SaveStringToFile(pstrFile As String, pstrText As String)
Dim FileNumber As Long
FileNumber = FreeFile
Open pstrFile For Output As #FileNumber
Print #FileNumber, pstrText
Close #FileNumber
End Sub
Private Function GetStructure(pstrPath As String, pstrFile As String, pstrFilter As String, pstrDefaultExt As String, penFlags As FlagsEnum) As OPENFILENAME
Const OFN_FILEMUSTEXIST = &H1000
Const OFN_PATHMUSTEXIST = &H800
Const OFN_HIDEREADONLY = &H4
Const OFN_LONGNAMES = &H200000
Const OFN_OVERWRITEPROMPT = &H2
Const OF_WRITE = &H1
Const MAX_PATH = 260
Dim frm As Form
With GetStructure
.lStructSize = Len(GetStructure)
' Get any form's window handle
For Each frm In Forms
Exit For
Next
.hwndOwner = frm.hwnd
Set frm = Nothing
.hInstance = App.hInstance
.lpstrFilter = Replace(pstrFilter, "|", Chr(0)) & Chr(0)
.nMaxFile = MAX_PATH + 1
.nMaxFileTitle = MAX_PATH + 1
.lpstrFileTitle = Space(MAX_PATH)
.lpstrInitialDir = pstrPath
.lpstrDefExt = pstrDefaultExt
Select Case penFlags
Case feOpen
.lpstrTitle = "Open"
.lpstrFile = Space(MAX_PATH)
.Flags = OFN_FILEMUSTEXIST + OFN_HIDEREADONLY + OFN_LONGNAMES
Case feSaveAs
.lpstrTitle = "Save As"
.lpstrFile = pstrFile & Space$(MAX_PATH - Len(pstrFile))
.Flags = OFN_PATHMUSTEXIST + OFN_HIDEREADONLY + OFN_LONGNAMES + OFN_OVERWRITEPROMPT + OF_WRITE
End Select
End With
End Function
-
Jul 9th, 2008, 01:26 AM
#3
Thread Starter
Addicted Member
Re: how can i load txt file to list box without common dailog Control...?
thnx Dude That Worked Like Charm!!
the reason..... i am not using any ocx... is i want 2 make program w/o any dependencies.......
thnx !!
●════════════════════════════◄►═════════════════════════●
___itš bεttεг tΘ bε απ Θρεπ šiππεг, thαπ α ƒαlšε šαiπt___
●════════════════════════════◄►═════════════════════════●
гαj
-
Jul 9th, 2008, 01:44 AM
#4
Thread Starter
Addicted Member
Re: [RESOLVED] how can i load txt file to list box without common dailog Control...?
1 MORE HELP PLZ........
dim s$
S = ShowOpenDialog(App.Path, "All Files|*.*", "TXT FILES")
HOW CAN I SHOW CUSTOM DAILOG TITLE..... EVERY TIME.... ??
●════════════════════════════◄►═════════════════════════●
___itš bεttεг tΘ bε απ Θρεπ šiππεг, thαπ α ƒαlšε šαiπt___
●════════════════════════════◄►═════════════════════════●
гαj
-
Jul 9th, 2008, 04:37 AM
#5
Re: [RESOLVED] how can i load txt file to list box without common dailog Control...?
What do you want to change it to?
-
Jul 9th, 2008, 10:49 AM
#6
Thread Starter
Addicted Member
Re: [RESOLVED] how can i load txt file to list box without common dailog Control...?
like...... i am gonna use that API at many place.....
so was expecting function like........
Code:
ShowOpenDialog(pstrInitialPath As String, pstrFilter As String, pstrDefaultExt As String, DailogCaption as string) as string
that way
●════════════════════════════◄►═════════════════════════●
___itš bεttεг tΘ bε απ Θρεπ šiππεг, thαπ α ƒαlšε šαiπt___
●════════════════════════════◄►═════════════════════════●
гαj
-
Jul 9th, 2008, 07:56 PM
#7
Re: [RESOLVED] how can i load txt file to list box without common dailog Control...?
Just change the value of lpstrTitle in the GetStructure function. You'll probably want to add a parameter to both GetStructure and both entry-point functions so you can change it for each call.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|