'create sample data. for simplicity, the data consists of an array
'of anonymous types that contain three properties
'name (a Sting), CallSign (a string) and age (an integer)
Dim galactica() = { _
New With {.Name = "William Adama", _
.CallSign = "Husker", _
.Age = 65}, _
New With {.Name = "Saul Tigh", _
.CallSign = Nothing, _
.Age = 83}, _
New With {.Name = "Lee Adama", _
.CallSign = "Apollo", _
.Age = 30}, _
New With {.Name = "Kara Thrace", _
.CallSign = "Starbuck", _
.Age = 28}, _
New With {.Name = "Gaius Baltar", _
.CallSign = Nothing, _
.Age = 42}}
'variables used to store results of Any and All methods
Dim anyResult As Boolean
Dim allResult As Boolean
'display the contents of the galactica array
Console.WriteLine("Galactica Crew:")
For Each crewMember In galactica
Console.WriteLine(" {0}", crewMember.Name)
Next
Console.WriteLine(Environment.NewLine)
'determine if the galactica array has any data
anyResult = galactica.Any
'display the results of the previous test
Console.WriteLine("Does the array contain any data: ")
If anyResult Then
Console.Write("Yes")
Else
Console.Write("No")
End If
Console.WriteLine(Environment.NewLine)
'determine if any members have nothign set for the CallSign property, using any method
anyResult = galactica.Any(Function(crewMember) crewMember.callsign Is Nothing)
'display the results of the previous test
Console.WriteLine("Do any crew members NOT have a callsign: ")
If anyResult Then
Console.Write("Yes")
Else
Console.Write("No")
End If
Console.WriteLine(Environment.NewLine)
'determine if all members of the array have an Age property
'greater than 40, using the All method
allResult = galactica.All(Function(crewMember) crewMember.Age > 40)
'display the results of the previous test
Console.WriteLine("Are all of the crew members over 40:")
If allResult Then
Console.Write("Yes")
Else
Console.Write("No")
End If
Console.WriteLine(Environment.NewLine)
'display the contents of the galactica array in reverse
Console.WriteLine("Galactica Crew (Reverse Order):")
For Each crewMember In galactica.Reverse
Console.WriteLine(" {0}", crewMember.Name)
Next
Console.ReadLine()
End Sub
#include
int main()
{
using namespace std;
int chest = 42;
int waist = 0x42;
int inseam = 042;
cout << "Monsieur custs a striking figure!\n";
cout << "Chest = " << chest << "\n";
cout << "Waist = " << waist << "\n";
cout << "Inseam = " << inseam << "\n";
return 0;
}
#include <iostream>
int main()
{
using namespace std;
int chest = 42;
int waist = 42;
int inseam = 42;
cout << "Monsieur cuts a striking figure!" << endl;
cout << " chest = " << chest << "(decimal)" << endl;
cout << hex; //manipulator for changing number base
cout << "waist = " << waist << " (hexidecimal)" << endl;
cout << oct;
cout << "inseam = " << inseam << " (octal) " << endl;
return 0;
}
#include <iostream>
int main()
{
using namespace std;
char ch; //declare a char variable
cout << "Enter a character: " << endl;
cin >> ch;
cout << "Holla!";
cout << "Thank you for the " << ch << " character." << endl;
return 0;
}
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'the AddressOf operator implicitly creates an object known as a delgate that forwards calls to the appropriate event handler when
'an event occurs
Try
AddHandler PrintDocument1.PrintPage, AddressOf Me.PrintGraphic
PrintDocument1.Print() 'print graphic
Catch ex As Exception
MessageBox.Show("Sorry, there is a problem printing", ex.ToString())
End Try
End Sub
'sub for printing graphic
Private Sub PrintGraphic(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
'create teh graphic using DrawImage
ev.Graphics.DrawImage(Image.FromFile(TextBox1.Text), ev.Graphics.VisibleClipBounds)
'specify that this is the last page to print
ev.HasMorePages = False
End Sub
No comments:
Post a Comment