Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning SharePoint 2010 Development
This is the forum to discuss the Wrox book Beginning SharePoint 2010 Development by Steve Fox; ISBN: 978-0-470-58463-7
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning SharePoint 2010 Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 8th, 2010, 01:10 PM
Registered User
 
Join Date: Jul 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default MyFirstWebPart in VB

Just got this book and I am really enjoying it. However, I do most of my programming in VB while all the examples so far are in C#. It's not too hard to convert the code examples in VB, but I had a bit of a problem getting myFirstWebPart to run. However, it's working fine now, so I thought I'd add my VB version here just in case anyone else has trouble

Code:
Imports System
Imports System.ComponentModel
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.WebControls

<ToolboxItemAttribute(false)> _
Public Class MyFirstWebPart
    Inherits WebPart

    Dim lblUserEntry As Label = New Label
    Dim txtbxUserEntry As TextBox = New TextBox
    Dim lblFinalCost As Label = New Label
    Dim txtbxFinalCost As TextBox = New TextBox
    Dim btnCalcTax As Button = New Button
    Dim totalTax As Double = 0.0
    Dim prodTax As Double = 0.11


    Protected Overrides Sub CreateChildControls()

        lblUserEntry.Text = "Cost of Widget:"
        lblFinalCost.Text = "Final Cost:    "
        btnCalcTax.Text = "Calc."
        txtbxUserEntry.Text = "59.30"

        Me.Controls.Add(lblUserEntry)
        Me.Controls.Add(txtbxUserEntry)
        Me.Controls.Add(New LiteralControl("<p>"))
        Me.Controls.Add(lblFinalCost)
        Me.Controls.Add(txtbxFinalCost)
        Me.Controls.Add(New LiteralControl("<p>"))
        Me.Controls.Add(btnCalcTax)

        'From c#: btnCalcTax.Click += new EventHandler(btnCalcTax_Click)
        AddHandler btnCalcTax.Click, AddressOf btnCalcTax_Click

        'From c#: Base.CreateChildControls()
        MyBase.CreateChildControls()

    End Sub

    Private Sub btnCalcTax_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim prodCost As Double = Convert.ToDouble(txtbxUserEntry.Text)
        totalTax = Math.Round(prodCost - (prodCost * prodTax), 2) * 100 / 100
        txtbxFinalCost.Text = totalTax.ToString

    End Sub


Similar Threads
Thread Thread Starter Forum Replies Last Post
Running a VB 2005 exe file on a system without VB dilionyi Pro Visual Basic 2005 3 September 21st, 2009 07:37 PM
VB.NET 2003 Appendix B convert to VB 2008 Express Edition brucechess BOOK: Beginning VB.NET Databases 10 February 5th, 2009 12:52 PM
Crystal Reports 11 from VB to VB.net koushik_b2002 Crystal Reports 2 June 1st, 2008 01:58 AM
convert dsr file from vb to vb.net Shashi001 VB Components 1 September 22nd, 2006 12:24 PM
VB.Net/VB/Access97/Access2002 Comparison doveb VB.NET 4 October 10th, 2003 09:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.