Week# 18 Challenge: VB.NET

A Introduction to VB.net.

Page 1 of 1

9 Replies - 11348 Views - Last Post: 11 May 2010 - 07:01 PM

#1 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,467
  • Joined: 29-May 08

Week# 18 Challenge: VB.NET

Post icon  Posted 25 April 2010 - 11:42 AM

Week #18 vb.net

Posted Image

Introduction
Let me begin by differentiating vb.NET from vb.
It is true to say that the vb in both does stand for Visual Basic and that they share a similar looking syntax, but they are very different. The most important difference is in how they are implemented.

vb (that's without the .NET) is compiled into a native executable
vb.NET (that's with the .NET) is compiled into a CIL which is then interpreted by the .NET Framework.

Where to download vb.net?
There are several editions of the vb.net out in the wilds;-
Visual Basic 2005 (aka VB8), Visual Basic 2008 (aka VB9)
But I suggest you uses the latest version
Visual Basic 2010 Express Edition (aka VB10)
Which has the latest version of the .NET Framework, .NET 4.0.

Useful Links
Visual Basic Developer Center
vb.net Tutorials
vb.net Snippets
vb.net Forum

A couple ideas to get you started.
Note: Yes we are aware that some one following Code Samples do break the Syntax Highlighter of the code tags.

  • Disable the Legacy Support for vb6
    Its a great way to learn the new stuff.
    Yeah a I know it takes a little getting used to, something you could do before you can't do Now.
    Eg Control Arrays.


  • Discover some of the benefit of Using Object Orient Design by Create your own class object.

  • Create DLL of useful bits. (Extension Methods)
    The following one is on I use lot.
    Spoiler


  • Investigate Generics
    For you don't know it a way of sharing and simplifying your code. The (Of T) Stuff

    Spoiler


  • Play with LINQ
    It more powerful than you think.
    Try combining LINQ wirh some Extension Methods

    Spoiler


    So far I been only showing Console Programs, which is great for testing out ideas with hassle dealing with challenges that an Asynchronous MultiThreaded Graphical Interface. It lets you focus on the core language. Learn the language features, controls and Forms are way easier user. It easy to change the project type to a Windows Forms application later on.

    Any How.

  • XML Literals

    One feature if VB.net and not yet available ro C# Programmers, (Who are calling out for them.) :baaa:
    Even as especially in VB10 since they (Microsoft) have included the XML-to-Scheme Template (Express Edition Too)
    Previously it was an extra download. What it does is allows add Intellisense support over an XML document, it has the schema of.

    Spoiler


There is an Periodic Table Example somewhere on my blog The Madman Scribblings that uses a lot of the above (of not all.)

Ain't RSS feeds xml based? What about the Google APIs?

Now you are starting to seeing the power of them.


Look in the Tutorials and Snippets for some other cool stuff

A personal view of vb10.

First of I'm sorry for such as long post but I felt impassioned to express to you my joy of coding in the vb.net language.

Spoiler


What tips would you give some starting in vb.net?

Hmm,
Spoiler


"Ok, What are you current coding? or project?"

Spoiler


Thank for reading and enjoy this weeks 52 Week of Code.



The Challenge

No specific challenge this week other than this.

I daring, double daring you to try vb.net and not to have fun exploring it.
If you happen;-
find something interesting on way
or you have created something you want to share among the rest of the vb.net community.


Thank you raading I know that was a lot longer than your typical 52WoC of Code post.

Finally,

Spoiler


Is This A Good Question/Topic? 0
  • +

Replies To: Week# 18 Challenge: VB.NET

#2 programble  Icon User is offline

  • (cons :dic :head)

Reputation: 49
  • View blog
  • Posts: 1,315
  • Joined: 21-February 09

Re: Week# 18 Challenge: VB.NET

Posted 03 May 2010 - 12:52 PM

You, sir, need some capitalization.
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Week# 18 Challenge: VB.NET

Posted 03 May 2010 - 01:04 PM

Hmm, and that had to be posted why exactly? Please keep posts in this thread related to the Challenge for the week listed
Was This Post Helpful? 0
  • +
  • -

#4 SwiftStriker00  Icon User is offline

  • No idea why my code works
  • member icon

Reputation: 433
  • View blog
  • Posts: 1,596
  • Joined: 25-December 08

Re: Week# 18 Challenge: VB.NET

Posted 03 May 2010 - 01:57 PM

Wow I didnt even know we had a spoiler tag until your post. I want to try this challenge since its so close to C# / .NET, and i've worked with the vb syntax before. Im busy this week so it might get back logged but, thanks for the detailed post, more info always helps.
Was This Post Helpful? 0
  • +
  • -

#5 Raynes  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 611
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

Re: Week# 18 Challenge: VB.NET

Posted 03 May 2010 - 03:35 PM

View PostAdamSpeight2008, on 25 April 2010 - 10:42 AM, said:

I daring, double daring you to try vb.net and not to have fun exploring it.


What do I get if I win? :P

View PostPsychoCoder, on 03 May 2010 - 12:04 PM, said:

Hmm, and that had to be posted why exactly? Please keep posts in this thread related to the Challenge for the week listed


In all seriousness, I have to agree with him. I mean, he even formatted the title of this thread wrong. Let's be consistent.

And before you're forced to reiterate the ol' "shut up" routine, I'll save you the trouble and not post here unless I have input related to the challenge.

Peace and harmony. <3
Was This Post Helpful? 0
  • +
  • -

#6 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,467
  • Joined: 29-May 08

Re: Week# 18 Challenge: VB.NET

Posted 03 May 2010 - 08:54 PM

If you have comments regarding the styling and quality of the this topic
Please post the in this thread.
Was This Post Helpful? 1
  • +
  • -

#7 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,467
  • Joined: 29-May 08

Re: Week# 18 Challenge: VB.NET

Posted 05 May 2010 - 05:02 PM

Seeing that nobody seems to be trying this one.
For any who's interest here mine first entry.

For a bit of fun messing around a console app, come with a DSL that allow the draw pictures (sort of).

Attached File  52WoC_wk18_vb_01.zip (128.52K)
Number of downloads: 297

It very 80's looking.

Imports System.Runtime.CompilerServices
Imports System.ConsoleColor

Module Module1
  Dim console As Console
  Sub Main()
    Console.Title = "Console Examples"
    ' 5
    console.DrawHLine(White, New XY(0, 0), 200)
    Console.DrawHLine(Yellow, New XY(0, 0), 5).DrawVLine(Yellow, New XY(0, 0), 3).
    DrawHLine(New XY(0, 3), 4).DrawBlock(New XY(4, 4)).DrawBlock(New XY(4, 5)).DrawHLine(New XY(0, 6), 4)
    ''2
    Console.DrawHLine(Red, New XY(5, 0), 4).DrawVLine(New XY(9, 1), 2).SetFG(DarkBlue).DrawHLine(New XY(6, 3), 3).
    DrawVLine(New XY(5, 4), 3).DrawHLine(New XY(5, 6), 5)
    'W
    Console.DrawVLine(Green, New XY(10, 0), 6).DrawBlock(New XY(11, 6)).DrawVLine(New XY(12, 2), 4).DrawBlock(New XY(13, 6)).DrawVLine(New XY(14, 0), 6)
    'o
    Console.DrawHLine(Blue, New XY(16, 2), 3).DrawVLine(New XY(19, 3), 3).DrawHLine(New XY(16, 6), 3).DrawVLine(New XY(15, 3), 3)
    'C
    Console.DrawVLine(Magenta, New XY(20, 1), 5).DrawHLine(New XY(21, 0), 3).
      DrawBlock(New XY(24, 1)).DrawHLine(New XY(21, 6), 3).DrawBlock(New XY(24, 5))

    Console.ResetColor()

    Console.SetCursorPosition(0, 8)
    Console.AskYesNoQuestion("Exit?")
  End Sub
End Module

Public Module Console_BlockExt
   <Extension()>
  Public Function SetFG(ByRef [Console] As Console, ByVal Color As ConsoleColor) As Console
    [Console].ForegroundColor = Color
    Return [Console]
  End Function
  <Extension()>
  Public Function SetBG(ByRef [Console] As Console, ByVal Color As ConsoleColor) As Console
    [Console].BackgroundColor = Color
    Return [Console]
  End Function
  <Extension()>
  Public Function SetFCBG(ByRef [Console] As Console, ByVal Color As ConsoleColor, ByVal BackColor As ConsoleColor) As Console
    Return [Console].SetFG(Color).SetBG(BackColor)
  End Function
  <Extension()>
  Public Function DrawVLine(ByRef [console] As Console,
                            ByVal xy As XY,
                            ByVal l As Integer) As Console
    Return DrawVLine([console], [console].ForegroundColor, xy, l)
  End Function
  <Extension()>
  Public Function DrawVLine(ByRef [console] As Console, ByVal Color As ConsoleColor,
                            ByVal xy As XY,
                            ByVal l As Integer) As Console
    Dim Prev As New XY([console].CursorLeft, [console].CursorTop)
    Try
      While (l > 0) : [console].DrawBlock(Color, xy) : xy.Y += 1 : l -= 1
      End While
    Catch ex As ArgumentOutOfRangeException
      Exit Try
    End Try

    [console].SetCursorPosition(Prev.X, Prev.Y)
    Return [console]
  End Function
  <Extension()>
  Public Function DrawHLine(ByRef [console] As Console, ByVal Color As ConsoleColor, ByVal xy As XY, ByVal l As Integer) As Console
     Dim Prev As New XY([console].CursorLeft, [console].CursorTop)
    Try
      While (l > 0) : [console].DrawBlock(Color, xy) : xy.X += 1 : l -= 1
      End While
    Catch ex As ArgumentOutOfRangeException
      Exit Try
    End Try
    [console].SetCursorPosition(Prev.X, Prev.Y)
    Return [console]
  End Function
  <Extension()>
  Public Function DrawHLine(ByRef [console] As Console, ByVal xy As XY, ByVal l As Integer) As Console
    Return DrawHLine([console], [console].ForegroundColor, xy, l)
  End Function
#Region "Blocks"

  <Extension()>
  Public Function DrawBlock(ByRef [console] As Console, ByVal xy As XY) As Console
    Return DrawBlock([console], [console].ForegroundColor, xy)
  End Function
  <Extension()>
  Public Function DrawBlock(ByRef [console] As Console, ByVal Color As ConsoleColor, ByVal xy As XY) As Console
    Dim Prev As New XY([console].CursorLeft, [console].CursorTop)
    [console].SetCursorPosition(xy.X, xy.Y)
    [console].ColorWrite("#", Color, Color)
    [console].SetCursorPosition(Prev.X, Prev.Y)
    Return [console]
  End Function
#End Region

  <Extension()>
  Public Function DrawDigit(ByVal [console] As Console,
                            ByVal D As Char,
                            ByVal x As Integer, ByVal y As Integer,
                            Optional ByVal FG As ConsoleColor = White,
                            Optional ByVal BG As ConsoleColor = Black) As Console
    Dim Prev As New XY([console].CursorLeft, [console].CursorTop)


    Select Case D
      Case "0"c
      Case "5"

    End Select


    [console].SetCursorPosition(Prev.X, Prev.Y)
    [console].ResetColor()

    Return [console]
  End Function

#Region "colors"

  <Extension()>
  Public Function ColorWriteLine(ByVal [console] As Console, ByVal Text As String,
                                  Optional ByVal FG As ConsoleColor = ConsoleColor.White,
                                  Optional ByVal BG As ConsoleColor = ConsoleColor.Black) As Console
    [console].SetFCBG(FG, BG)
    [console].WriteLine(Text)
    Return [console]
  End Function

  <Extension()>
  Public Function ColorWrite(ByVal [console] As Console,
                                  ByVal Text As String,
                                  Optional ByVal FG As ConsoleColor = ConsoleColor.White,
                                  Optional ByVal BG As ConsoleColor = ConsoleColor.Black) As Console
    [console].SetFCBG(FG, BG)
    [console].Write(Text)
    Return [console]
  End Function
#End Region

  <Extension()>
  Public Function PauseFor(ByVal [console] As Console, ByVal ms As Integer) As Console
    Threading.Thread.Sleep(ms)
    Return [console]
  End Function
  <Extension()>
  Public Sub PressAnyKey(ByVal [console] As Console, ByVal Text As String)
    [console].WriteLine(Text)
    [console].ReadKey(True)
    Dim P As New Tuple(Of Integer, Integer)(console.CursorLeft, console.CursorTop)
  End Sub

  <Extension()>
  Public Function AskYesNoQuestion(ByVal [console] As Console,
                                   ByVal Question As String) As Boolean
    Dim KeyPressed As ConsoleKeyInfo
    [console].WriteLine(Question)
    Dim P As New Tuple(Of Integer, Integer)(console.CursorLeft, console.CursorTop)
    While True
      ' Wait for key to be pressed
      KeyPressed = console.ReadKey(True)
      If KeyPressed.IsOneOf({ConsoleKey.Y, ConsoleKey.N}) Then Exit While
      [console].ColorWriteLine("Not one of the allowed Keys", ConsoleColor.Black, ConsoleColor.Red)
      [console].PauseFor(1000)
      [console].SetCursorPosition(P.Item1, P.Item2)
      [console].ColorWriteLine("Not one of the allowed Keys", ConsoleColor.Black, ConsoleColor.Black)
    End While
    If KeyPressed.Key = ConsoleKey.N Then Return False
    Return True
  End Function

  <Extension()>
  Public Function IsOneOf(ByVal KeyPressed As ConsoleKeyInfo, ByVal ParamArray AllowedKeys() As ConsoleKey) As Boolean
    Return AllowedKeys.Contains(KeyPressed.Key)
  End Function


End Module
Public Class XY
  Public X As Integer
  Public Y As Integer
  Public Sub New(ByVal sx As Integer, ByVal sy As Integer)
    X = sx
    Y = sy
  End Sub
End Class

Was This Post Helpful? 1
  • +
  • -

#8 programble  Icon User is offline

  • (cons :dic :head)

Reputation: 49
  • View blog
  • Posts: 1,315
  • Joined: 21-February 09

Re: Week# 18 Challenge: VB.NET

Posted 08 May 2010 - 12:50 PM

View PostAdamSpeight2008, on 05 May 2010 - 06:02 PM, said:

Seeing that nobody seems to be trying this one.


I wonder why. Remember this thread?
Was This Post Helpful? 0
  • +
  • -

#9 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2873
  • View blog
  • Posts: 11,032
  • Joined: 15-July 08

Re: Week# 18 Challenge: VB.NET

Posted 09 May 2010 - 08:30 AM

I've been messing around with VB.NET the past week or so (no clue about this challenge), but I think I'll make the second contribution: a notepad clone (No printing functionality yet). I'd say the most interesting part is the persistent settings (like Font and word wrap settings stay even after application closes and reopens). I used My.Settings!

Comments?

Form-Handler code
Public Class Notepad

    Dim filename As String = "Untitled"
    Dim unsavedChanges As Boolean = False

    Private Sub miWordWrap_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles miWordWrap.Click
        If txtNote.WordWrap = True Then
            txtNote.WordWrap = False
            miWordWrap.Checked = False
        Else
            txtNote.WordWrap = True
            miWordWrap.Checked = True
        End If

        My.Settings.WordWrap = txtNote.WordWrap
    End Sub

    Private Sub miNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miNew.Click
        If unsavedChanges = True Then
            If contUnsaved() = False Then
                Return
            End If
        End If

        txtNote.Clear()
        txtNote.ClearUndo()
        filename = "Untitled"
        unsavedChanges = False
        Me.Text = filename & "  ||  Notepad--"

    End Sub

    Private Sub miOpen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles miOpen.Click
        If unsavedChanges = True Then
            If contUnsaved() = False Then
                Return
            End If
        End If

        fdOpen.Filter = "Text Files(*.txt)|*.txt|Python Files(*.py)|*.py|Ruby Files(*.rb)|*.rb|Java Files(*.java)|*.java |C/C++ Files(*.c *.cpp *.cxx *.c++)|*.c;*.cpp;*.cxx;*.c++|All Files(*.*)|*.*"
        Dim result As DialogResult = fdOpen.ShowDialog()

        If result = DialogResult.Cancel Then
            MessageBox.Show("You cancelled the load.", "Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        Else
            filename = fdOpen.FileName
            Dim fileReader As New System.IO.StreamReader(filename)
            txtNote.Text = fileReader.ReadToEnd()
            fileReader.Close()

            Me.Text = filename & "  ||  Notepad--"
            unsavedChanges = False
        End If
    End Sub

    Private Sub miSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles miSave.Click
        If filename = "Untitled" Then
            miSaveAs.PerformClick()
        Else
            Dim fileSaver As New System.IO.StreamWriter(filename)
            fileSaver.Write(txtNote.Text)
            fileSaver.Close()

            Me.Text = filename & "  ||  Notepad--"
            unsavedChanges = False
        End If
    End Sub

    Private Sub miSaveAs_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles miSaveAs.Click
        fdSave.Filter = "Text Files(*.txt)|*.txt|Python Files(*.py)|*.py|Ruby Files(*.rb)|*.rb|Java Files(*.java)|*.java |C/C++ Files(*.c *.cpp *.cxx *.c++)|*.c;*.cpp;*.cxx;*.c++|All Files(*.*)|*.*"
        Dim result As DialogResult = fdSave.ShowDialog()
        If result = DialogResult.Cancel Then
            MessageBox.Show("You cancelled the Save.", "Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        Else
            filename = fdSave.FileName
            miSave.PerformClick()
        End If
    End Sub

    Private Sub miExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles miExit.Click
        If unsavedChanges = True Then
            If contUnsaved() = False Then
                Return
            End If
        End If

        Me.Close()
    End Sub

    Private Sub txtNote_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNote.TextChanged
        unsavedChanges = True
        Me.Text = "*" & filename & "  ||  Notepad--"
    End Sub

    Private Function contUnsaved() As Boolean
        Dim result As DialogResult = MessageBox.Show("There are unsaved changes. Continue without saving?", "Unsaved Changes", _
                                                     MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
        If result = DialogResult.Yes Then
            Return True
        Else
            Return False
        End If
    End Function

    Private Sub miFont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miFont.Click
        Dim result As DialogResult = fdFontDialog.ShowDialog()
        If result = DialogResult.OK Then
            My.Settings.UserFont = fdFontDialog.Font
            txtNote.Font = fdFontDialog.Font
        End If
    End Sub

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        txtNote.Font = My.Settings.UserFont
        txtNote.WordWrap = My.Settings.WordWrap
        If My.Settings.WordWrap = True Then
            miWordWrap.Checked = True
        Else
            miWordWrap.Checked = False
        End If

    End Sub

    Private Sub miUndo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miUndo.Click
        txtNote.Undo()
    End Sub

    Private Sub miCut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miCut.Click
        txtNote.Cut()
    End Sub

    Private Sub miCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miCopy.Click
        txtNote.Copy()
    End Sub

    Private Sub miPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miPaste.Click
        txtNote.Paste()
    End Sub

    Private Sub miSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miSelectAll.Click
        txtNote.SelectAll()
    End Sub

    Private Sub Notepad_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If unsavedChanges = True Then
            Dim result As DialogResult = contUnsaved()
            If result = False Then
                e.Cancel = True
            Else
                e.Cancel = False
            End If
        End If
    End Sub
End Class



Generated Code
'Notepad.Designer.vb
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Notepad
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.MenuStrip1 = New System.Windows.Forms.MenuStrip()
        Me.FileToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
        Me.miNew = New System.Windows.Forms.ToolStripMenuItem()
        Me.miOpen = New System.Windows.Forms.ToolStripMenuItem()
        Me.miSave = New System.Windows.Forms.ToolStripMenuItem()
        Me.miSaveAs = New System.Windows.Forms.ToolStripMenuItem()
        Me.ToolStripMenuItem1 = New System.Windows.Forms.ToolStripSeparator()
        Me.miExit = New System.Windows.Forms.ToolStripMenuItem()
        Me.EditToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
        Me.miUndo = New System.Windows.Forms.ToolStripMenuItem()
        Me.ToolStripMenuItem2 = New System.Windows.Forms.ToolStripSeparator()
        Me.miCut = New System.Windows.Forms.ToolStripMenuItem()
        Me.miCopy = New System.Windows.Forms.ToolStripMenuItem()
        Me.miPaste = New System.Windows.Forms.ToolStripMenuItem()
        Me.ToolStripMenuItem3 = New System.Windows.Forms.ToolStripSeparator()
        Me.miSelectAll = New System.Windows.Forms.ToolStripMenuItem()
        Me.FormatToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
        Me.miWordWrap = New System.Windows.Forms.ToolStripMenuItem()
        Me.miFont = New System.Windows.Forms.ToolStripMenuItem()
        Me.fdOpen = New System.Windows.Forms.OpenFileDialog()
        Me.fdSave = New System.Windows.Forms.SaveFileDialog()
        Me.FileSystemWatcher1 = New System.IO.FileSystemWatcher()
        Me.fdFontDialog = New System.Windows.Forms.FontDialog()
        Me.txtNote = New System.Windows.Forms.RichTextBox()
        Me.MenuStrip1.SuspendLayout()
        CType(Me.FileSystemWatcher1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'MenuStrip1
        '
        Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.FileToolStripMenuItem, Me.EditToolStripMenuItem, Me.FormatToolStripMenuItem})
        Me.MenuStrip1.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.HorizontalStackWithOverflow
        Me.MenuStrip1.Location = New System.Drawing.Point(0, 0)
        Me.MenuStrip1.Name = "MenuStrip1"
        Me.MenuStrip1.Size = New System.Drawing.Size(781, 24)
        Me.MenuStrip1.TabIndex = 0
        Me.MenuStrip1.Text = "MenuStrip1"
        '
        'FileToolStripMenuItem
        '
        Me.FileToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.miNew, Me.miOpen, Me.miSave, Me.miSaveAs, Me.ToolStripMenuItem1, Me.miExit})
        Me.FileToolStripMenuItem.Name = "FileToolStripMenuItem"
        Me.FileToolStripMenuItem.Size = New System.Drawing.Size(37, 20)
        Me.FileToolStripMenuItem.Text = "&File"
        '
        'miNew
        '
        Me.miNew.Name = "miNew"
        Me.miNew.ShortcutKeys = CType((System.Windows.Forms.Keys.Control Or System.Windows.Forms.Keys.N), System.Windows.Forms.Keys)
        Me.miNew.Size = New System.Drawing.Size(186, 22)
        Me.miNew.Text = "&New"
        '
        'miOpen
        '
        Me.miOpen.Name = "miOpen"
        Me.miOpen.ShortcutKeys = CType((System.Windows.Forms.Keys.Control Or System.Windows.Forms.Keys.O), System.Windows.Forms.Keys)
        Me.miOpen.Size = New System.Drawing.Size(186, 22)
        Me.miOpen.Text = "&Open"
        '
        'miSave
        '
        Me.miSave.Name = "miSave"
        Me.miSave.ShortcutKeys = CType((System.Windows.Forms.Keys.Control Or System.Windows.Forms.Keys.S), System.Windows.Forms.Keys)
        Me.miSave.Size = New System.Drawing.Size(186, 22)
        Me.miSave.Text = "&Save"
        '
        'miSaveAs
        '
        Me.miSaveAs.Name = "miSaveAs"
        Me.miSaveAs.ShortcutKeys = CType(((System.Windows.Forms.Keys.Control Or System.Windows.Forms.Keys.Shift) _
                    Or System.Windows.Forms.Keys.S), System.Windows.Forms.Keys)
        Me.miSaveAs.Size = New System.Drawing.Size(186, 22)
        Me.miSaveAs.Text = "Save &As"
        '
        'ToolStripMenuItem1
        '
        Me.ToolStripMenuItem1.Name = "ToolStripMenuItem1"
        Me.ToolStripMenuItem1.Size = New System.Drawing.Size(183, 6)
        '
        'miExit
        '
        Me.miExit.Name = "miExit"
        Me.miExit.ShortcutKeys = CType((System.Windows.Forms.Keys.Control Or System.Windows.Forms.Keys.Q), System.Windows.Forms.Keys)
        Me.miExit.Size = New System.Drawing.Size(186, 22)
        Me.miExit.Text = "E&xit"
        '
        'EditToolStripMenuItem
        '
        Me.EditToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.miUndo, Me.ToolStripMenuItem2, Me.miCut, Me.miCopy, Me.miPaste, Me.ToolStripMenuItem3, Me.miSelectAll})
        Me.EditToolStripMenuItem.Name = "EditToolStripMenuItem"
        Me.EditToolStripMenuItem.Size = New System.Drawing.Size(39, 20)
        Me.EditToolStripMenuItem.Text = "&Edit"
        '
        'miUndo
        '
        Me.miUndo.Name = "miUndo"
        Me.miUndo.ShortcutKeys = CType((System.Windows.Forms.Keys.Control Or System.Windows.Forms.Keys.Z), System.Windows.Forms.Keys)
        Me.miUndo.Size = New System.Drawing.Size(164, 22)
        Me.miUndo.Text = "&Undo"
        '
        'ToolStripMenuItem2
        '
        Me.ToolStripMenuItem2.Name = "ToolStripMenuItem2"
        Me.ToolStripMenuItem2.Size = New System.Drawing.Size(161, 6)
        '
        'miCut
        '
        Me.miCut.Name = "miCut"
        Me.miCut.ShortcutKeys = CType((System.Windows.Forms.Keys.Control Or System.Windows.Forms.Keys.X), System.Windows.Forms.Keys)
        Me.miCut.Size = New System.Drawing.Size(164, 22)
        Me.miCut.Text = "Cu&t"
        '
        'miCopy
        '
        Me.miCopy.Name = "miCopy"
        Me.miCopy.ShortcutKeys = CType((System.Windows.Forms.Keys.Control Or System.Windows.Forms.Keys.C), System.Windows.Forms.Keys)
        Me.miCopy.Size = New System.Drawing.Size(164, 22)
        Me.miCopy.Text = "&Copy"
        '
        'miPaste
        '
        Me.miPaste.Name = "miPaste"
        Me.miPaste.ShortcutKeys = CType((System.Windows.Forms.Keys.Control Or System.Windows.Forms.Keys.V), System.Windows.Forms.Keys)
        Me.miPaste.Size = New System.Drawing.Size(164, 22)
        Me.miPaste.Text = "&Paste"
        '
        'ToolStripMenuItem3
        '
        Me.ToolStripMenuItem3.Name = "ToolStripMenuItem3"
        Me.ToolStripMenuItem3.Size = New System.Drawing.Size(161, 6)
        '
        'miSelectAll
        '
        Me.miSelectAll.Name = "miSelectAll"
        Me.miSelectAll.ShortcutKeys = CType((System.Windows.Forms.Keys.Control Or System.Windows.Forms.Keys.A), System.Windows.Forms.Keys)
        Me.miSelectAll.Size = New System.Drawing.Size(164, 22)
        Me.miSelectAll.Text = "&Select All"
        '
        'FormatToolStripMenuItem
        '
        Me.FormatToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.miWordWrap, Me.miFont})
        Me.FormatToolStripMenuItem.Name = "FormatToolStripMenuItem"
        Me.FormatToolStripMenuItem.Size = New System.Drawing.Size(57, 20)
        Me.FormatToolStripMenuItem.Text = "F&ormat"
        '
        'miWordWrap
        '
        Me.miWordWrap.Checked = True
        Me.miWordWrap.CheckState = System.Windows.Forms.CheckState.Checked
        Me.miWordWrap.Name = "miWordWrap"
        Me.miWordWrap.Size = New System.Drawing.Size(134, 22)
        Me.miWordWrap.Text = "&Word Wrap"
        '
        'miFont
        '
        Me.miFont.Name = "miFont"
        Me.miFont.Size = New System.Drawing.Size(134, 22)
        Me.miFont.Text = "&Font"
        '
        'fdOpen
        '
        Me.fdOpen.FileName = "OpenFileDialog1"
        '
        'FileSystemWatcher1
        '
        Me.FileSystemWatcher1.EnableRaisingEvents = True
        Me.FileSystemWatcher1.SynchronizingObject = Me
        '
        'txtNote
        '
        Me.txtNote.Dock = System.Windows.Forms.DockStyle.Fill
        Me.txtNote.Location = New System.Drawing.Point(0, 24)
        Me.txtNote.Name = "txtNote"
        Me.txtNote.Size = New System.Drawing.Size(781, 404)
        Me.txtNote.TabIndex = 1
        Me.txtNote.Text = ""
        '
        'Notepad
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(781, 428)
        Me.Controls.Add(Me.txtNote)
        Me.Controls.Add(Me.MenuStrip1)
        Me.MainMenuStrip = Me.MenuStrip1
        Me.Name = "Notepad"
        Me.Text = "Untitled  ||  Notepad--"
        Me.MenuStrip1.ResumeLayout(False)
        Me.MenuStrip1.PerformLayout()
        CType(Me.FileSystemWatcher1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents MenuStrip1 As System.Windows.Forms.MenuStrip
    Friend WithEvents FileToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents miNew As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents miOpen As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents miSave As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents miSaveAs As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents ToolStripMenuItem1 As System.Windows.Forms.ToolStripSeparator
    Friend WithEvents miExit As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents EditToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents miUndo As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents ToolStripMenuItem2 As System.Windows.Forms.ToolStripSeparator
    Friend WithEvents miCut As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents miCopy As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents miPaste As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents ToolStripMenuItem3 As System.Windows.Forms.ToolStripSeparator
    Friend WithEvents miSelectAll As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents FormatToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents miWordWrap As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents fdOpen As System.Windows.Forms.OpenFileDialog
    Friend WithEvents fdSave As System.Windows.Forms.SaveFileDialog
    Friend WithEvents FileSystemWatcher1 As System.IO.FileSystemWatcher
    Friend WithEvents miFont As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents fdFontDialog As System.Windows.Forms.FontDialog
    Friend WithEvents txtNote As System.Windows.Forms.RichTextBox

End Class



Yes, I used forms, but I was just learning file input/output and event handling.

I am attaching the solutoin if you guys are interested.
Attached File  Notepad.zip (582.42K)
Number of downloads: 313
Was This Post Helpful? 1
  • +
  • -

#10 zedth2  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 121
  • Joined: 14-September 09

Re: Week# 18 Challenge: VB.NET

Posted 11 May 2010 - 07:01 PM

Here is a web browser I've been playing with for a little while. I've been using VB.NET for a while now, I love VB

Public Class WebBaseline
    Dim tabCount As Integer
    Dim FullModeOn As Boolean = True
    Dim TabHeight As Integer
    Dim FormWidth As Integer
    Dim FormHeight As Integer

    Private Sub SubRemoveAllTabs()
        tabconBase.TabPages.Clear()
        SubAddTab()
    End Sub

    Private Sub SubFullMode()
        FormWidth = Me.Width() - 14
        FormHeight = Me.Height()
        If FullModeOn = True Or WebBaselineSettingsuser.Default.FullMode = True Then

            FullModeOn = False
            btnAddTab.Visible = False
            btnRemoveTab.Visible = False
            btnGo.Visible = False
            btnStop.Visible = False
            btnBack.Visible = False
            btnForward.Visible = False
            btnHome.Visible = False
            smiFullMode.Checked = True
            txtAddress.Location = New System.Drawing.Point(0, 32)
            txtAddress.Width = FormWidth
            tabconBase.Location = New System.Drawing.Point(0, 53)
            tabconBase.Height = (FormHeight - 90)
        ElseIf FullModeOn = False Or WebBaselineSettingsuser.Default.FullMode = False Then
            txtAddress.Location = New System.Drawing.Point(174, 37)
            txtAddress.Width = 588
            tabconBase.Location = New System.Drawing.Point(0, 90)
            tabconBase.Height = FormHeight - 127
            FullModeOn = True
            btnAddTab.Visible = True
            btnHome.Visible = True
            btnRemoveTab.Visible = True
            btnGo.Visible = True
            btnStop.Visible = True
            btnBack.Visible = True
            btnForward.Visible = True
            smiFullMode.Checked = False
        End If
    End Sub

    Private Sub SubAddTab()
        Dim Browse As New WebBrowser
        Dim tabCount As Integer = tabconBase.TabCount()
        tabconBase.TabPages.Add(1, tabCount & "Tab")
        tabconBase.SelectTab(tabCount)
        Browse.Name = "wb"
        Browse.Dock = DockStyle.Fill
        tabconBase.SelectedTab.Controls.Add(Browse)
        tabCount = tabCount + 1
    End Sub

    Private Sub SubRemoveTab()
        Dim tabIndex As Integer = tabconBase.SelectedIndex()
        tabCount = tabconBase.TabCount()
        If tabIndex > 0 Then
            tabconBase.TabPages.RemoveAt(tabconBase.SelectedIndex)
            tabconBase.SelectTab(tabIndex - 1)
            tabCount = tabCount - 1
        ElseIf tabIndex = 0 Then
            If tabCount = 1 Then
                SubHome()
            Else
                tabconBase.TabPages.RemoveAt(tabconBase.SelectedIndex)
                tabCount = tabCount - 1
            End If
        End If
        tabCount = tabconBase.TabCount()
    End Sub

    Private Sub SubHome()
        CType(tabconBase.SelectedTab.Controls.Item(0), WebBrowser).GoHome()
    End Sub

    Private Sub SubGo()
        Dim address As String = txtAddress.Text
        address = address.ToLower()
        If address = "home" Then
            SubHome()
        ElseIf address = "back" Then
            SubBack()
        ElseIf address = "forward" Then
            SubForward()
        Else
            CType(tabconBase.SelectedTab.Controls.Item(0), WebBrowser).Navigate(txtAddress.Text)
            tabconBase.SelectedTab.Text = address
        End If

    End Sub

    Private Sub SubStop()
        CType(tabconBase.SelectedTab.Controls.Item(0), WebBrowser).Stop()
    End Sub

    Private Sub SubForward()
        CType(tabconBase.SelectedTab.Controls.Item(0), WebBrowser).GoForward()
    End Sub

    Private Sub SubBack()
        CType(tabconBase.SelectedTab.Controls.Item(0), WebBrowser).GoBack()
    End Sub

    Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
        SubGo()
    End Sub

    Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
        SubStop()
    End Sub

    Private Sub btnAddTab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddTab.Click
        SubAddTab()
    End Sub

    Private Sub btnRemoveTab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemoveTab.Click
        SubRemoveTab()
    End Sub

    Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
        SubBack()
    End Sub

    Private Sub btnForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForward.Click
        SubForward()
    End Sub

    Private Sub WebBaseline_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SubAddTab()
        FormHeight = Me.Height()
        FormWidth = Me.Width()
        tabconBase.Height = (FormHeight - 127)
        tabconBase.Width = (FormWidth - 14)
    End Sub

    Private Sub txtAddress_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtAddress.KeyPress
        If Asc(e.KeyChar) = Keys.Enter Then
            SubGo()
        End If
    End Sub

    Private Sub smnuRemoveTab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles smnuRemoveTab.Click
        SubRemoveTab()
    End Sub

    Private Sub smiNewWebTab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles smiNewWebTab.Click
        SubAddTab()
    End Sub

    Private Sub smiFullMode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles smiFullMode.Click
        If FullModeOn = False Then
            SubFullMode()
        ElseIf FullModeOn = True Then
            SubFullMode()
        End If
    End Sub

    Private Sub smiRemoveAllTabs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles smiRemoveAllTabs.Click
        SubRemoveAllTabs()
    End Sub

    Private Sub btnHome_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHome.Click
        SubHome()
    End Sub

    Private Sub WebBaseline_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        If FullModeOn = False Then
            FormWidth = Me.Width() - 16
            txtAddress.Width = FormWidth
        End If
    End Sub

    Private Sub SettingsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SettingsToolStripMenuItem.Click
        WebBaselineSettings.Show()
    End Sub
End Class




Some of the code was written with help from the tuts here and other spots took a couple of weeks of banging my head against the wall. Right now I've been trying to figure out the savefiledialog and how to save a picture image because I'm also working on a picture viewer. But I just can't find a really good tut on the savefiledialog.

VB IS FUN!
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1