Image of Navigational Map linked to Home / Contents / Search Save and Get Settings

by Rob Parsons - Eyecan Publishing
Image of Line Break

SaveSetting and GetSetting make writing application settings a breeze.

Here are two utility functions to retrieve and store the current form's position, just as an example.

Public Sub FormPosition_Get(F As Form)

' Retrieve Form F's position from an ini/reg file and position it accordingly

Dim buf As String
Dim l, t, h, w As Integer
Dim pos As Integer

buf = GetSetting(app.EXEName, "FormPosition", F.Tag, "")

If buf = "" Then ' default with centering the form
    F.Move (Screen.Width - F.Width) \ 2, (Screen.Height - F.Height) \ 2

Else    ' extract l,t,w,h and move form

    pos = InStr(buf, ",")
    l = CInt(Mid(buf, 1, pos - 1))
    buf = Mid(buf, pos + 1)
    pos = InStr(buf, ",")
    t = CInt(Mid(buf, 1, pos - 1))
    buf = Mid(buf, pos + 1)
    pos = InStr(buf, ",")
    w = CInt(Mid(buf, 1, pos - 1))
    h = CInt(Mid(buf, pos + 1))
    F.Move l, t, w, h
End If

End Sub

Public Sub FormPosition_Put(F As Form)

' Write forms F top,left,height and width properties to
' the reg/ini file for the application

Dim buf As String

buf = F.left & "," & & "," & F.Width & "," & F.Height
SaveSetting app.EXEName, "FormPosition", F.Tag, buf

End Sub

These utilities should be placed in a module and called from the forms load and unload events respectively. Note that you must place the name of the form in its Tag property for these utilites to work.

Sub Form_Load()

        FormPosition_Get Me

End Sub

Sub Form_Unload()

        FormPosition_Put Me

End Sub 

Written by: Rob Parsons
May '97

Image of Arrow linked to Previous Article Image of Arrow linked to Next Article
Image of Line Break