|
-
Feb 14th, 2021, 06:54 PM
#1
Thread Starter
Lively Member
[HELP CODING BEGINNER] MAKE A BACK UP FROM A FORM AND RESTORE it later?
Hi everyone!
i am back again for your great help!
I have learn a lot thank to you! and i say you thank you indefinitely!
ok, imy problem is i have a form with several pictures, labels , numericupdown,checkbox ,etc i would like a code to make a back up from this form and a code to restore the data ( numericdown,picture,and so on...) i found on net coding but i don't manage to do what i want!
my research show me sql database but i didn' t understand the mecanism!
SO i will be very grateful for a hand!
thank you so much in advance for your answer!
Last edited by danzey; Feb 14th, 2021 at 08:05 PM.
-
Feb 14th, 2021, 11:27 PM
#2
Re: [HELP CODING BEGINNER] MAKE A BACK UP FROM A FORM AND RESTORE it later?
This really is too broad a question. You're not backing up a form. You're simply saving data. It's up to you how you want to do that: text file, serialisation, database, etc. Once you've decided on the method, then you need to research that method. It's not for us to teach you everything about databases and data access here. That's a broad topic and there's lots of information easily accessible so you need to do your research first, do what you can for yourself and then ask us when you encounter an actual issue. If you're unable to use a search engine effectively for some reason, there's a Database FAQ link in my signature below that provides links to some of the ADO.NET resources on this site.
-
Feb 16th, 2021, 03:54 PM
#3
Hyperactive Member
Re: [HELP CODING BEGINNER] MAKE A BACK UP FROM A FORM AND RESTORE it later?
danzey,
did you mean you want to make a backup from a form without any code in it just with controls? Its pretty simple. From another project just add existing item, select your desired form and you have backed it up!
As for sql, I dont have any experiences with it so I cannot comment.
Please dont forget to add good reputation if my advices were useful for you.
How? Under this post there is "RATE THIS POST" button. Click on it.
-
Feb 16th, 2021, 04:53 PM
#4
Re: [HELP CODING BEGINNER] MAKE A BACK UP FROM A FORM AND RESTORE it later?
 Originally Posted by VB.NET Developer
danzey,
did you mean you want to make a backup from a form without any code in it just with controls? Its pretty simple. From another project just add existing item, select your desired form and you have backed it up!
As for sql, I dont have any experiences with it so I cannot comment.
Looks like you’ve misunderstood the question. As JM understood it, and as I understood it, danzey is looking to save a form state, then recreate that state at a later time...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 16th, 2021, 05:45 PM
#5
Re: [HELP CODING BEGINNER] MAKE A BACK UP FROM A FORM AND RESTORE it later?
When I need to save my form data, I create a class with the appropriate properties linked to each data to save on the form, then create and instance of that class and save the instance in a xml file :
Code:
Public Sub Save_xml(ByVal my_instance As my_class)
Dim filetosave As New SaveFileDialog With { .FileName = "name" }
If filetosave.ShowDialog() = DialogResult.OK Then
Dim Filename As String = filetosave.FileName
Dim serialiseur As New XmlSerializer(GetType(my_class))
Using fs As FileStream = File.Create(Filename)
serialiseur.Serialize(fs, my_instance)
End Using
End If
End Sub
Works well with numbers and strings but I never try with a picture as I usually save the pictures as separate files
Last edited by Delaney; Feb 16th, 2021 at 05:49 PM.
The best friend of any programmer is a search engine 
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
-
Feb 18th, 2021, 03:31 PM
#6
Thread Starter
Lively Member
Re: [HELP CODING BEGINNER] MAKE A BACK UP FROM A FORM AND RESTORE it later?
 Originally Posted by Delaney
