保存和加载数据的简单方法 Visual Basic [英] Simple way to save and load data Visual Basic

查看:35
本文介绍了保存和加载数据的简单方法 Visual Basic的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在 vb 中通过不同形式保存和加载数据的最简单方法是什么.我只想保存用户保存的 3 个 textbox.text 并能够将其加载到不同的表单上.

I was wondering what is the easiest way to save and load data through different forms in vb. I just want to save 3 textbox.text that a user saves and be able to load it on a different form.

推荐答案

最简单的选择是将它们保存到一个简单的分隔文本文件中.例如,这会将值保存在以竖线分隔的文件中:

The simplest option would be to save them to a simple delimited text file. For instance, this would save the values in a pipe-delimited file:

File.WriteAllText("C:Data.txt", String.Join("|", new String() {TextBox1.Text, TextBox2.Text, TextBox3.Text}))

这会读到:

Dim values() as String = File.ReadAllText("C:Data.txt").Split("|"c)
TextBox1.Text = values(0)
TextBox2.Text = values(1)
TextBox3.Text = values(2)

但是,保存到根目录中的文件并不明智.最安全的做法是将其存储在独立存储中的文件中.此外,将其存储在 XML 中会更好.这可以通过序列化轻松完成.

However, it's not smart to save to a file in the root directory. The safest thing would be to store it in a file in Isolated Storage. Also, it would be even better to store it in XML. This could be easily done with serialization.

这篇关于保存和加载数据的简单方法 Visual Basic的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