Technology
 

Samples

From DotNET Wiki

VB Basic Samples.

  • Run: Run.exe

file: Run.vb When you begin designing an application, you will think it would be easy in Visual Basic, but if you do not generate complex content and design, the application may not catch the passive block. Visual Studio 2005 Professional Edition was used to develop this sample. Feel free to edit and reproduce the code in any edition of Visual Studio.

Module Run
'I kept this simple for both beginner and advanced users to understand.
'Please visit MSDN for the Visual Studio free Express
'Editions and Trials.
Sub Main()
Console.WriteLine("Hello, please enter your username after the beep!")
Console.Beep()
Dim username1 = Console.ReadLine
If (username1 IsNot Nothing) Then
Console.WriteLine("Welcome, " + username1)
ElseIf (username1 Is Nothing) Then
Console.WriteLine("Please re-enter your username.")
Dim usernamecheck1 = Console.ReadLine
If (usernamecheck1 IsNot Nothing) Then
Console.WriteLine("Welcome, " + usernamecheck1)
ElseIf (usernamecheck1 Is Nothing) Then
Console.WriteLine("Sorry, cannot access your username, may I help you anonymous?")
End If
End If
Console.WriteLine("Please enter the application you now wish to run:")
Dim readapp = Console.ReadLine
Console.WriteLine("Running..." + readapp)
Console.WriteLine("Press any key to run another application.")
If My.Computer.FileSystem.FileExists(readapp) Then
Process.Start(readapp)
Else
Console.WriteLine("Error, press any key and re-enter")
End If
ProcessIt()
Console.ReadKey(True)
Console.ReadKey(True)
'Once this line is processed and passed End Sub the application may close for some users.
End Sub
Sub ProcessIt()
Console.WriteLine("Please enter the application you now wish to run:")
Dim readapp = Console.ReadLine
Console.WriteLine("Running..." + readapp)
Console.WriteLine("Press any key to run another application.")
If My.Computer.FileSystem.FileExists(readapp) Then
Process.Start(readapp)
Else
Console.WriteLine("Error, press any key and re-enter")
End If
Console.ReadKey(True)
ProcessIn()
End Sub
Sub ProcessIn()
'Generate repeat.
ProcessIt()
End Sub
End Module


VC# Basic Samples.

[edit] Hello World

  • Compile: csc.exe Program.cs
  • Run: Program.exe

file: Program.cs

public class SampleMain
{
   static void Main()
   {
       System.Console.WriteLine(
         "Hello World!.. visit http://dotnet.wikia.com");
   }
}

[edit] Basic I/O Stream

  • Compile: csc.exe ProgramIO.cs
  • Run: ProgramIO.exe

file: ProgramIO.cs

using System;
using System.IO;//... to use StreamWriter class
public class SampleIOMain
{
   static void Main()
   {
       const string fileName = @"C:\wikiaSampleIOFile.txt";
       bool appendContent = File.Exists(fileName);
       using (StreamWriter writer =
         new StreamWriter(fileName, appendContent))
       {
           writer.WriteLine("File Text Line One");
           writer.WriteLine("File Text Line Two");
       }//auto-close the File Stream.
   }
}