Results 1 to 21 of 21

Thread: A big issue with saving Textboxes position

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2016
    Posts
    753

    A big issue with saving Textboxes position

    Hello VbForums community
    I'm saving my textboxes left , top, width and height properties in an ini file.
    From time to time everything gets collapsed.
    The textboxes are shrinked and become 0 Left.
    My textboxes are inside a picturebox.
    My original textboxes:
    Name:  pic1.png
Views: 332
Size:  2.2 KB

    After the collapse
    Name:  pic2.png
Views: 318
Size:  2.1 KB
    in IDE (to illustrate)

    Please Have you ever exprienced this?

  2. #2
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: A big issue with saving Textboxes position

    I don't think that anybody can answer this.
    Please post a sample program that has the problem to examine what could be happening.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2016
    Posts
    753

    Re: A big issue with saving Textboxes position

    Thank you for replying
    This is what I'm doing:
    Code:
    Public Function WriteToAppINI(strSection As String, strKeyName As String, strValue As String, strFile As String) As Long
    Dim intStatus As Long
    On Error GoTo PROC_ERR
    intStatus = WritePrivateProfileString(strSection, strKeyName, strValue, strFile)
    WriteToAppINI = (intStatus <> 0)
    
    PROC_EXIT:
    Exit Function
      
    PROC_ERR:
    MsgBox "Error: " & Err.Number & "   " & Err.Description, , "WriteToAppINI"
    Resume PROC_EXIT
    End Function
    Code:
    Public Function ReadFromAppINI(SectionHeader As String, VarName As String, ByVal Default As String, strFile As String) As String
    Dim RetStr As String
    RetStr = String(255, Chr(0))
    ReadFromAppINI = Left(RetStr, GetPrivateProfileString(SectionHeader, ByVal VarName$, Default, RetStr, Len(RetStr), strFile))
    End Function

    Code:
    For Each ctl In Valdation_frm.Controls
    If TypeOf ctl Is TextBox Then
    Dim RetVal As Long
      RetVal = WriteToAppINI(Me.Name & "Positions", ctl.Name & " width", CStr(ctl.Width), DataFolder & "\AppSetting.ini")
      RetVal = WriteToAppINI(Me.Name & "Positions", ctl.Name & " height", CStr(ctl.Height), DataFolder & "\AppSetting.ini")
      RetVal = WriteToAppINI(Me.Name & "Positions", ctl.Name & " left", CStr(ctl.Left), DataFolder & "\AppSetting.ini")
      RetVal = WriteToAppINI(Me.Name & "Positions", ctl.Name & " top", CStr(ctl.Top), DataFolder & "\AppSetting.ini")
    End if 
    Next
    Code:
    For Each ctl In Valdation_frm.Controls
    If TypeOf ctl Is TextBox Then
    Dim RetVal As Long
    ctl.Width = ReadFromAppINI(Me.Name & "Positions", ctl.Name & " Width", ctl.Width, DataFolder & "\AppSetting.ini")
    ctl.Height = ReadFromAppINI(Me.Name & "Positions", ctl.Name & " height", ctl.Height, DataFolder & "\AppSetting.ini")
    ctl.Left = ReadFromAppINI(Me.Name & "Positions", ctl.Name & " Left", ctl.Left, DataFolder & "\AppSetting.ini")
    ctl.Top = ReadFromAppINI(Me.Name & "Positions", ctl.Name & " Top", ctl.Top, DataFolder & "\AppSetting.ini")
    End if 
    Next

  4. #4
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: A big issue with saving Textboxes position

    Ok. How often does the problem occur?

    Are you able to make it happen or does it happen rarely and you cannot know when is it going to happen?

    I would put some stop points in the code to start investigating what could be happening:

    Code:
    Public Function WriteToAppINI(strSection As String, strKeyName As String, strValue As String, strFile As String) As Long
    Dim intStatus As Long
    On Error GoTo PROC_ERR
    If Val(strValue) = 0 Then Stop
    intStatus = WritePrivateProfileString(strSection, strKeyName, strValue, strFile)
    WriteToAppINI = (intStatus <> 0)
    
    PROC_EXIT:
    Exit Function
      
    PROC_ERR:
    MsgBox "Error: " & Err.Number & "   " & Err.Description, , "WriteToAppINI"
    Resume PROC_EXIT
    End Function
    Code:
    Public Function ReadFromAppINI(SectionHeader As String, VarName As String, ByVal Default As String, strFile As String) As String
    Dim RetStr As String
    RetStr = String(255, Chr(0))
    ReadFromAppINI = Left(RetStr, GetPrivateProfileString(SectionHeader, ByVal VarName$, Default, RetStr, Len(RetStr), strFile))
    If Val(ReadFromAppINI) = 0 Then Stop
    End Function
    Only the Left of the controls is set to 0, not the Top or other properties?

  5. #5
    Addicted Member
    Join Date
    Jun 2018
    Posts
    189

    Re: A big issue with saving Textboxes position

    It's not possible to reproduce your problem based on your code
    Check the attachment and see whether you can reproduce the problem with it.
    Attached Files Attached Files

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2016
    Posts
    753

    Re: A big issue with saving Textboxes position

    Thank you Eduardo- for the help
    Are you able to make it happen or does it happen rarely and you cannot know when is it going to happen?
    It happens rarely and I cannot know when it is going to happen.

    Only the Left of the controls is set to 0, not the Top or other properties?
    Yes, only the left proprtty.
    Thanks

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2016
    Posts
    753

    Re: A big issue with saving Textboxes position

    PGBSoft
    thank you for the interest and thank you for the sample
    I tested the sample and everything is perfect.
    Is there any change in your codes?
    thank you

  8. #8
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: A big issue with saving Textboxes position

    Quote Originally Posted by Mustaphi View Post
    It happens rarely and I cannot know when it is going to happen.
    But how much "rarely"?

    If you run the program 20 times, is it probably that it will show the problem once?
    Or would it be 100 times, or 1000 times...

    Or does it seem to depend on some unknown factor and one day it could do it three times consecutive and then not to do it for several days?

    Also, the problem does occur in only one machine or in several ones?

    How many times did you see it?

  9. #9
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,046

    Re: A big issue with saving Textboxes position

    Quote Originally Posted by Mustaphi View Post
    Hello VbForums community
    I'm saving my textboxes left , top, width and height properties in an ini file.
    From time to time everything gets collapsed.
    The textboxes are shrinked and become 0 Left.
    My textboxes are inside a picturebox.
    why do you save the Settings ?

    you have a Form_Load and Resize

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  10. #10
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: A big issue with saving Textboxes position

    I would suggest that when you encounter this problem take a look at the ini file with notepad and see if you have a 0 written to the file. If you do then look at the point where you write to the ini file, if the value is no 0 in the ini file then check the part that reads and sets the positions.

    What ever is going on it pretty much has to be either your read, your write or your position assignments.

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2016
    Posts
    753

    Re: A big issue with saving Textboxes position

    Eduardo
    Thanks again
    It is exactly as you described.
    it seems to depend on some unknown factor and one day it could do it three times consecutive and then not to do it for several days
    The problem occurs on other machines too.
    On one pc it may occur very frequently and on another it may occur very rarely.

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2016
    Posts
    753

    Re: A big issue with saving Textboxes position

    ChrisE
    I need to move the textboxes at runtime and save the new position.

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2016
    Posts
    753

    Re: A big issue with saving Textboxes position

    DataMiser
    There is no 0 written on the ini file

  14. #14
    Addicted Member
    Join Date
    Jun 2018
    Posts
    189

    Re: A big issue with saving Textboxes position

    If you are still having the problem, this is just an idea.

    Can't you dynamically load the textboxes just like in the attached sample here?

    Changes to consider in this sample from the previous sample in #5:

    1. TextBoxes (array based) are dynamically loaded at runtime instead of design-time.
    2. The index of textboxes are saved in the ini file instead of their Names.
    3. TextBoxes are refreshed after setting their positions from the ini file.
    4. TextBoxes can be positioned at runtime.

    Name:  t2.jpg
Views: 162
Size:  30.0 KB

    1. You can move the textboxes at runtime.
    2. Close the form.
    3. Reopen

    Name:  t3.jpg
Views: 162
Size:  30.7 KB
    Attached Files Attached Files
    Last edited by PGBSoft; Aug 27th, 2018 at 07:17 AM.

  15. #15
    gibra
    Guest

    Re: A big issue with saving Textboxes position

    Quote Originally Posted by Mustaphi View Post
    There is no 0 written on the ini file
    You should public a TEST zipped project(ini file included) that reproduce the issue to discover your problem.

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2016
    Posts
    753

    Re: A big issue with saving Textboxes position

    Thanks PGBSoft
    I have been playing with your sample example for a hundred times wthout producing the error.
    It is nearly thesame thing I'm doing in my project

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2016
    Posts
    753

    Re: A big issue with saving Textboxes position

    gibra
    The attached sample of Mr PGBSoft is the same as mine.

  18. #18
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    460

    Re: A big issue with saving Textboxes position

    I've seen this happen when switching locales or users who use different decimal and digit separators

    Code:
    12.345,00 vs 12,345.00
    and one of your conversion functions may be silently failing and returning 0. I think Eduardo- is right, insert some lines like

    Code:
    If Val(strValue) = 0 Then Stop
    to prevent 0 from being applied or saved.

  19. #19
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,375

    Re: A big issue with saving Textboxes position

    I would save values only in full integer twips without decimal separator to avoid locale missinterpretations between read/write.

    e.g.
    CStr(CLng(ctl.Width))

  20. #20
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: A big issue with saving Textboxes position

    That may well be the problem.

    CStr() is locale-aware so you should not use it with data that is persisted or exchanged with another computer. Never. Use the Invariant Locale formatting instead.

    Converting back you are relying on compiler-inserted implicit coercion, which I believe is locale-blind and always uses the Invariant Locale.


    Instead you can convert numeric values to String using the old Str$() function and convert back from String using the old Val() function. These are both locale-blind.

  21. #21
    gibra
    Guest

    Re: A big issue with saving Textboxes position

    Quote Originally Posted by Mustaphi View Post
    gibra
    The attached sample of Mr PGBSoft is the same as mine.
    Then you have already solved your problem. Good.
    So you set the thread as RESOLVED.

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