Archive for October, 2008

VB.NET My.Settings

Want to store some user settings in vb.net?This could be used for any number of things, I used this to store the length of a barcode that was being read from a text file, the user could change the default of 12 to any custom value:

 

Open My Project / Settings
Name = message
Type = integer
Scope = user
Value = 10

Add this code below our Public Class:

Public Sub New()
‘ This call is required by the Windows Form Designer.
InitializeComponent()

End Sub
On you form load add (to display the value):
Try

txtbox1.text = My.Settings.message

Catch ex AsException

MsgBox(ex.Message)

End Try
 

To Update the setting(put this on a button, reads new value from textbox):

Try
My.Settings.message = CInt(txtNewValue.Text)
My.Settings.Save()
My.Settings.Reload()
Msgbox(”New Setting Saved.”)

Catch ex As Exception

MsgBox(ex.Message)

End Try

VB.net Create file name from date

The following code will produce a unique text file name:

 _____________________________________________________________
 Dim FileTime As Long = DateTime.Now.ToFileTime() 

 Dim FILENAME = “Log-” & FileTime & “.txt”

 ___________________________________________________________
Usefule for creating a uniqye file name for a program log