Monday, December 13, 2010

Monday December 13th 2010

The following code is from a tutorial by Evangelo Petroutsos, but I didn't seem to get it working all that well.



Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim srchWord As String = TextBox1.Text.Trim
If srchWord.Length = 0 Then Exit Sub
Dim wordIndex As Integer
wordIndex = ListBox1.FindStringExact(srchWord)
If wordIndex >= 0 Then
ListBox1.TopIndex = wordIndex
ListBox1.SelectedIndex = wordIndex
Else
wordIndex = ListBox1.FindString(srchWord)
If wordIndex >= 0 Then
ListBox1.TopIndex = wordIndex
ListBox1.SelectedIndex = wordIndex
Else

End If
End If
End Sub
End Class


Here is another tutorial by Jesse Liberty


'Object is the base class for all other classes.

Dim myIntegerVariable As Integer = 123

Sub Main()
'Boxing
Dim myObjectVariable As Object = myIntegerVariable
Console.WriteLine("myObjectVariable: {0} ", myObjectVariable.ToString)

'unboxing
Dim anotherIntegerVariable As Integer = _
DirectCast(myObjectVariable, Integer)
Console.WriteLine("anotherIntegerVariable {0}", anotherIntegerVariable)

Console.ReadLine()

End Sub


Here is the next Jesse Liberty Tutorial, from "Learning Visual Basic .NET"



'from a tutorial by Jesse Liberty. Some modifications by myself.
Imports System
'This set of notes are from Srinivasa Sivkumar:
'Namespaces are the basic builidng block for the .net framework
'System is the basic namespace of every .net code
Namespace StructureDemonstration

'declare a structure named Location
Public Structure Location
'the structure has private data
Private myXVal As Integer
Private myYVal As Integer

'constructor

Public Sub New( _
ByVal xCoordinate As Integer, ByVal yCoordinate As Integer)
myXVal = xCoordinate
myYVal = yCoordinate
End Sub 'new

'Property
Public Property XVal() As Integer
Get
Return myXVal
End Get
Set(ByVal Value As Integer)
myXVal = Value
End Set
End Property

Public Property YVal() As Integer
Get
Return myYVal
End Get
Set(ByVal value As Integer)
myYVal = value
End Set
End Property

'Display the structure as a string
Public Overrides Function ToString() As String
Return [String].Format("{0}, {1}", XVal, YVal)
End Function 'toString
End Structure 'Location

Class tester
Public Sub Run()
'create an instance of the structure
Dim locl As New Location(200, 300)

'display the values in the structure
Console.WriteLine("Locl location: {0}", locl)

'invoke the default constructor
Dim loc2 As New Location()
Console.WriteLine("Loc2 location: {0}", loc2)

'pass the structure to a method
myFunc(locl)

'redisplay the value in the structure
Console.WriteLine("Locl location:{0} ", locl)
End Sub 'run

'method takes a structure as a parameter
Public Sub myFunc(ByVal loc As Location)
'modift the values through the properties
loc.XVal = 50
loc.YVal = 100
Console.WriteLine("Locl location: {0}", loc)

End Sub 'myFunc

End Class
End Namespace

Namespace circleDemonstration
'this is my own variation note that I got circumference and diameter confused
Public Structure cCircle
Private rRadius As Integer
Private cColor As String
Private dDiameter As Double

Public Sub New(ByVal inputRadius As Integer, ByVal inputColor As String)
rRadius = inputRadius
cColor = inputColor
End Sub

Public Sub getCircumference()
dDiameter = (rRadius ^ 2) * 3.14
End Sub

Public Overrides Function toString() As String
Return [String].Format("The circumference is {0} ", dDiameter)
End Function

Public Property myRadius() As Integer
Get
Return rRadius
End Get
Set(ByVal value As Integer)
rRadius = value
End Set
End Property

End Structure

Class newCircle

Public Sub run()
Dim circ As New cCircle
Console.WriteLine("Please enter the radius of the circle")
circ.myRadius = Console.ReadLine()
circ.getCircumference()
Console.WriteLine(circ.toString())

End Sub

End Class

End Namespace
Module module1
Sub main()
Dim t As New StructureDemonstration.tester

t.Run()
Console.ReadLine()

Dim c As New circleDemonstration.newCircle

c.run()
Console.ReadLine()

End Sub
End Module


Here is a tutorial by Michael Halverson on drawing



Public Class Form1

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

End Sub

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
'prepare GraphicsFun Variable for graphics calls
Dim GraphicsFun As System.Drawing.Graphics
GraphicsFun = Me.CreateGraphics

'use a red pen color to draw a line and an ellipse
Dim PenColor As New System.Drawing.Pen(System.Drawing.Color.Red)
GraphicsFun.DrawLine(PenColor, 20, 30, 100, 80)
GraphicsFun.DrawEllipse(PenColor, 10, 120, 200, 160)

'use a green brush color to create a filled rectangle
Dim BrushColor As New SolidBrush(Color.Green)
GraphicsFun.FillRectangle(BrushColor, 150, 10, 250, 100)

'Create a blue cardinal spline curve with four points
Dim Points() As Point = {New Point(358, 280), _
New Point(300, 320), New Point(275, 155), New Point(350, 180)}
For tension As Single = 0 To 2.5 Step 0.5
GraphicsFun.DrawCurve(Pens.DodgerBlue, Points, tension)
Next
End Sub
End Class

2 comments:

Brad Jensen said...
This comment has been removed by the author.
Brad Jensen said...

I don't understand the difference between a a structure and a class, they seem to look the same to me, I will have to research that.