Tuesday, September 6, 2011

Tuesday 9.2.11

Public Shared Sub Main()

Dim info As FileVersionInfo = FileVersionInfo.GetVersionInfo("C:\Program Files (x86)\FileZilla FTP Client\filezilla.exe")

'Display Version information
Console.WriteLine("Checking File: " & info.FileName)
Console.WriteLine("Product Name: " & info.ProductName)
Console.WriteLine("Product Versions: " & info.ProductVersion)
Console.WriteLine("Company Name: " & info.CompanyName)
Console.WriteLine("File Version: " & info.FileVersion)
Console.WriteLine("File Description: " & info.FileDescription)
Console.WriteLine("Original Filename: " & info.OriginalFilename)
Console.WriteLine("Legal Copyright: " & info.LegalCopyright)
Console.WriteLine("InternalName: " & info.InternalName)
Console.WriteLine("IsDebug: " & info.IsDebug)
Console.WriteLine("IsPatched: " & info.IsPatched)
Console.WriteLine("IsPreRelease: " & info.IsPreRelease)
Console.WriteLine("IsPrivateBuild: " & info.IsPrivateBuild)
Console.WriteLine("IsSpecialBuild: " & info.IsSpecialBuild)


End Sub


Private Sub Fill(ByVal dirNode As TreeNode)
Dim dir As New DirectoryInfo(dirNode.FullPath)

'an exception could be thrown n this code if you don't
' have sufficient security permissions for a file or directory
'you can catch and then ignore this exception
For Each dirItem As DirectoryInfo In dir.GetDirectories
'add a node for the directory
Dim newNode As New TreeNode(dirItem.Name)
dirNode.Nodes.Add(newNode)
newNode.Nodes.Add("*")
Next
End Sub

Private Sub DirectoryTree_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'set the first node
Dim rootNode As New TreeNode("C:\")
treeDirectory.Nodes.Add(rootNode)

'fill the first level and expand it
Fill(rootNode)
treeDirectory.Nodes(0).Expand()
End Sub

Private Sub treeDirectory_BeforeExpand(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles treeDirectory.BeforeExpand
'if a dummy node is found, remove it and read teh real directory list
If e.Node.Nodes(0).Text = "*" Then
e.Node.Nodes.Clear()
Fill(e.Node)
End If
End Sub


Public Class Recipe05_07
Public Shared Sub Main()

'create a new file
Using fs As New FileStream("C:\inetpub\test4.txt", FileMode.Create)
'create a writer and specifiy the encoding the
'defaut (utf-8) supports special unicode characters,
'but encodes all standard characters in the same way as ASCII encoding
Using w As New StreamWriter(fs, Encoding.UTF8)
'write a decimal, string, special Unicode character and char
w.WriteLine(CDec(124.23))
w.WriteLine("Test string")
w.WriteLine("!")
End Using
End Using

Console.WriteLine("Press enter to read the information.")
Console.ReadLine()

'Open the file in read-only mode
Using fs As New FileStream("C:\inetpub\test4.txt", FileMode.Open)
Using r As New StreamReader(fs, Encoding.UTF8)
'read the data and convert it to the appropriate data type
Console.WriteLine(Decimal.Parse(r.ReadLine))
Console.WriteLine(r.ReadLine)
Console.WriteLine(Char.Parse(r.ReadLine))

End Using
End Using

'wait to continue
Console.WriteLine(Environment.NewLine)


End Sub
End Class


#include
char line[100];
int total;
int item;
int minus_items;

int main()
{
total = 0;
minus_items = 0;

while(1){
printf("Enter # to add\n");
printf(" or 0 to stop:");

fgets(line, sizeof(line), stdin);
sscanf(line, "%d", &item);

if(item == 0)
{
break;
}

if(item<0)
{
++minus_items;
continue;
//the continue statement is very similar to the break statement
//except that instead of terminating the loop, continue starts reexecuting the body of the loop
//from the beginning
}
total += item;
printf("Total: %d\n", total);
}

printf("Final total %d\n", total);
printf("with %d negative items omitted\n", minus_items);

return 0;
}

No comments: