Page 1 of 2 12 LastLast
Results 1 to 40 of 67

Thread: [RESOLVED] saving control properties/names to text

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Resolved [RESOLVED] saving control properties/names to text

    I am attempting to save the project controls names and properties to a text file so that the end user can save their project and load it into my app at a later time if they want. I have not completed it yet but would like to know if I am going about it the right way.

    Please advise, and thanks in advance.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     FormBackColor Me
    5. End Sub
    6.  
    7. Private Sub cmdSaveFile_Click()
    8.     m_intFF = FreeFile
    9.     m_strDirectory = "Projects"
    10.     m_SaveProjectFileName = txtFileName.Text
    11.     m_strSDPROJFileName = m_SaveProjectFileName & ".sdproj"
    12.     m_strFileNameLocation = App.Path & "\" & m_strDirectory & "\" & m_strSDPROJFileName
    13.    
    14.     If Len(Dir$(App.Path & "\" & m_strDirectory & "\", vbDirectory)) > 0 Then
    15.         'do nothing because the Projects directory exists
    16.     Else
    17.         MkDir (m_strDirectory)
    18.     End If
    19.    
    20.     'get all the controls on the form
    21.     For Each m_Ctrl In frmMain.Controls
    22.         'if all the controls are a label and they are visible then
    23.         If m_Ctrl Is Label And m_Ctrl.Visible Then
    24.             'lets see how many labels are on the form
    25.             m_intControlCountLBLTEXT = frmMain.lblText.Count
    26.             'now that we have the amounts, lets get the properties of those controls
    27.             'in the control array
    28.             For m_intIndex = 1 To m_intControlCountLBLTEXT
    29.                 With frmMain.lblText(m_intIndex)
    30.                     m_lngBorderStyle = .BorderStyle
    31.                     m_lngTop = .Top
    32.                     m_lngLeft = .Left
    33.                     m_lngHeight = .Height
    34.                     m_lngWidth = .Width
    35.                     m_lngAppearance = .Appearance
    36.                     m_lngBorderStyle = .BorderStyle
    37.                     m_lngBackStyle = .BackStyle
    38.                     m_strCaption = .Caption
    39.                 End If
    40.             Next m_intIndex
    41.         'if all the controls are pictureboxes and they are called
    42.         'pbShape(Index) and are visible then
    43.         ElseIf m_Ctrl Is PictureBox And m_Ctrl.Name = "pbShape" Then
    44.             'lets see how many pictureboxes called pbShape are present
    45.             m_intControlCountPB = frmMain.pb.Count
    46.             'now that we have the amounts, lets get the properties of those controls
    47.             'in the control array
    48.            
    49.         'if all the controls are pictureboxes and they are called
    50.         'pb(Index) and are visible then
    51.         ElseIf m_Ctrl Is PictureBox And m_Ctrl.Name = "pb" Then
    52.             'lets see how many pictureboxes called pb are present
    53.             m_intControlCountPBSHAPE = frmMain.pbShape.Count
    54.             'now that we have the amounts, lets get the properties of those controls
    55.             'in the control array
    56.            
    57.         'now lets get the work area
    58.         ElseIf m_Ctrl Is PictureBox And m_Ctrl.Name = "pbWorkArea" Then
    59.             'should only be one
    60.             m_intControlCountWORKAREA = frmMain.pbWorkArea.Count
    61.             'pbWorkArea is not in a control array so get the properties
    62.             With frmMain.pbWorkArea
    63.                 m_lngHeight = .Height
    64.                 m_lngWidth = .Width
    65.                 m_lngAppearance = .Appearance
    66.                 m_lngBorderStyle = .BorderStyle
    67.             End With
    68.         End If
    69.     Next m_Ctrl
    70.    
    71.     Open m_strFileNameLocation For Output As #m_intFF
    72.     Print #m_intFF, [PRINT THE RELEVANT INFORMATION HERE]
    73.     Close #m_intFF
    74. End Sub
    75.  
    76. Private Sub cmdCancel_Click()
    77.     Unload Me
    78. End Sub

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: saving control properties/names to text

    VB Code:
    1. If m_Ctrl Is Label And m_Ctrl.Visible Then
    2.             'lets see how many labels are on the form
    3.             m_intControlCountLBLTEXT = frmMain.lblText.Count
    4. ...
    5. With frmMain.lblText(m_intIndex)
    Only controls that are part of an array have .Count and .Index properties. You're not addressing controls that aren't part of an array.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  3. #3
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: saving control properties/names to text

    well at the moment you're looping through the controls. Every label you come to you loop through a control array - overwriting a particular set of variables - which probably isn't what you intended to do.

    With this code you want to be thinking about how you're going to be loading this information - how are you going to know what properties to assign to which controls etc.

    Since all the controls (bar-one) that you want to save are in control arrays - it might make sense to loop through those control arrays one by one. In the example below I've chosen to record the name (and index) of the control at the top and then properties underneath (the reason for this was because of the loading code):
    VB Code:
    1. Private Sub cmdSaveFile_Click()
    2.     Dim oCtl As Control
    3.     '
    4.     '
    5.     Open m_strFileNameLocation For Output As #m_intFF
    6.    
    7.         ' lblText Control Array
    8.         For Each oCtl In lblText
    9.             If oCtl.Index Then
    10.                 With oCtl
    11.                     Print #m_intFF, "###"
    12.                     Print #m_intFF, .Name & "|" & .Index
    13.                     Print #m_intFF, "BorderStyle", .BorderStyle
    14.                     Print #m_intFF, "Top", .Top
    15.                     '
    16.                     '
    17.                 End With
    18.             End If
    19.         Next oCtl
    20.        
    21.         ' pbShape Control Array
    22.         For Each oCtl In pbShape
    23.             If oCtl.Index Then
    24.                 With oCtl
    25.                     '
    26.                     '
    27.         '
    28.         '
    29.     Close #m_intFF
    30. End Sub
    Now to load those control properties I'm going to use the CallByName function which allows me to Get/Let/Set properties by knowing their names as a string:
    VB Code:
    1. Private Sub cmdLoadFile_Click()
    2.     Dim oCtl As Control
    3.     Dim sParts() As String, sLine As String
    4.     Dim bNewCtl As Boolean
    5.    
    6.     Open m_strFileNameLocation For Input As #m_intFF
    7.         Do Until EOF(m_intFF)
    8.             Line Input #m_intFF, sLine
    9.            
    10.             Select Case True
    11.                 Case bNewCtl
    12.                     sParts = Split(sLine, "|")
    13.                     If UBound(sParts) Then
    14.                         Set oCtl = Me.Controls(sParts(0))(Val(sParts(1)))
    15.                         Load oCtl
    16.                     Else
    17.                         Set oCtl = Me.Controls(sParts(0))
    18.                     End If
    19.                     bNewCtl = False
    20.                 Case sLine = "###"
    21.                     oCtl.Visible = True
    22.                     Set oCtl = Nothing
    23.                     bNewCtl = True
    24.                 Case Len(sLine)
    25.                     sParts = Split(sLine, "|")
    26.                     CallByName oCtl, sParts(0), VbLet, sParts(1)
    27.             End Select
    28.         Loop
    29.     Close #m_intFF
    30. End Sub
    Now there are many ways to approach this - so you may get other (better) suggestions - the code above is just something to think about - feel free to ask any questions.

    Also none of that code has been tested - it should work, but there may be silly errors in it.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    The following error points to the highlighted part of the code.
    Run-time error: '438':
    Object doesnt support this property or method
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     FormBackColor Me
    5. End Sub
    6.  
    7. Private Sub cmdSaveFile_Click()
    8.     m_intFF = FreeFile
    9.     m_strDirectory = "Projects"
    10.     m_strSaveProjectFileName = txtFileName.Text
    11.     m_strSDPROJFileName = m_strSaveProjectFileName & ".sdproj"
    12.     m_strFileNameLocation = App.Path & "\" & m_strDirectory & "\" & m_strSDPROJFileName
    13.    
    14.     If Len(Dir$(App.Path & "\" & m_strDirectory & "\", vbDirectory)) > 0 Then
    15.         'do nothing because the Projects directory exists
    16.     Else
    17.         MkDir (m_strDirectory)
    18.     End If
    19.    
    20.     Open m_strFileNameLocation For Output As #m_intFF
    21.         For Each m_Ctrl In frmMain.lblText
    22.             If m_Ctrl.Index Then
    23.                 With m_Ctrl
    24.                     Print #m_intFF, "###"
    25.                     Print #m_intFF, .Name & "|" & .Index
    26.                     Print #m_intFF, "BorderStyle", .BorderStyle
    27.                     Print #m_intFF, "Top", .Top
    28.                     Print #m_intFF, "Left", .Left
    29.                     Print #m_intFF, "Height", .Height
    30.                     Print #m_intFF, "Width", .Width
    31.                     Print #m_intFF, "Appearance", .Appearance
    32.                     Print #m_intFF, "BackStyle", .BackStyle
    33.                     Print #m_intFF, "Caption", .Caption
    34.                     Print #m_intFF, "Alignment", .Alignment
    35.                     [hl]Print #m_intFF, "Color", .Font.Color[/hl]
    36.                     Print #m_intFF, "Size", .Font.Size
    37.                     Print #m_intFF, "Style", .Font.Style
    38.                 End With
    39.             End If
    40.         Next m_Ctrl
    41.        
    42.         For Each m_Ctrl In frmMain.pbShape
    43.             If m_Ctrl.Index Then
    44.                 With m_Ctrl
    45.                     Print #m_intFF, "###"
    46.                     Print #m_intFF, .Name & "|" & .Index
    47.                     Print #m_intFF, "Top", .Top
    48.                     Print #m_intFF, "Left", .Left
    49.                     Print #m_intFF, "Height", .Height
    50.                     Print #m_intFF, "Width", .Width
    51.                     Print #m_intFF, "Appearance", .Appearance
    52.                     Print #m_intFF, "BorderStyle", .BorderStyle
    53.                 End With
    54.             End If
    55.     Next m_Ctrl
    56.    
    57.         For Each m_Ctrl In frmMain.pb
    58.             If m_Ctrl.Index Then
    59.                 With m_Ctrl
    60.                     Print #m_intFF, "###"
    61.                     Print #m_intFF, .Name & "|" & .Index
    62.                     Print #m_intFF, "Top", .Top
    63.                     Print #m_intFF, "Left", .Left
    64.                     Print #m_intFF, "Height", .Height
    65.                     Print #m_intFF, "Width", .Width
    66.                     Print #m_intFF, "Appearance", .Appearance
    67.                     Print #m_intFF, "BorderStyle", .BorderStyle
    68.                     Print #m_intFF, "Picture", .Picture
    69.                 End With
    70.             End If
    71.         Next m_Ctrl
    72.    
    73.     With frmMain.pbWorkArea
    74.         Print #m_intFF, "###"
    75.         Print #m_intFF, .Name
    76.         Print #m_intFF, "Top", .Top
    77.         Print #m_intFF, "Left", .Left
    78.         Print #m_intFF, "Height", .Height
    79.         Print #m_intFF, "Width", .Width
    80.         Print #m_intFF, "Picture", .Picture
    81.     End With
    82.    
    83.     Close #m_intFF
    84. End Sub
    85.  
    86. Private Sub cmdCancel_Click()
    87.     Unload Me
    88. End Sub

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    when i change .Font.Color to .ForeColor, I then get the same error on the line
    VB Code:
    1. Print #m_intFF, "Style", .Font.Style

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: saving control properties/names to text

    well Font.Color and Font.Style don't exist.

    Use:
    VB Code:
    1. Print #m_intFF, "ForeColor", .ForeColor
    2.                     Print #m_intFF, "FontSize", .FontSize
    3.                     Print #m_intFF, "FontName", .FontName
    4.                     'assuming that's what you meant by style

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    Quote Originally Posted by bushmobile
    well Font.Color and Font.Style don't exist.

    Use:
    VB Code:
    1. Print #m_intFF, "ForeColor", .ForeColor
    2.                     Print #m_intFF, "FontSize", .FontSize
    3.                     Print #m_intFF, "FontName", .FontName
    4.                     'assuming that's what you meant by style
    font style as in regular, bold, bold italic, italic etc. this is how i am using it and it works, so i tried to get the property for the text to save that too and i get the error, haha.
    VB Code:
    1. Private Sub mnuLabelFontStyleBold_Click()
    2.     lblText(m_intControlIndex).Font.Bold = True
    3. End Sub
    all the font styles are being implemented in my app (click on font in the properties window, and then i am using the setting in the "font style" box), so need to figure out which one is being used for the caption and then need to save it. so its almost there, but this is the problematic part.

  8. #8
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: saving control properties/names to text

    any changes to the Font properties, i.e. .Font.Bold are reflected in direct properties e.g. .FontBold.

    Regardless of how you're assigning them, just save the .FontBold, .FontItalic etc. properties.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    Quote Originally Posted by bushmobile
    any changes to the Font properties, i.e. .Font.Bold are reflected in direct properties e.g. .FontBold.

    Regardless of how you're assigning them, just save the .FontBold, .FontItalic etc. properties.
    but there isnt one for Bold+Italic right?

    also, I put a picturebox on my workarea, added an icon to it called icon.ico, i went to save it as a project file and this is what was written.... why is the .Picture numbers instead of the filename... will this make a difference?
    Code:
    ###
    pb|1
    Top            50 
    Left           50 
    Height         500 
    Width          500 
    Appearance     0 
    BorderStyle    0 
    Picture        133235761 
    ###
    pbWorkArea
    Top            1696 
    Left           3264 
    Height         2938 
    Width          5098 
    Picture        0

  10. #10
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: saving control properties/names to text

    no there isn't one for Bold+Italic, .FontBold = True and .FontItalic = True.

    I made a slight error in my saving code - it should be this (so that it works with the loading):
    VB Code:
    1. Print #m_intFF, .Name & "|" & .Index
    2.                     Print #m_intFF, "BorderStyle" [B]& "|" &[/B] .BorderStyle
    3.                     Print #m_intFF, "Top" [B]& "|" &[/B] .Top
    4.                     ' etc.
    Regarding the picture - vb doesn't store the path of the picture, it loads the picture into memory - so you can either attempt to store the picture in binary form - or store the filename somewhere (perhaps in the .Tag property) and load it. E.g.
    VB Code:
    1. ' Saving
    2. Print #m_intFF, "Picture" & "|" & .Tag
    3.  
    4. ' Loading
    5. '
    6. Case Len(sLine)
    7.     sParts = Split(sLine, "|")
    8.     If sLine(0) = "Picture" Then
    9.         If Len(sLine(1)) Then oCtl = LoadPicture("C:\pathtofile\" & sLine(1))
    10.     Else
    11.         CallByName oCtl, sParts(0), VbLet, sParts(1)
    12.     End If
    13. '

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    so if the picture is put into the .Tag property, then wouldnt the following need to reference the value in .Tag within the LoadPicture()?
    VB Code:
    1. If Len(sLine(1)) Then oCtl = LoadPicture("C:\pathtofile\" & sLine(1))

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    also, loading the picture into memory isnt going to be good when saving because once the end user boots down the computer, the picture is no longer in memory so then the app wouldnt know what image file to load. thats why saving the location of that file would be the best way to go about it, right?

  13. #13

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    Quote Originally Posted by bushmobile
    ' Loading
    '
    Case Len(sLine)
    sParts = Split(sLine, "|")
    If sLine(0) = "Picture" Then
    If Len(sLine(1)) Then oCtl = LoadPicture("C:\pathtofile\" & sLine(1))
    Else
    CallByName oCtl, sParts(0), VbLet, sParts(1)
    End If
    '[/Highlight]
    maybe do something like this?
    VB Code:
    1. Case Len(sLine)
    2.     sParts = Split(sLine, "|")
    3.     If sLine(0) = "Picture" Then
    4.         [hl]m_strFileName = .Tag[/hl]
    5.         If Len(sLine(1)) Then oCtl = LoadPicture("[hl]m_strFileName[/hl]" & sLine(1))
    6.     Else
    7.         CallByName oCtl, sParts(0), VbLet, sParts(1)
    8.     End If

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    VB Code:
    1. Print #m_intFF, "Picture" & "|" & .Tag
    when i save the project file, the picture location isnt saved to the file.
    this is what the file looks like: (pb(1) should have a picture assigned and doesnt)
    Code:
    ###
    pb|1
    Top|50
    Left|50
    Height|500
    Width|500
    Appearance|0
    BorderStyle|0
    Picture|
    ###
    pbWorkArea
    Top|1696
    Left|3264
    Height|2938
    Width|5098
    Picture|

  15. #15
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: saving control properties/names to text

    rather than try to explain what i meant out of context, I've put together an example.

    The SaveControls, LoadControls and the second half of the picArr_MouseDown sub are the important ones.

    Attached Files Attached Files

  16. #16

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    I am getting the following error on the highlighted part:
    Run-time error '52':
    Bad file name or number
    VB Code:
    1. Private Sub cmdOpenFile_Click()
    2.     m_strFileName = txtFileName.Text 'full path to the .sdproj file
    3.    
    4.     [hl]Open m_strFileName For Input As #m_intFF[/hl]
    5.         Do Until EOF(m_intFF)
    6.             Line Input #m_intFF, m_strLine
    7.            
    8.             Select Case True
    9.                 Case m_blnNewControl
    10.                     m_strParts = Split(m_strLine, "|")
    11.                         If UBound(m_strParts) Then
    12.                             Set m_Ctrl = frmMain.Controls(m_strParts(0))(Val(m_strParts(1)))
    13.                             Load m_Ctrl
    14.                             m_Ctrl.Container = frmMain.pbWorkArea
    15.                         Else
    16.                             Set m_Ctrl = frmMain.Controls(m_strParts(0))
    17.                         End If
    18.                        
    19.                         m_blnNewControl = False
    20.                     Case m_strLine = "###"
    21.                         If Not m_Ctrl Is Nothing Then m_Ctrl.Visible = True
    22.                         m_Ctrl.Container = frmMain.pbWorkArea
    23.                         Set m_Ctrl = Nothing
    24.                         m_blnNewControl = True
    25.                     Case Len(m_strLine)
    26.                         m_strParts = Split(m_strLine, "|")
    27.                             If m_strParts(0) = "Picure" Then
    28.                                 If Len(m_strParts(1)) Then
    29.                                     m_Ctrl.Picture = LoadPicture(App.Path & "\Files\" & m_strParts(1))
    30.                                     FileCopy App.Path & "\Files\" & m_strParts(1), _
    31.                                              App.Path & "\Temp\" & m_strParts(1)
    32.                                     m_Ctrl.Tag = m_strParts(1)
    33.                                 End If
    34.                             Else
    35.                                 CallByName m_Ctrl, m_strParts(0), VbLet, m_strParts(1)
    36.                             End If
    37.                         End Select
    38.                     Loop
    39.                 Close #m_intFF
    40.             If Not m_Ctrl Is Nothing Then m_Ctrl.Visible = True
    41. End Sub

  17. #17
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: saving control properties/names to text

    What were the values of m_strFileName and m_intFF when the program stopped?
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  18. #18

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    Quote Originally Posted by Al42
    What were the values of m_strFileName and m_intFF when the program stopped?
    m_strFileName shows the complete path to the file and
    VB Code:
    1. Do Until EOF(m_intFF)
    has a value of zero (m_intFF)
    As #m_intFF didnt show any value in the popup thingy
    m_blnNewControl shows as False and m_strLine shows as ""

  19. #19
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: saving control properties/names to text

    you probably just need a
    VB Code:
    1. m_intFF = FreeFile
    2.     Open m_strFileName For Input As #m_intFF
    you should really keep things that are only going to be used in the Sub local to the sub.

  20. #20
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: saving control properties/names to text

    Quote Originally Posted by bushmobile
    you probably just need a
    VB Code:
    1. m_intFF = FreeFile
    2.     Open m_strFileName For Input As #m_intFF
    That's what I was thinking - either the number or the name was empty.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  21. #21

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    Quote Originally Posted by Al42
    That's what I was thinking - either the number or the name was empty.
    yeah, forgot to set the variable as a free file. now getting an error 91 (object variable or with block variable not set)
    VB Code:
    1. Private Sub cmdOpenFile_Click()
    2.     m_intFF = FreeFile
    3.    
    4.     m_strFileName = txtFileName.Text 'full path to the .sdproj file
    5.    
    6.     Open m_strFileName For Input As #m_intFF
    7.         Do Until EOF(m_intFF)
    8.             Line Input #m_intFF, m_strLine
    9.            
    10.             Select Case True
    11.                 Case m_blnNewControl
    12.                     m_strParts = Split(m_strLine, "|")
    13.                         If UBound(m_strParts) Then
    14.                             Set m_Ctrl = frmMain.Controls(m_strParts(0))(Val(m_strParts(1)))
    15.                             Load m_Ctrl
    16.                             m_Ctrl.Container = frmMain.pbWorkArea
    17.                         Else
    18.                             Set m_Ctrl = frmMain.Controls(m_strParts(0))
    19.                         End If
    20.                        
    21.                         m_blnNewControl = False
    22.                     Case m_strLine = "###"
    23.                         If Not m_Ctrl Is Nothing Then m_Ctrl.Visible = True
    24.                         [hl]m_Ctrl.Container = frmMain.pbWorkArea[/hl]
    25.                         Set m_Ctrl = Nothing
    26.                         m_blnNewControl = True
    27.                     Case Len(m_strLine)
    28.                         m_strParts = Split(m_strLine, "|")
    29.                             If m_strParts(0) = "Picure" Then
    30.                                 If Len(m_strParts(1)) Then
    31.                                     m_Ctrl.Picture = LoadPicture(App.Path & "\Files\" & m_strParts(1))
    32.                                     FileCopy App.Path & "\Files\" & m_strParts(1), _
    33.                                              App.Path & "\Temp\" & m_strParts(1)
    34.                                     m_Ctrl.Tag = m_strParts(1)
    35.                                 End If
    36.                             Else
    37.                                 CallByName m_Ctrl, m_strParts(0), VbLet, m_strParts(1)
    38.                             End If
    39.                         End Select
    40.                     Loop
    41.                 Close #m_intFF
    42.             If Not m_Ctrl Is Nothing Then m_Ctrl.Visible = True
    43.            
    44.             With frmMain
    45.                 .lblText(.lblText.UBound).Visible = True
    46.                 .pb(.pb.UBound).Visible = True
    47.                 .pbShape(.pbShape.UBound).Visible = True
    48.             End With
    49. End Sub
    but im thinking now that the highlighted part isnt needed right?

  22. #22

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    when i comment out the highlighted part in the post above, im getting an "invalid procedure call or argument" error on the following
    VB Code:
    1. If UBound(m_strParts) Then
    2.                             Set m_Ctrl = frmMain.Controls(m_strParts(0))(Val(m_strParts(1)))
    3.                             Load m_Ctrl
    4.                             [hl]m_Ctrl.Container = frmMain.pbWorkArea[/hl]
    5.                         Else

  23. #23

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    forgot to "set" the container, and when i did, i then go the error 91 problem again

  24. #24

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    getting a subscript out of range error on the current code which is:
    VB Code:
    1. Private Sub cmdOpenFile_Click()
    2.     m_intFF = FreeFile
    3.    
    4.     m_strFileName = txtFileName.Text 'full path to the .sdproj file
    5.    
    6.     Open m_strFileName For Input As #m_intFF
    7.         Do Until EOF(m_intFF)
    8.             Line Input #m_intFF, m_strLine
    9.            
    10.             Select Case True
    11.                 Case m_blnNewControl
    12.                     m_strParts = Split(m_strLine, "|")
    13.                         If UBound(m_strParts) Then
    14.                             Set m_Ctrl = frmMain.Controls(m_strParts(0))(Val(m_strParts(1)))
    15.                             Load m_Ctrl
    16.                             Set m_Ctrl.Container = frmMain.pbWorkArea
    17.                         Else
    18.                             Set m_Ctrl = frmMain.Controls(m_strParts(0))
    19.                         End If
    20.                        
    21.                         m_blnNewControl = False
    22.                     Case m_strLine = "###"
    23.                         If Not m_Ctrl Is Nothing Then m_Ctrl.Visible = True
    24.                         'Set m_Ctrl.Container = frmMain.pbWorkArea
    25.                         Set m_Ctrl = Nothing
    26.                         m_blnNewControl = True
    27.                     Case Len(m_strLine)
    28.                         m_strParts = Split(m_strLine, "|")
    29.                             If m_strParts(0) = "Picure" Then
    30.                                 If Len(m_strParts(1)) Then
    31.                                     m_Ctrl.Picture = LoadPicture(App.Path & "\Files\" & m_strParts(1))
    32.                                     FileCopy App.Path & "\Files\" & m_strParts(1), _
    33.                                              App.Path & "\Temp\" & m_strParts(1)
    34.                                     m_Ctrl.Tag = m_strParts(1)
    35.                                 End If
    36.                             Else
    37.                                 [hl]CallByName m_Ctrl, m_strParts(0), VbLet, m_strParts(1)[/hl]
    38.                             End If
    39.                         End Select
    40.                     Loop
    41.                 Close #m_intFF
    42.             If Not m_Ctrl Is Nothing Then m_Ctrl.Visible = True
    43.            
    44.             With frmMain
    45.                 .lblText(.lblText.UBound).Visible = True
    46.                 .pb(.pb.UBound).Visible = True
    47.                 .pbShape(.pbShape.UBound).Visible = True
    48.             End With
    49. End Sub

  25. #25
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: saving control properties/names to text

    yes wrong place

    yes use set

    step through your code and check what's happening, what's the value of m_strLine for instance.

  26. #26

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    Quote Originally Posted by bushmobile
    yes wrong place

    yes use set

    step through your code and check what's happening, what's the value of m_strLine for instance.
    m_strLine shows the address that a user can save to a different file and then include in the caption of a label for a text element. m_strLine shows everything after the first line of the address. thats definately the cause. When you save the file, this is what it looks like (for some reason)

    also, there should be a picture assigned to the workarea but its not showing up in the project file. but the part that its not including, is highlighted.
    Code:
    ###
    lblText|1
    BorderStyle|0
    Top|50
    Left|50
    Height|2630
    Width|2705
    Appearance|0
    BackStyle|0
    Caption|123 Avenue
    City, State Zip
    USA
    
    Alignment|2
    Color|255
    Size|9.75
    FontBold|True
    FontItalic|False
    Strikethrough|False
    Underline|False
    FontName|MS Sans Serif
    ###
    pbWorkArea
    Top|1696
    Left|3264
    Height|2938
    Width|5098
    Picture|
    The address is inputted by the end user into a multiline textbox, its then saved to a file called UserAddress.dat. then when a user right clicks on the label and the popup menu comes up, the user can then insert that address into the selected label caption.

  27. #27
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: saving control properties/names to text

    Quote Originally Posted by bushmobile
    what's the value of m_strLine for instance.
    Quote Originally Posted by BrailleSchool
    m_strLine shows the address that a user can save ...
    The value of m_strLine? Also LBound(m_strParts) and UBound(m_strParts)?
    VB Code:
    1. Case m_strLine = "###"
    How can that ever happen if
    VB Code:
    1. m_strParts = Split(m_strLine, "|")
    can happen?
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  28. #28
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: saving control properties/names to text

    ok, to solve the subscript out of range:
    VB Code:
    1. ' Save code:
    2. Print #m_intFF, "Caption" & "|" & Replace(.Caption, vbCr, vbNullString)
    3.  
    4. ' Load code:
    5. ' Try this:
    6.     CallByName m_Ctrl, m_strParts(0), VbLet, Replace(m_strParts(1), vbLf, vbCrLf)
    7.  
    8. ' if that didn't work then do this:
    9. Else
    10.     If m_strParts(0) = "Caption" Then m_strParts(1) = Replace(m_strParts(1), vbLf, vbCrLf)
    11.     CallByName m_Ctrl, m_strParts(0), VbLet, m_strParts(1)
    12. End If

  29. #29

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    "subscript out of range"
    VB Code:
    1. [hl]If m_strParts(1) = "Caption" Then[/hl]
    2.                                     m_strParts(1) = Replace(m_strParts(1), vbLf, vbCrLf)
    3.                                     CallByName m_Ctrl, m_strParts(0), VbLet, m_strParts(1)

  30. #30

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    object doesnt support property or method
    VB Code:
    1. Private Sub cmdOpenFile_Click()
    2.     m_intFF = FreeFile
    3.     m_strFileName = txtFileName.Text 'full path to the .sdproj file
    4.    
    5.     Open m_strFileName For Input As #m_intFF
    6.         Do Until EOF(m_intFF)
    7.             Line Input #m_intFF, m_strLine
    8.            
    9.             Select Case True
    10.                 Case m_blnNewControl
    11.                     m_strParts = Split(m_strLine, "|")
    12.                         If UBound(m_strParts) Then
    13.                             Set m_Ctrl = frmMain.Controls(m_strParts(0))(Val(m_strParts(1)))
    14.                             Load m_Ctrl
    15.                             Set m_Ctrl.Container = frmMain.pbWorkArea
    16.                         Else
    17.                             Set m_Ctrl = frmMain.Controls(m_strParts(0))
    18.                         End If
    19.                        
    20.                         m_blnNewControl = False
    21.                     Case m_strLine = "###"
    22.                         If Not m_Ctrl Is Nothing Then m_Ctrl.Visible = True
    23.                         'Set m_Ctrl.Container = frmMain.pbWorkArea
    24.                         Set m_Ctrl = Nothing
    25.                         m_blnNewControl = True
    26.                     Case Len(m_strLine)
    27.                         m_strParts = Split(m_strLine, "|")
    28.                             If m_strParts(0) = "Picure" Then
    29.                                 If Len(m_strParts(1)) Then
    30.                                     m_Ctrl.Picture = LoadPicture(App.Path & "\Files\" & m_strParts(1))
    31.                                     FileCopy App.Path & "\Files\" & m_strParts(1), _
    32.                                              App.Path & "\Temp\" & m_strParts(1)
    33.                                     m_Ctrl.Tag = m_strParts(1)
    34.                                 End If
    35.                             Else
    36.                                 If m_strParts(1) = "Caption" Then m_strParts(1) = Replace(m_strParts(1), vbLf, vbCrLf)
    37.                                     [hl]CallByName m_Ctrl, m_strParts(0), VbLet, m_strParts(1)[/hl]
    38.                             End If
    39.                         End Select
    40.                     Loop
    41.                 Close #m_intFF
    42.             If Not m_Ctrl Is Nothing Then m_Ctrl.Visible = True
    43.            
    44.             With frmMain
    45.                 .lblText(.lblText.UBound).Visible = True
    46.                 .pb(.pb.UBound).Visible = True
    47.                 .pbShape(.pbShape.UBound).Visible = True
    48.             End With
    49. End Sub

  31. #31
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: saving control properties/names to text

    the error messages mean nothing without the values.

    1st error:
    well I said
    VB Code:
    1. If m_strParts[B](0)[/B] = "Caption" Then
    but it would have errored anyway. Can't say anything without values - presumably it's because of the multiline thing again but I don't know. The replacing of vbCr with vbNullstring should have solved that problem. According to my test

    Test code:
    VB Code:
    1. Private Sub Form_Load()
    2.     Dim s As String
    3.      
    4.     s = "This is" & vbCrLf & "a test"
    5.    
    6.     Open "C:\CRTest.txt" For Output As #1
    7.         Print #1, Replace(s, vbCr, vbNullString)
    8.         Print #1, "Next Line";
    9.     Close #1
    10.    
    11.     s = vbNullString
    12.    
    13.     Open "C:\CRTest.txt" For Input As #1
    14.         Do Until EOF(1)
    15.             Line Input #1, s
    16.             Debug.Print Replace(s, vbLf, vbCrLf)
    17.         Loop
    18.     Close #1
    19. End Sub
    2nd error
    Need values

  32. #32

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    VB Code:
    1. CallByName m_Ctrl, m_strParts(0), VbLet, m_strParts(1)

    values:
    m_Ctrl = ""
    m_strParts(0) = BorderStyle
    vbLet = 4
    m_strParts(1) = 0

  33. #33

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    when i saved the new project file, the txt file shows how it was saved.
    Attached Files Attached Files

  34. #34
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: saving control properties/names to text

    i don't see why you would get that error (i assume we're talking about the 'object doesnt support property or method' one).

    what do you get if you type
    Code:
    ?m_Ctrl.Name
    in the immediate window when the error occurs

  35. #35

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    Quote Originally Posted by bushmobile
    i don't see why you would get that error (i assume we're talking about the 'object doesnt support property or method' one).

    what do you get if you type
    Code:
    ?m_Ctrl.Name
    in the immediate window when the error occurs
    yes, and the value returned in the immediate window is lblText

  36. #36
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: saving control properties/names to text

    i can't think of any reason why it shouldn't work - all the values seem to be correct

  37. #37

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    Quote Originally Posted by bushmobile
    i can't think of any reason why it shouldn't work - all the values seem to be correct
    i have no clue either... all this stuff is pretty new to me so you know more than i do, of course

  38. #38

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    i have created a video for ya, and now the debug is showing something totally different, weird.
    http://www.brailleschool.com/vbf/prj.html

  39. #39
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: saving control properties/names to text

    upload that file that you opened in the vid

  40. #40

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: saving control properties/names to text

    Quote Originally Posted by bushmobile
    upload that file that you opened in the vid
    which file? the file called False? i dont know even know how that was created. its probably an old file.

Page 1 of 2 12 LastLast

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