Config Creator in Visual Basic
Submitted by Yorkiebar on Tuesday, May 27, 2014 - 03:20.
Introduction:
This tutorial is on how to create a config creator in Visual Basic.
Imports:
We need to import the System.IO namespace in order to access files within the computers filesystem for saving later on...
Design:
Our design will simple consist of;
Textbox, textbox1, Hold the property name.
Textbox, textbox2, Hold the property value.
Button, button1, Add property.
Button, button2, Save config.
Variables:
To hold all the current properties to write to the config file in the near future, we will create a String list within the global scope...
Button1 Click Event:
Once button1 is clicked, we first want to ensure that both the property name and value boxes are not empty...
If they are both not nothing, we want to add the values using a delimiter of a colon (:) to separate the name from the value, to the list...
Button2 Click Event:
Once button2 is clicked, we want to allow the user to set a save destination through a new SaveFileDialog browser box, then use a new StreamWriter to write each property held within our 'props' list variable/object to the new config file...
- Imports System.IO
- Dim props As New List(Of String)
- If (Not TextBox1.Text = Nothing And Not TextBox2.Text = Nothing) Then
- Else
- End If
- props.Add(TextBox1.Text + ":" + TextBox2.Text)
- If (props.Count() > 0) Then
- Using fo As New OpenFileDialog
- fo.MultiSelect = False
- fo.RestoreDirectory = True
- fo.ShowDialog()
- If (fo.FileName = Nothing) Then
- MsgBox("That config name is not valid.")
- Else
- Using sw As New StreamWriter(fo.FileName)
- For Each prop As String In props
- sw.WriteLine(prop)
- Next
- End Using
- End If
- End Using
- End If
Add new comment
- 8 views