Sunday, November 7, 2010

Sunday 11/7/2010


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = System.Environment.MachineName
TextBox2.Text = System.Environment.UserName
TextBox3.Text = My.Computer.Info.OSFullName
TextBox4.Text = My.Computer.Info.OSPlatform
TextBox5.Text = My.Computer.Info.OSVersion
TextBox6.Text = My.Computer.Info.InstalledUICulture.ToString

End Sub


Here is a quick tutorial on OpenFileDialog


Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
TextBox1.Text = OpenFileDialog1.FileName

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.ShowDialog()
End Sub


Here is a tutorial I did on drawing a line in a picture box.


Public Class Form1


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PictureBox1.Refresh()
End Sub



Function getX1()
Dim S As Integer
If TextBox1.Text = "" Then
S = 0
Else
S = CInt(TextBox1.Text)
End If
Return S
End Function

Function getX2()
Dim S As Integer
If TextBox2.Text = "" Then
S = 0
Else
S = CInt(TextBox2.Text)
End If
Return S
End Function

Function getY1()
Dim S As Integer
If TextBox3.Text = "" Then
S = 0
Else
S = CInt(TextBox3.Text)
End If
Return S
End Function


Function getY2()
Dim S As Integer
If TextBox3.Text = "" Then
S = 0
Else
S = CInt(TextBox4.Text)
End If
Return S
End Function





Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Dim S(1) As Integer
Dim F(1) As Integer

Dim pen As Pen = Pens.Blue

S(0) = getX1()
S(1) = getX2()
F(0) = getY1()
F(1) = getY2()

e.Graphics.DrawLine(pen, S(0), S(1), F(0), F(1))
End Sub
End Class


Here is a variation I did on a tutorial by Michael Halvorson from his book Microsoft Visual Basic 2005 Step by Step which is by the way so far with of my favorite instructional books on using VB so far.



Imports System.IO

Public Class Form1

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

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'This is based on a tutorial by Michael Halvorson with some modifications of my own (in my version, the user can select the text to be uploaded on their own.
Dim fileLocation As String = ""
Dim streamToDisplay As StreamReader

Call getFileName(fileLocation)
TextBox1.Text = fileLocation


streamToDisplay = New StreamReader(fileLocation)
textDisplay.Text = streamToDisplay.ReadToEnd
streamToDisplay.Close()
textDisplay.Select(0, 0)

End Sub


Sub getFileName(ByRef fileLocation)
OpenFileDialog1.ShowDialog()
'I got this to work with notepad style text files, but not with document files. oh well.
OpenFileDialog1.Filter = "Text files (*.txt) |*.txt | Document files (*.doc) | *doc"
If OpenFileDialog1.FileName <> "" Then
fileLocation = OpenFileDialog1.FileName
lblFileName.Text = OpenFileDialog1.FileName
Else
MsgBox("You did not select a file")
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SaveFileDialog1.Filter = "Text files (*.txt) | *.txt"
SaveFileDialog1.ShowDialog()
If SaveFileDialog1.FileName <> "" Then
FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output)
PrintLine(1, textDisplay.Text) ' copy text to disk
FileClose(1)

End If


End Sub
End Class

No comments: