Results 1 to 11 of 11

Thread: How to save the setting in the program?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    17
    I am here to ask how to save a setting in the program rather in a file?

    For example, I add a value, say "10" in a blank textbox, is it posible to save the value "10" in the program so that next time when started the program again, the textbox is contain value "10" and not blank? Anyone can help?

  2. #2
    Lively Member
    Join Date
    Jan 2000
    Location
    Springfield, IL
    Posts
    124
    You can use the GetSetting and the SaveSetting. This will save to the registry. There are examples in the Help or let me know and I can dig some up.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    17

    What you mean I can find it in help?

    Where is the help locate?

    Or you can just help me with giving me an example, thianks

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    What you can do is write to the registry the value of the Textbox when you close your program and read it back when you start the program again:
    Code:
    Private Sub Form_Load()
        Text1.Text = GetSettings("MyApplication", "TextboxValue", "Value", 0)
    End Sub
    
    
    Private Sub Form_Unload(Cancel As Integer)
        SaveSettings "MyApplication", "TextboxValue", "Value", Text1.Text
    End Sub

  5. #5
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    or you can save it to a file:

    Code:
    'to save
    Open "c:\myprog\settings.stn" for append as #1
    Write #1, "Hello"
    'to open
    Open "c:\myprog\settings.stn" for Input as #1
    Do Until EOF(1)
    Input #1, myString
    ListOptions.additem mystring
    Loop

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    17

    How about different settings?

    How about if I have some different seeting in a form,
    such as combination of checkboxes, comboboxes, and textboxes?

    Is it posibble for me to save the setting in a same file or have to saved it differently?


  7. #7
    Junior Member
    Join Date
    Mar 2000
    Location
    Ede, Gelderland, Nederland
    Posts
    26

    Lightbulb Better registery....

    This is also possible!

    Step 1

    Download: www.laupro.homepage.com/laupro.dll (Save target as...)

    Step 2

    Start VB, New project; And go to the menu Project; And than the submenu References

    Step 4

    Click on Browse and select LauPro.dll

    Step 5

    Add this code to a new project:

    Code:
    Option Explicit
    
    Const Reg_Key = "\Software\MyApp"
    Const Reg_Key_Caption = "Caption"
    
    Private Sub cmdGet_Click()
        Dim LPS As LPStandard
        Set LPS = New LPStandard
        
        Caption = LPS.LPGetRegValue(Reg_Key, Reg_Key_Caption, txtCaption.Text)
    End Sub
    
    Private Sub cmdSet_Click()
        Dim LPS As LPStandard
        Set LPS = New LPStandard
        
        LPS.LPSetRegValue Reg_Key, Reg_Key_Caption, txtCaption.Text
    End Sub
    Download project: www.laupro.homepage.com/reg.zip (Save target as...]
    LauPro

  8. #8

    Wink Undocumented...

    An undocumented feature of the GetSetting, SaveSetting, and DeleteSetting functions is that you can use paths. For example, to save to HKEY_LOCAL_USER\Software\VB and VBA Program Settings\MyApp\SubFolder\MiniFolder to the key "x" with a value of "2", say:
    Code:
    SaveSetting App.Title, "SubFolder\MiniFolder", "x", "2"

  9. #9
    Lively Member
    Join Date
    Jul 2000
    Location
    Brunei
    Posts
    100
    Originally posted by Serge
    What you can do is write to the registry the value of the Textbox when you close your program and read it back when you start the program again:
    Code:
    Private Sub Form_Load()
        Text1.Text = GetSettings("MyApplication", "TextboxValue", "Value", 0)
    End Sub
    
    
    Private Sub Form_Unload(Cancel As Integer)
        SaveSettings "MyApplication", "TextboxValue", "Value", Text1.Text
    End Sub
    Hi there,

    Is it possible to save the color settings of the mshflex grid control cells using the savesetting and getsetting functions?

    If yes, pls give some ideas.

    Thank you.

    Rathi

  10. #10
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Here's a little example. Add Common Dialog control and MsFlexGrid to your form:
    Code:
    Private Sub Form_Load()
        Dim intRow As Integer
        Dim intCol As Integer
        
        With MSFlexGrid1
            .Rows = 11
            .Cols = 5
            
            For intRow = 1 To .Rows - 1
                .Row = intRow
                For intCol = 0 To .Cols - 1
                    .Col = intCol
                    .Text = "Field" & intCol & intRow
                    'get saved settings for the color.
                    'if settings don't exist, then use default colors
                    .CellBackColor = GetSetting("GridDemo", "Row" & intRow, "Col" & intCol, vbWindowBackground)
                Next
            Next
        End With
        
    End Sub
    
    
    Private Sub Form_Unload(Cancel As Integer)
        Dim intRow As Integer
        Dim intCol As Integer
        
        With MSFlexGrid1
            
            For intRow = 1 To .Rows - 1
                .Row = intRow
                For intCol = 1 To .Cols - 1
                    .Col = intCol
                    SaveSetting "GridDemo", "Row" & intRow, "Col" & intCol, .CellBackColor
                Next
            Next
        End With
        
    End Sub
    
    
    Private Sub MSFlexGrid1_DblClick()
        With CommonDialog1
            .CancelError = True
            .ShowColor
            
            If Err.Number = cdlCancel Then Exit Sub
            
            MSFlexGrid1.CellBackColor = .Color
            
        End With
    End Sub
    By double clicking on any cell in the Grid will let you change it's back color. Then when you close your form, it will save color settings in the registry and use them on next Form_Load event.


    Regards,

  11. #11
    Lively Member
    Join Date
    Jul 2000
    Location
    Brunei
    Posts
    100
    Originally posted by Serge
    Here's a little example. Add Common Dialog control and MsFlexGrid to your form:
    Code:
    Private Sub Form_Load()
        Dim intRow As Integer
        Dim intCol As Integer
        
        With MSFlexGrid1
            .Rows = 11
            .Cols = 5
            
            For intRow = 1 To .Rows - 1
                .Row = intRow
                For intCol = 0 To .Cols - 1
                    .Col = intCol
                    .Text = "Field" & intCol & intRow
                    'get saved settings for the color.
                    'if settings don't exist, then use default colors
                    .CellBackColor = GetSetting("GridDemo", "Row" & intRow, "Col" & intCol, vbWindowBackground)
                Next
            Next
        End With
        
    End Sub
    
    
    Private Sub Form_Unload(Cancel As Integer)
        Dim intRow As Integer
        Dim intCol As Integer
        
        With MSFlexGrid1
            
            For intRow = 1 To .Rows - 1
                .Row = intRow
                For intCol = 1 To .Cols - 1
                    .Col = intCol
                    SaveSetting "GridDemo", "Row" & intRow, "Col" & intCol, .CellBackColor
                Next
            Next
        End With
        
    End Sub
    
    
    Private Sub MSFlexGrid1_DblClick()
        With CommonDialog1
            .CancelError = True
            .ShowColor
            
            If Err.Number = cdlCancel Then Exit Sub
            
            MSFlexGrid1.CellBackColor = .Color
            
        End With
    End Sub
    By double clicking on any cell in the Grid will let you change it's back color. Then when you close your form, it will save color settings in the registry and use them on next Form_Load event.


    Regards,

    Hi Serge,

    Thank you very much for your time and help.

    I got stuck with that problem for a couple of days. Thanks a lot.

    sincerely,
    Rathi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width