Visual Basic

From IT Wiki
Jump to navigation Jump to search

Visual Basic, originally called Visual Basic .NET (VB.NET), is a multi-paradigm, object-oriented programming language, implemented on .NET, Mono, and the .NET Framework. Microsoft launched VB.NET in 2002 as the successor to its original Visual Basic language, the last version of which was Visual Basic 6.0. Although the ".NET" portion of the name was dropped in 2005, "Visual Basic [.NET]" is often used to refer to all Visual Basic languages released since 2002, in order to distinguish between them and the classic Visual Basic.

Comment blocks

In Visual Studio you can use the keyboard shortcuts that will comment/uncomment the selected lines for you:

  • Ctrl + K + C to comment
  • Ctrl + K + U to uncomment

Reset settings

For Visual Studio 2013, to reset the settings for Visual Studio go to Windows > Programs > Visual Studio 2013 > Visual Studio Tools.

In the File Explorer window that opens, choose Developer Command Prompt for VS2013.

Then enter the following at the command prompt and hit enter:

devenv /resetuserdata

Although the one below may not work, you may need to also need to enter:

devenv /resetallsettings

If devenv /resetallsettings does not work, it is not necessary to reset Visual Studio.

Write text to file

There are different methods to do this.

WriteAllText is great when you have a single string that you want to write to a file. But if you have a whole lot of strings to write, it's easier to write to a StreamWriter rather than build up a single string and then write that using WriteAllText.

FileStream gives you a little more control over writing files, which can be beneficial in certain cases. It also allows you to keep the file handle open and continuously write data without relinquishing control.

WriteAllText

Microsoft How to: Write Text to Files in Visual Basic

For Each foundFile As String In
My.Computer.FileSystem.GetFiles("C:\Documents and Settings")
    foundFile = foundFile & vbCrLf
    My.Computer.FileSystem.WriteAllText(
      "C:\Documents and Settings\FileList.txt", foundFile, True)
Next

StreamWriter

MIcrosoft How to: Write Text to Files with a StreamWriter in Visual Basic

Dim file As System.IO.StreamWriter
file = My.Computer.FileSystem.OpenTextFileWriter("c:\test.txt", True)
file.WriteLine("Here is the first string.")
file.Close()