• We just launched and are currently in beta. Join us as we build and grow the community.

Advertise Here

Advertise Here

Advertise Here

How To Use Project Settings in Visual Basic

skyblockgod

Coder Extraordinaire
S Rep
0
0
0
Rep
0
S Vouches
0
0
0
Vouches
0
Posts
103
Likes
82
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
Introduction:
This tutorial is on how to use Settings in Visual Basic.

Settings:
Project Settings in Visual Basic project solutions are simple ways to carry data over from one running instance of the application to another. Instead of variables and objects where the data gets cleared once the process is stopped or files which holding data between running processes which can be accessed by the users of the machine, project settings are unique to the application and stored permanently until modified within the application itself (or an attached process).

Creating Settings:
We are going to create an example setting name 'user' to hold the fake username of the logged in user to the application.

So first we must create the setting. To do this, open your Visual Studio/Basic application project solution, then go to the following...
'Solution Explorer', right click on '{Your Project Name}', then go to 'Properties'.

Now, enter a string (the setting/variable/object name) in the 'Name' column of the 'Settings' tab. Set the type to the appropriate type (for this setting it is already a String, so don't interact with the first dropdown box column 'Type'), leave the 'Scope' as 'User' and you may set a default 'Value' if you wish. Save the settings using Ctrl + S keyboard shortcut.

Reading Settings:
To read a setting from within the application, we simple type...

  1. My.Settings.{Name}

So to output our 'User' setting, we type...

  1. MsgBox(My.Settings.User)

Modifying Settings:
To modify the value of a setting we use the same code as reading it, except with an assignment operator ('=') and a new value following the operator, like so...

  1. My.Settings.{Name} = {New

    Value}

So to change the 'User' Setting value to 'Yorkiebar', we would type...

  1. My.Settings.User = "Yorkiebar"

 

452,496

343,269

343,277

Top