When I need to save my form data, I create a class with the appropriate properties linked to each data to save on the form, then create and instance of that class and save the instance in a xml file :
Code:
Public Sub Save_xml(ByVal my_instance As my_class)
Dim filetosave As New SaveFileDialog With { .FileName = "name" }
If filetosave.ShowDialog() = DialogResult.OK Then
Dim Filename As String = filetosave.FileName
Dim serialiseur As New XmlSerializer(GetType(my_class))
Using fs As FileStream = File.Create(Filename)
serialiseur.Serialize(fs, my_instance)
End Using
End If
End Sub
Works well with numbers and strings but I never try with a picture as I usually save the pictures as separate files
THANK all of us for your Answers , i like your idea(delaney! from france too!) but now the question is how can i restore or load in my form saved with the file xlm?
-
Feb 18th, 2021, 04:36 PM
#7
Re: [HELP CODING BEGINNER] MAKE A BACK UP FROM A FORM AND RESTORE it later?
for the importation it is the same :
Code:
Public Function importation_xml() As my_class
Dim filetoopen As New OpenFileDialog
If filetoopen.ShowDialog() = DialogResult.OK Then
Dim Filename As String = filetoopen.FileName
'open an instance of reading
Dim str As Stream = File.OpenRead(Filename)
Dim dsr As New XmlSerializer(GetType(my_class))
Return CType(dsr.Deserialize(str), my_class)
sr.Close()
Else
Return New my_class
End If
End Function
I advice you to put both importation function and save sub in the class
in your form, create a sub to load your data and call the function and link the properties of the class to the controls:
Code:
dim my_instance As new my_class ' you may want to put that at the top of the form if you need to update the data in several other sub.
my_instance= my_instance.importation_xml()
thereafter an example :
Code:
with my_instance
label_name.text=.name (and in my instance you have : property name as string)
label_age.text=.age.tostring (and in my instance you have : property age as integer)
etc.for each control you want to fill
end with
The best friend of any programmer is a search engine 
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
-
Feb 18th, 2021, 05:55 PM
#8
Re: [HELP CODING BEGINNER] MAKE A BACK UP FROM A FORM AND RESTORE it later?
@Delaney - Are you certain that you can serialize/deserialize a Form like that?
The reason I ask is because my knee jerk reaction would be that it would serialize the Form properties but would have unintended side effects when deserializing the data back, especially for controls that you want to update a non-primitive property (like PictureBox.Image).
Edit - Please do not misconstrue my question. I am not questioning your abilities as a programmer, I simply haven't serialized a Form before in a manner that you're describing. If it works, it is good to have in my back pocket.
-
Feb 18th, 2021, 07:03 PM
#9
Re: [HELP CODING BEGINNER] MAKE A BACK UP FROM A FORM AND RESTORE it later?
 Originally Posted by dday9
@Delaney - Are you certain that you can serialize/deserialize a Form like that?
The reason I ask is because my knee jerk reaction would be that it would serialize the Form properties but would have unintended side effects when deserializing the data back, especially for controls that you want to update a non-primitive property (like PictureBox.Image).
Edit - Please do not misconstrue my question. I am not questioning your abilities as a programmer, I simply haven't serialized a Form before in a manner that you're describing. If it works, it is good to have in my back pocket.
Don't worry, you have the right to question my abilities as I am an amateur, I do a lot of error of coding (I still use msgbox ) and I have still a lot to learn.
I don't serialize a form, I serialize a instance of a class I created and that contains all the information I need to use and save. I fill the data of the class with the info of the controls of the form (like textbox, label, etc.) or the reverse (fill the form textbox, label, combobox, etc. with the data from the class). For my applications, it is always strings and numbers and list (of strings or number) and other classes I created (I created a class called curve that contains a list of points, name of the curve, comment, etc. ). I never try to do it with a picturebox or a chart as I recreate the charts with my class "curve" and for the pictures, I save or export them as separate files. I can send to you some files of one of my applications if you want.
PS : now, I see the confusion I created as I was speaking of the form data in post #5. I am sorry, It is a misuse of words. By form data I mean all the information that are in the controls I put on the form (texts, etc.). In fact I same much more than that as I use the form only as a User Interface and I do every data treatment and calculus in the specific class I create for that.
Last edited by Delaney; Feb 18th, 2021 at 07:17 PM.
The best friend of any programmer is a search engine 
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|