I need to write data to a text file. I am able to open the save file dialog box. I need to append the .txt for file name if the user has not given the extension
the code i have is :
Dim lngFormHwnd As Long
Dim lngAppInstance As Long
Dim strInitDir As String
Dim strFileFilter As String
Dim strFileName As String
Dim lngResult As String
Dim strTitle As String
Dim mlngFileNum As Long
mlngFileNum = FreeFile
strTitle = "Save File"
strFileName = "" & String(256, 0)
lngResult = objDialog.ExportDialog(lngFormHwnd, lngAppInstance, strInitDir, strFileFilter, strFileName, strTitle)
Public Function ExportDialog(lngFormHwnd As Long, lngAppInstance As Long, strInitDir As String, strFileFilter As String, strFileName As String, strTitle As String) As String
Dim Ofn As OPENFILENAME
Dim txtPosition As Integer
With Ofn
.lStructSize = Len(Ofn)
.hwndOwner = lngFormHwnd
.hInstance = lngAppInstance
.lpstrFilter = strFileFilter
.nFilterIndex = 1
.lpstrFile = strFileName
.nMaxFile = Len(Ofn.lpstrFile) - 1
.lpstrFileTitle = Ofn.lpstrFile
.nMaxFileTitle = Ofn.nMaxFile
.lpstrInitialDir = strInitDir
.lpstrTitle = strTitle
.Flags = 0
End With
If GetSaveFileName(Ofn) = 0 Then
mstrFileName = "none"
mblnStatus = False
Else
mstrFileName = Trim(Ofn.lpstrFile)
mstrFileTitle = Trim(Ofn.lpstrFileTitle)
mblnStatus = True
End If
txtPosition = InStr(RTrim(LTrim(mstrFileName)), ".txt")
If txtPosition Then
ExportDialog = RTrim(LTrim(mstrFileName))
Else
ExportDialog = RTrim(LTrim(mstrFileName)) & ".txt"
End If
End Function
I am not able to append the .txt string at the end of mstrFileName
"C:\Documents and Settings\ramakris.k\My Documents\test12367....(till total chars are 256)"
Why this chars are coming? Ltrim and Rtrim are also not working!
Thnaks and regards
Rama
the code i have is :
Dim lngFormHwnd As Long
Dim lngAppInstance As Long
Dim strInitDir As String
Dim strFileFilter As String
Dim strFileName As String
Dim lngResult As String
Dim strTitle As String
Dim mlngFileNum As Long
mlngFileNum = FreeFile
strTitle = "Save File"
strFileName = "" & String(256, 0)
lngResult = objDialog.ExportDialog(lngFormHwnd, lngAppInstance, strInitDir, strFileFilter, strFileName, strTitle)
Public Function ExportDialog(lngFormHwnd As Long, lngAppInstance As Long, strInitDir As String, strFileFilter As String, strFileName As String, strTitle As String) As String
Dim Ofn As OPENFILENAME
Dim txtPosition As Integer
With Ofn
.lStructSize = Len(Ofn)
.hwndOwner = lngFormHwnd
.hInstance = lngAppInstance
.lpstrFilter = strFileFilter
.nFilterIndex = 1
.lpstrFile = strFileName
.nMaxFile = Len(Ofn.lpstrFile) - 1
.lpstrFileTitle = Ofn.lpstrFile
.nMaxFileTitle = Ofn.nMaxFile
.lpstrInitialDir = strInitDir
.lpstrTitle = strTitle
.Flags = 0
End With
If GetSaveFileName(Ofn) = 0 Then
mstrFileName = "none"
mblnStatus = False
Else
mstrFileName = Trim(Ofn.lpstrFile)
mstrFileTitle = Trim(Ofn.lpstrFileTitle)
mblnStatus = True
End If
txtPosition = InStr(RTrim(LTrim(mstrFileName)), ".txt")
If txtPosition Then
ExportDialog = RTrim(LTrim(mstrFileName))
Else
ExportDialog = RTrim(LTrim(mstrFileName)) & ".txt"
End If
End Function
I am not able to append the .txt string at the end of mstrFileName
"C:\Documents and Settings\ramakris.k\My Documents\test12367....(till total chars are 256)"
Why this chars are coming? Ltrim and Rtrim are also not working!
Thnaks and regards
Rama