How to savesetting of all form in a textfile and gain these Savesettings again.

How to savesetting in a textfile and gain these Savesettings again.
and also tell me can i save all form setting in the registry in one line ornot please tell me
zubair007Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
To save setttings in a file like Myini.ini (as opposed to the registry):

Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long

Function Write_Profile_Info(ByVal InAppName As String, ByVal InKeyName As String, ByVal InString As String, ByVal InFileName As String) As Integer
   
    Dim x As Integer
    On Error GoTo WriteProfileInformationError

    x = WritePrivateProfileString(InAppName, InKeyName, InString, InFileName)

    Exit Function

WriteProfileInformationError:
    WriteProfileInformation = 0
    Exit Function

End Function

******* To retrieve the settings *********:


Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Function Get_Profile_Info(ByVal InAppName As String, ByVal InKeyName As String, InFileName As String) As String
    Dim ReturnedStringLength%
    Dim TempString$, Zero
        'WriteLog "Get_Profile_Info: InAppName: " & InAppName & ", InKeyName: " & InKeyName & ", InFileName: " & InFileName
    lpAppName$ = InAppName
    lpKeyName$ = InKeyName
    lpDefault$ = Space$(250)
    lpReturnedString$ = Space$(250)
    nSize% = Len(lpReturnedString$)
    lpFileName$ = InFileName
   
    ReturnedStringLength% = GetPrivateProfileString(lpAppName$, lpKeyName$, lpDefault$, lpReturnedString$, nSize%, lpFileName$)
   
    If ReturnedStringLength% = 0 Then
        Get_Profile_Info = ""
        Exit Function
    End If
    'Windows NT doesn't always return zero length when not found
    'so trim and truncate again, just in case
    TempString$ = Trim$(Left$(lpReturnedString$, ReturnedStringLength%))
    Zero = InStr(TempString$, Chr$(0))
    If Zero > 0 Then
        TempString$ = Left$(TempString$, Zero - 1)
    End If
    'WriteLog "Get_Profile_Info: Returns " & TempString$
    Get_Profile_Info = TempString$
End Function


 *********** To save and restore form settings, hook these events in each form:
Private Sub Form_Unload(Cancel As Integer)
    SaveLayout Me
End Sub

Private Sub Form_Load()
    SetMeUp Me
End Sub

******* to these procedures
Public Sub SetMeUp(Frm As Form)
Dim SaveLeft As Long
Dim SaveTop As Long
Dim UseSettings As Boolean
Const Margin = 0.05
SaveLeft = Val(GetSetting(App.Title, "Form Layouts", Frm.Name & "_Left"))
SaveTop = Val(GetSetting(App.Title, "Form Layouts", Frm.Name & "_Top"))
'check to see if form will restore within screen bounds
    If SaveLeft + Frm.Width > Screen.Width * Margin Then
        If SaveLeft < Screen.Width * (1 - Margin) Then
            If SaveTop > 0 Then
                If SaveTop < Screen.Height * (1 - Margin) Then
                    UseSettings = True
                End If
            End If
        End If
    End If
    If UseSettings Then
        Frm.Left = SaveLeft
        Frm.Top = SaveTop
        If Frm.BorderStyle = vbSizable Then
            If GetSetting(App.Title, "Form Layouts", Frm.Name & "_Height") <> "" Then
                Frm.Height = Val(GetSetting(App.Title, "Form Layouts", Frm.Name & "_Height"))
                Frm.Width = Val(GetSetting(App.Title, "Form Layouts", Frm.Name & "_Width"))
            End If
        End If
    Else
        Frm.Left = (Screen.Width - Frm.Width) / 2
        Frm.Top = (Screen.Height - Frm.Height) / 2
    End If
End Sub

Public Sub SaveLayout(Frm As Form)
    SaveSetting App.Title, "Form Layouts", Frm.Name & "_Left", "" & Frm.Left
    SaveSetting App.Title, "Form Layouts", Frm.Name & "_Top", Frm.Top
    If Frm.BorderStyle = vbSizable Then
        SaveSetting App.Title, "Form Layouts", Frm.Name & "_Height", Frm.Height
        SaveSetting App.Title, "Form Layouts", Frm.Name & "_Width", Frm.Width
    End If
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zubair007Author Commented:
no no bai jan i want to save all setting in the Mytext.txt file only for this that to avoid too much coding that is why i know this process ..........i want to use text file whose extension *.txt
0
GrahamSkanRetiredCommented:
Who's bai jan?

You don't have to use the extension *.ini. It will still work with a name like MyFile.txt.
0
CleanupPingCommented:
zubair007:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.