Click to See Complete Forum and Search --> : My.Setting


Blaknite
June 19th, 2006, 11:53 AM
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If CustomerDocument = "1" Then
My.Settings.InvoiceNum = My.Settings.InvoiceNum + 1
Label8.Text = "IMON"
Label10.Text = My.Settings.InvoiceNum
My.Settings.InvoiceNum = Label10.Text
Else
My.Settings.QuoteNum = My.Settings.QuoteNum + 1
Label8.Text = "QMON"
Label10.Text = My.Settings.QuoteNum
My.Settings.QuoteNum = Label10.Text
End If
End Sub

I am using VB.Net 2005. It was suggested to me to use the My.Setting
function rather than to use SaveSetting/GetSetting which I had
originally planned to use.

The problem with the code I have pasted above is this:

InvoiceNum and QuoteNum are set to 0, when I run this code it does
complete the following process: 0 + 1 = 1 and then displays "1" in
Label10 just like I want it to do.

Now I want to save the new number displayed in Label10 as the new
setting value so that I can keep adding 1 to it everytime the Form2_Load
event happens.

I was told My.Setting would autosave but this does not seem to be the
case or I am just not doing something right. Can someone please help me
fix this?

Thanks

Shuja Ali
June 20th, 2006, 05:24 AM
While creating the Setting if you have selected the Scope as Applicationt hen the Setting becomes readonly. Have you tried changing the Scope of the setting in the Project Properties to User?

Blaknite
June 20th, 2006, 03:46 PM
The scope is already user.

What is the file Settings.vb for?

should I be writing what I want do in there somehow?

It says in the prewritten comments that the file generated I can use an event called SettingsSaving. Is that what I need?


'This class allows you to handle specific events on the settings class:
' The SettingChanging event is raised before a setting's value is changed.
' The PropertyChanged event is raised after a setting's value is changed.
' The SettingsLoaded event is raised after the setting values are loaded.
' The SettingsSaving event is raised before the setting values are saved.

Partial Friend NotInheritable Class MySettings

End Class

Shuja Ali
June 21st, 2006, 02:51 AM
You shouldn't be writing anything under MySettings class unless you are going to do something extra while Saving or changing the setting.

Do you get an error while executing/building the program? If so what does the error message say?