首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

GetSetting与SaveSetting的有关问题

2012-01-30 
GetSetting与SaveSetting的问题 窗体中text2.text0.2,text3.text0.0015,text4.text0.05,text5.text0.1

GetSetting与SaveSetting的问题

窗体中text2.text=0.2,text3.text=0.0015,text4.text=0.05,text5.text=0.1,text6.text=0.005

Private   Sub   Form_Load()  
Text2   =   GetSetting(App.Title,   "settings ",   "text ",   s1)  
Text3   =   GetSetting(App.Title,   "settings ",   "text ",   s2)  
Text4   =   GetSetting(App.Title,   "settings ",   "text ",   s3)  
Text5   =   GetSetting(App.Title,   "settings ",   "text ",   s4)  
Text6   =   GetSetting(App.Title,   "settings ",   "text ",   s5)  
End   Sub  
Private   Sub   Form_Unload(Cancel   As   Integer)  
SaveSetting   App.Title,   "settings ",   "text ",   Text2.Text  
SaveSetting   App.Title,   "settings ",   "text ",   Text3.Text  
SaveSetting   App.Title,   "settings ",   "text ",   Text4.Text  
SaveSetting   App.Title,   "settings ",   "text ",   Text5.Text  
SaveSetting   App.Title,   "settings ",   "text ",   Text6.Text  

End   Sub  

运行程序,5个text控件并不是显示各自的内容,而是统一显示text2的内容

[解决办法]
那是当然的啦! 
你写入的都是同一个东西:看这句
SaveSetting App.Title, "settings ", "text ", 几个文本的东西都保存到最后的这个项值里了!

第一次 这个项值里保存 text2 的数据 第二次又在这个项值里写入了text3的数据 那么原来text2的数据 就被覆盖啦!

应该这样写:

Private Sub Form_Load()
Text2 = GetSetting(App.Title, "settings ", "text2 ")
Text3 = GetSetting(App.Title, "settings ", "text3 ")
Text4 = GetSetting(App.Title, "settings ", "text4 ")
Text5 = GetSetting(App.Title, "settings ", "text5 ")
Text6 = GetSetting(App.Title, "settings ", "text6 ")
End Sub
Private Sub Form_Unload(Cancel As Integer)
SaveSetting App.Title, "settings ", "text2 ", Text2.Text
SaveSetting App.Title, "settings ", "text3 ", Text3.Text
SaveSetting App.Title, "settings ", "text4 ", Text4.Text
SaveSetting App.Title, "settings ", "text5 ", Text5.Text
SaveSetting App.Title, "settings ", "text6 ", Text6.Text
End Sub

热点排行