[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.
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
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:
Private Sub cmdSaveFile_Click()
Dim oCtl As Control
'
'
Open m_strFileNameLocation For Output As #m_intFF
' lblText Control Array
For Each oCtl In lblText
If oCtl.Index Then
With oCtl
Print #m_intFF, "###"
Print #m_intFF, .Name & "|" & .Index
Print #m_intFF, "BorderStyle", .BorderStyle
Print #m_intFF, "Top", .Top
'
'
End With
End If
Next oCtl
' pbShape Control Array
For Each oCtl In pbShape
If oCtl.Index Then
With oCtl
'
'
'
'
Close #m_intFF
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:
Private Sub cmdLoadFile_Click()
Dim oCtl As Control
Dim sParts() As String, sLine As String
Dim bNewCtl As Boolean
Open m_strFileNameLocation For Input As #m_intFF
Do Until EOF(m_intFF)
Line Input #m_intFF, sLine
Select Case True
Case bNewCtl
sParts = Split(sLine, "|")
If UBound(sParts) Then
Set oCtl = Me.Controls(sParts(0))(Val(sParts(1)))
Load oCtl
Else
Set oCtl = Me.Controls(sParts(0))
End If
bNewCtl = False
Case sLine = "###"
oCtl.Visible = True
Set oCtl = Nothing
bNewCtl = True
Case Len(sLine)
sParts = Split(sLine, "|")
CallByName oCtl, sParts(0), VbLet, sParts(1)
End Select
Loop
Close #m_intFF
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.
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:
Private Sub mnuLabelFontStyleBold_Click()
lblText(m_intControlIndex).Font.Bold = True
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.
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
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:
' Saving
Print #m_intFF, "Picture" & "|" & .Tag
' Loading
'
Case Len(sLine)
sParts = Split(sLine, "|")
If sLine(0) = "Picture" Then
If Len(sLine(1)) Then oCtl = LoadPicture("C:\pathtofile\" & sLine(1))
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?
' 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:
Case Len(sLine)
sParts = Split(sLine, "|")
If sLine(0) = "Picture" Then
[hl]m_strFileName = .Tag[/hl]
If Len(sLine(1)) Then oCtl = LoadPicture("[hl]m_strFileName[/hl]" & sLine(1))
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)
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
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
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.
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:
Case m_strLine = "###"
How can that ever happen if
VB Code:
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
the error messages mean nothing without the values.
1st error:
well I said
VB Code:
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