顯示具有 Visual Basic 標籤的文章。 顯示所有文章
顯示具有 Visual Basic 標籤的文章。 顯示所有文章

2016年2月1日 星期一

在Web Application使用Add Reference 參考 Shared Project

 

Tool:Visual Studio 2015 Enterprise Update1
OS:Windows 10
Visual Basic

Shared Project可以讓你在不同類型的專案之中,共享程式碼。不過使用Visual Studio 2015 建立VB專案,在主控台類型程式,可以選取Project –> Add Reference – > Shared Project,就可以在Console專案中引用Shared Project:image

而在Web Application類型的專案中,則無此選項,沒法選到Shared Project:

image

 

 

2015年6月9日 星期二

Visual Studio 2015 IDE新功能 - VB14

Tool:Visual Studio 2015 Enterprise RC
OS:Windows Server 2012 R2

不管使用VB14或C#6專案,Visual Studio 2015 IDE提供的新功能都差不多,以下使用Visual Basic 14的主控台應用程式為例。

image

2012年5月15日 星期二

Visual Basic 11 新功能-方法多載


在Visual Studio 2010 撰寫Visual Basic 10程式時,若定義多載方法時,函式簽名只有差在一個Optional 參數;

Module Module1
    Sub Main()
        Console.WriteLine(Add(10))
        Console.WriteLine(Add(10, 20))
    End Sub
    Private Function Add(i As Integer) As Integer
        Return i
    End Function
    Private Function Add(i As Integer, Optional j As Integer = 0) As Integer
        Return i + j
    End Function
End Module

則編譯程式時,會出現錯誤
image
而在Visual Studio 11 Beta中 (Visual Basic 11),已經沒有這個限制了,當然程式也可以正常執行:
image

2011年10月5日 星期三

Visual Basic 匿名方法

 

Visual Basic 終於支援匿名方法

Module Module1
    Sub Main()
        Dim nameList = Function() As String
                           Return "Hi"
                       End Function
        Console.Write(nameList())
    End Sub
End Module

2009年6月17日 星期三

VB 10 的新語法

1.Auto-Implemented Properties 自動實作屬性



1 Module Module1

2 Property EmpName As String = "Mary"

3 Sub Main()

4 Console.WriteLine(EmpName)

5 End Sub

6 End Module


2.Collection Initializers & Statement Lambdas ,
除了3.5的Array Initializer之外,多了Collection Initializers

1 Module Module1

2 Sub Main()

3 '陣列初始設定式

4 Dim dataArr() As Integer = {1, 4, 23, 21, 34, 24}

5 Array.ForEach(dataArr, Sub(x)

6 Console.WriteLine(x)

7 End Sub)

8

9 '集合初始設定式

10 Dim dataCol As New List(Of Integer) From {1, 4, 23, 21, 34, 24}

11 dataCol.ForEach(Sub(x)

12 Console.WriteLine(x)

13 End Sub)

14 End Sub

15 End Module

2009年2月6日 星期五

Visual Basic可以直接操作XML

Visual Basic 2008可以直接操作XML,例如直接將XML片段指定給XElement :

1 Dim x As XElement = <employee>

2 <id>1id>

3 <name>Maryname>

4 employee>

5 MsgBox(x.ToString())


若不想把XML的文字資料寫死,可以改用Expression:

1 Dim emp As Employee = New Employee()

2 emp.ID = "1"

3 emp.Name = "Mary"

4 Dim x As XElement = <employee>

5 <id><%= emp.ID %>id>

6 <name><%= emp.Name %>name>

7 employee>

8 MsgBox(x.ToString())


Employee類別如下:

1 Class Employee

2 Public ID As Integer

3 Public Name As String

4 End Class

移除事件處理常式不必要的參數

在Visual Basic中事件處理常式會帶兩個參數,例如以下是Button的Click處理常式:

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

2

3 End Sub


若在Visual Basic 2008撰寫程式,不需要使用到sender與e參數的話,程式可以簡寫如下

1 Private Sub Button1_Click() Handles Button1.Click

2

3 End Sub


這是 Visual Basic 專用語法,C#不能用!

總網頁瀏覽量