免费观看又色又爽又黄的小说免费_美女福利视频国产片_亚洲欧美精品_美国一级大黄大色毛片

vb.net類計(jì)算 vbnet adodb

VB.NET怎么位運(yùn)算?

注意只能對(duì)整型執(zhí)行按位運(yùn)算。浮點(diǎn)值必須轉(zhuǎn)換為整型后,才能執(zhí)行按位運(yùn)算。按位運(yùn)算采用二進(jìn)制(以 2 為基)形式計(jì)算兩個(gè)整數(shù)值。它們比較對(duì)應(yīng)位置上的位,然后基于比較的結(jié)果賦值。下面的示例演示了 And 運(yùn)算符。復(fù)制Dim x As Integerx = 3 And 5 前面的示例將 x 的值設(shè)置為 1。發(fā)生這種情況的原因如下:這些值以二進(jìn)制形式處理:二進(jìn)制格式的 3 為 011二進(jìn)制格式的 5 為 101And 運(yùn)算符比較這些二進(jìn)制表示方式,一次比較一個(gè)二進(jìn)制位置(位)。如果給定位置的兩個(gè)位都為 1,則將 1 放在結(jié)果中的該位置。如果任何一個(gè)位是 0,則將 0 放在結(jié)果中的該位置。在前面的示例中,按如下所示計(jì)算結(jié)果:011(二進(jìn)制格式的 3)101(二進(jìn)制格式的 5)001(二進(jìn)制格式的計(jì)算結(jié)果)計(jì)算結(jié)果以十進(jìn)制形式處理。值 001 是 1 的二進(jìn)制表示形式,因此 x = 1。除了在任何一個(gè)比較位是 1 或兩個(gè)比較位都是 1 的情況下將 1 賦予結(jié)果位以外,按位 Or 運(yùn)算與此類似。Xor 在比較的位正好只有一個(gè)是 1(而不是兩者都是 1)時(shí)將 1 賦給結(jié)果位。Not 采用單個(gè)操作數(shù)并反轉(zhuǎn)所有位(包括符號(hào)位),然后將該值賦予結(jié)果。這意味著,對(duì)于有符號(hào)正數(shù),Not 始終返回負(fù)值,而對(duì)于負(fù)數(shù),Not 始終返回正值或零。AndAlso 和OrElse 運(yùn)算符不支持按位運(yùn)算。 追問(wèn): 好復(fù)雜啊...還是不會(huì),還有整數(shù)怎么轉(zhuǎn)換為二進(jìn)制數(shù)? 回答: 為什么一定要用位運(yùn)算呢,你那個(gè)乘法只能通過(guò)左移操作符“ ”來(lái)進(jìn)行,而左移一次代表乘以2,要是乘以一個(gè)小數(shù),就必須先化成2的n次方,不夠再用加減法調(diào)整,很麻煩啊,沒(méi)必要用位運(yùn)算啊。。。 追問(wèn): 因?yàn)槲乙M(jìn)行大量的運(yùn)算,但速度要快,所有用位運(yùn)算...我也不想啊.. 回答: 那就不該用VB 啊,c/c++在執(zhí)行效率上是沒(méi)話說(shuō)的。 追問(wèn): 問(wèn)題就是不會(huì)嘛... 回答: 那你上csdn上發(fā)帖效果應(yīng)該不錯(cuò) 追問(wèn): CSDN發(fā)了,我發(fā)在高性能運(yùn)算,沒(méi)人... 回答: 耐心一些,或者你應(yīng)該發(fā)到VB.NET論壇那里。。。 追問(wèn): 額..只能這樣了... 提問(wèn)者 的感言: 太復(fù)雜了..算了 2010-11-08

成都創(chuàng)新互聯(lián)公司主要從事網(wǎng)頁(yè)設(shè)計(jì)、PC網(wǎng)站建設(shè)(電腦版網(wǎng)站建設(shè))、wap網(wǎng)站建設(shè)(手機(jī)版網(wǎng)站建設(shè))、成都響應(yīng)式網(wǎng)站建設(shè)公司、程序開(kāi)發(fā)、網(wǎng)站優(yōu)化、微網(wǎng)站、小程序制作等,憑借多年來(lái)在互聯(lián)網(wǎng)的打拼,我們?cè)诨ヂ?lián)網(wǎng)網(wǎng)站建設(shè)行業(yè)積累了豐富的成都做網(wǎng)站、網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、網(wǎng)絡(luò)營(yíng)銷經(jīng)驗(yàn),集策劃、開(kāi)發(fā)、設(shè)計(jì)、營(yíng)銷、管理等多方位專業(yè)化運(yùn)作于一體。

vb.net 計(jì)算階層的代碼

我們用一個(gè)比較時(shí)髦的辦法,用面向?qū)ο笏枷氚衙恳恍凶龀梢粋€(gè)類。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

Class Value '聲明Value為類

REM 類的公共數(shù)據(jù)

Public Type As String '類型rb或是rf

Public ValX As Double '表第二列

Public ValY As Double '表第三列

Public Sub New(t As String, x As String, y As String) '構(gòu)造函數(shù)

Type = t '賦值

ValX = x

ValY = y

End Sub

REM 類的靜態(tài)方法,用來(lái)得出結(jié)果x=(12.1+12.4)/2+(12.2+12.3)/2

Public Shared Function SolveX(ByRef Values() As Value) As Double '以一個(gè)Value數(shù)組為參數(shù)

Dim result1 As Double = 0 '第一個(gè)加數(shù)(12.1+12.4)/2

Dim count1 As Integer = 0 'rb的個(gè)數(shù)

For Each v In Values '遍歷這個(gè)數(shù)組

If v.Type = "rb" Then '若是rb

result1 += v.ValX '先加進(jìn)去

count1 += 1 '個(gè)數(shù)加一。也可以寫成count1 = count1 + 1

End If

Next

result1 /= count1 '算出第一個(gè)加數(shù)。也可以寫成result1 = result1 / count

Dim result2 As Double = 0 '依此類推,算出第二個(gè)加數(shù)

Dim count2 As Integer = 0

For Each v In Values

If v.Type = "rf" Then

result2 += v.ValX

count2 += 1

End If

Next

result2 /= count2

Return result1 + result2 '返回兩個(gè)加數(shù)的和

End Function

REM 同樣的

Public Shared Function SolveY(ByRef Values() As Value) As Double

Dim result1 As Double = 0

Dim count1 As Integer = 0

For Each v In Values

If v.Type = "rb" Then

result1 += v.ValY

count1 += 1

End If

Next

result1 /= count1

Dim result2 As Double = 0

Dim count2 As Integer = 0

For Each v In Values

If v.Type = "rf" Then

result2 += v.ValY

count2 += 1

End If

Next

result2 /= count2

Return result1 - result2

End Function

End Class

怎么使用這個(gè)類呢?

1

2

3

4

5

6

7

8

9

10

11

12

13

Dim values() As Value = {New Value("rb", 12.1, 1.1), _

New Value("rf", 12.2, 1.2), _

New Value("rf", 12.3, 1.3), _

New Value("rb", 12.4, 1.4)} '聲明一個(gè)數(shù)組values并一次放入4個(gè)Value對(duì)象

Console.WriteLine("X = {0}", Value.SolveX(values)) 'Value.SolveX(數(shù)組)表示X結(jié)果

Console.WriteLine("Y = {0}", Value.SolveY(values)) 'Value.SolveY(數(shù)組)表示Y結(jié)果

Console.ReadKey()

用VB.NET編的計(jì)算器程序!

Public Class SimpleCalculator

Inherits System.Windows.Forms.Form

#Region " Windows 窗體設(shè)計(jì)器生成的代碼 "

Public Sub New()

MyBase.New()

'該調(diào)用是 Windows 窗體設(shè)計(jì)器所必需的。

InitializeComponent()

'在 InitializeComponent() 調(diào)用之后添加任何初始化

End Sub

'窗體重寫處置以清理組件列表。

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Windows 窗體設(shè)計(jì)器所必需的

Private components As System.ComponentModel.IContainer

'注意:以下過(guò)程是 Windows 窗體設(shè)計(jì)器所必需的

'可以使用 Windows 窗體設(shè)計(jì)器修改此過(guò)程。

'不要使用代碼編輯器修改它。

Friend WithEvents Label1 As System.Windows.Forms.Label

Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

Friend WithEvents Button1 As System.Windows.Forms.Button

Friend WithEvents Button2 As System.Windows.Forms.Button

Friend WithEvents Button3 As System.Windows.Forms.Button

Friend WithEvents Button4 As System.Windows.Forms.Button

Friend WithEvents Button5 As System.Windows.Forms.Button

Friend WithEvents Button6 As System.Windows.Forms.Button

Friend WithEvents Button7 As System.Windows.Forms.Button

Friend WithEvents Button8 As System.Windows.Forms.Button

Friend WithEvents Button9 As System.Windows.Forms.Button

Friend WithEvents Button10 As System.Windows.Forms.Button

Friend WithEvents Button11 As System.Windows.Forms.Button

Friend WithEvents Button12 As System.Windows.Forms.Button

Friend WithEvents Button13 As System.Windows.Forms.Button

Friend WithEvents Button14 As System.Windows.Forms.Button

Friend WithEvents Button15 As System.Windows.Forms.Button

Friend WithEvents Button16 As System.Windows.Forms.Button

System.Diagnostics.DebuggerStepThrough() Private Sub InitializeComponent()

Me.Label1 = New System.Windows.Forms.Label

Me.TextBox1 = New System.Windows.Forms.TextBox

Me.Button1 = New System.Windows.Forms.Button

Me.Button2 = New System.Windows.Forms.Button

Me.Button3 = New System.Windows.Forms.Button

Me.Button4 = New System.Windows.Forms.Button

Me.Button5 = New System.Windows.Forms.Button

Me.Button6 = New System.Windows.Forms.Button

Me.Button7 = New System.Windows.Forms.Button

Me.Button8 = New System.Windows.Forms.Button

Me.Button9 = New System.Windows.Forms.Button

Me.Button10 = New System.Windows.Forms.Button

Me.Button11 = New System.Windows.Forms.Button

Me.Button12 = New System.Windows.Forms.Button

Me.Button13 = New System.Windows.Forms.Button

Me.Button14 = New System.Windows.Forms.Button

Me.Button15 = New System.Windows.Forms.Button

Me.Button16 = New System.Windows.Forms.Button

Me.SuspendLayout()

'

'Label1

'

Me.Label1.Location = New System.Drawing.Point(16, 16)

Me.Label1.Name = "Label1"

Me.Label1.Size = New System.Drawing.Size(48, 16)

Me.Label1.TabIndex = 0

Me.Label1.Text = "結(jié)果:"

'

'TextBox1

'

Me.TextBox1.Location = New System.Drawing.Point(64, 8)

Me.TextBox1.Name = "TextBox1"

Me.TextBox1.Size = New System.Drawing.Size(120, 21)

Me.TextBox1.TabIndex = 1

Me.TextBox1.Text = ""

'

'Button1

'

Me.Button1.Location = New System.Drawing.Point(200, 8)

Me.Button1.Name = "Button1"

Me.Button1.Size = New System.Drawing.Size(56, 24)

Me.Button1.TabIndex = 2

Me.Button1.Text = "清空"

'

'Button2

'

Me.Button2.Location = New System.Drawing.Point(48, 56)

Me.Button2.Name = "Button2"

Me.Button2.Size = New System.Drawing.Size(24, 24)

Me.Button2.TabIndex = 3

Me.Button2.Text = "1"

'

'Button3

'

Me.Button3.Location = New System.Drawing.Point(88, 56)

Me.Button3.Name = "Button3"

Me.Button3.Size = New System.Drawing.Size(24, 24)

Me.Button3.TabIndex = 4

Me.Button3.Text = "2"

'

'Button4

'

Me.Button4.Location = New System.Drawing.Point(136, 56)

Me.Button4.Name = "Button4"

Me.Button4.Size = New System.Drawing.Size(24, 24)

Me.Button4.TabIndex = 5

Me.Button4.Text = "3"

'

'Button5

'

Me.Button5.Location = New System.Drawing.Point(48, 88)

Me.Button5.Name = "Button5"

Me.Button5.Size = New System.Drawing.Size(24, 24)

Me.Button5.TabIndex = 6

Me.Button5.Text = "4"

'

'Button6

'

Me.Button6.Location = New System.Drawing.Point(88, 88)

Me.Button6.Name = "Button6"

Me.Button6.Size = New System.Drawing.Size(24, 24)

Me.Button6.TabIndex = 7

Me.Button6.Text = "5"

'

'Button7

'

Me.Button7.Location = New System.Drawing.Point(136, 88)

Me.Button7.Name = "Button7"

Me.Button7.Size = New System.Drawing.Size(24, 24)

Me.Button7.TabIndex = 8

Me.Button7.Text = "6"

'

'Button8

'

Me.Button8.Location = New System.Drawing.Point(48, 120)

Me.Button8.Name = "Button8"

Me.Button8.Size = New System.Drawing.Size(24, 24)

Me.Button8.TabIndex = 9

Me.Button8.Text = "7"

'

'Button9

'

Me.Button9.Location = New System.Drawing.Point(88, 120)

Me.Button9.Name = "Button9"

Me.Button9.Size = New System.Drawing.Size(24, 24)

Me.Button9.TabIndex = 10

Me.Button9.Text = "8"

'

'Button10

'

Me.Button10.Location = New System.Drawing.Point(136, 120)

Me.Button10.Name = "Button10"

Me.Button10.Size = New System.Drawing.Size(24, 24)

Me.Button10.TabIndex = 11

Me.Button10.Text = "9"

'

'Button11

'

Me.Button11.Location = New System.Drawing.Point(48, 152)

Me.Button11.Name = "Button11"

Me.Button11.Size = New System.Drawing.Size(24, 24)

Me.Button11.TabIndex = 12

Me.Button11.Text = "0"

'

'Button12

'

Me.Button12.Location = New System.Drawing.Point(176, 56)

Me.Button12.Name = "Button12"

Me.Button12.Size = New System.Drawing.Size(24, 24)

Me.Button12.TabIndex = 13

Me.Button12.Text = "+"

'

'Button13

'

Me.Button13.Location = New System.Drawing.Point(176, 88)

Me.Button13.Name = "Button13"

Me.Button13.Size = New System.Drawing.Size(24, 24)

Me.Button13.TabIndex = 14

Me.Button13.Text = "-"

'

'Button14

'

Me.Button14.Location = New System.Drawing.Point(176, 120)

Me.Button14.Name = "Button14"

Me.Button14.Size = New System.Drawing.Size(24, 24)

Me.Button14.TabIndex = 15

Me.Button14.Text = "*"

'

'Button15

'

Me.Button15.Location = New System.Drawing.Point(176, 152)

Me.Button15.Name = "Button15"

Me.Button15.Size = New System.Drawing.Size(24, 24)

Me.Button15.TabIndex = 16

Me.Button15.Text = "/"

'

'Button16

'

Me.Button16.Location = New System.Drawing.Point(88, 152)

Me.Button16.Name = "Button16"

Me.Button16.Size = New System.Drawing.Size(72, 24)

Me.Button16.TabIndex = 17

Me.Button16.Text = "計(jì)算"

'

'SimpleCalculator

'

Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)

Me.ClientSize = New System.Drawing.Size(264, 190)

Me.Controls.Add(Me.Button16)

Me.Controls.Add(Me.Button15)

Me.Controls.Add(Me.Button14)

Me.Controls.Add(Me.Button13)

Me.Controls.Add(Me.Button12)

Me.Controls.Add(Me.Button11)

Me.Controls.Add(Me.Button10)

Me.Controls.Add(Me.Button9)

Me.Controls.Add(Me.Button8)

Me.Controls.Add(Me.Button7)

Me.Controls.Add(Me.Button6)

Me.Controls.Add(Me.Button5)

Me.Controls.Add(Me.Button4)

Me.Controls.Add(Me.Button3)

Me.Controls.Add(Me.Button2)

Me.Controls.Add(Me.Button1)

Me.Controls.Add(Me.TextBox1)

Me.Controls.Add(Me.Label1)

Me.Name = "SimpleCalculator"

Me.Text = "簡(jiǎn)單計(jì)算器"

Me.ResumeLayout(False)

End Sub

#End Region

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

Private Sub TextBox1_TabStopChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim btn As Button '按鈕類型的變量

btn = sender '把產(chǎn)生該事件的按鈕對(duì)象賦值給btn

TextBox1.Text = TextBox1.Text + btn.Text '把該按鈕的Text屬性值連接到TextBox1中

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Dim btn As Button

btn = sender

TextBox1.Text += btn.Text

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

Dim btn As Button

btn = sender

TextBox1.Text += btn.Text

End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

Dim btn As Button

btn = sender

TextBox1.Text += btn.Text

End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

Dim btn As Button

btn = sender

TextBox1.Text += btn.Text

End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click

Dim btn As Button

btn = sender

TextBox1.Text += btn.Text

End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click

Dim btn As Button

btn = sender

TextBox1.Text += btn.Text

End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click

Dim btn As Button

btn = sender

TextBox1.Text += btn.Text

End Sub

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click

Dim btn As Button

btn = sender

TextBox1.Text += btn.Text

End Sub

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click

Dim btn As Button

btn = sender

TextBox1.Text += btn.Text

End Sub

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click

Dim btn As Button

btn = sender

'在文本框的Text屬性后連接一個(gè)空格、本按鈕的Text屬性值和一個(gè)空格

TextBox1.Text = TextBox1.Text + " " + btn.Text + " "

End Sub

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

TextBox1.Text = "" '清空文本框

End Sub

Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click

Dim btn As Button

btn = sender

TextBox1.Text = TextBox1.Text + " " + btn.Text + " "

End Sub

Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click

Dim btn As Button

btn = sender

TextBox1.Text = TextBox1.Text + " " + btn.Text + " "

End Sub

Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click

Dim btn As Button

btn = sender

TextBox1.Text = TextBox1.Text + " " + btn.Text + " "

End Sub

Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click

'發(fā)生錯(cuò)誤轉(zhuǎn)移到標(biāo)號(hào)“ErrorPro”指定的行去執(zhí)行錯(cuò)誤處理程序

On Error GoTo ErrorPro

Dim r As Decimal '保存計(jì)算結(jié)果的變量

Dim t As String = TextBox1.Text '用于保存文本框中的算術(shù)表達(dá)式

Dim space As Integer = t.IndexOf(" ") '搜索空格位置,如果沒(méi)有空格,返回值為0

'字符串的取子符方法,第二個(gè)參數(shù)小于0,則將產(chǎn)生錯(cuò)誤號(hào)為5的異常,即過(guò)程參數(shù)不正確

Dim s1 As String = t.Substring(0, space) '通過(guò)取子串方法獲得第一個(gè)運(yùn)算數(shù)

Dim op As String = t.Substring(space + 1, 1) '通過(guò)取子串方法獲得運(yùn)算符

Dim s2 As String = t.Substring(space + 3) '通過(guò)取子串方法獲得第二個(gè)運(yùn)算數(shù)

Dim arg1, arg2 As Integer

arg1 = Val(s1) : arg2 = Val(s2)

Select Case op

Case "+" : r = arg1 + arg2

Case "-" : r = arg1 - arg2

Case "*" : r = arg1 * arg2

Case "/" : r = arg1 / arg2

Case Else

MsgBox("輸入的運(yùn)算符有誤!")

Exit Sub

End Select

TextBox1.Text = CStr(r) '顯示結(jié)果

Exit Sub '退出過(guò)程

ErrorPro: '錯(cuò)誤處理程序塊

Select Case Err.Number

Case 6 '除數(shù)為零時(shí),或運(yùn)算溢出時(shí)的錯(cuò)誤號(hào)

MsgBox("算術(shù)運(yùn)算溢出!", , "溢出提示")

TextBox1.Focus()

Exit Sub

Case 5 ' Substring過(guò)程的參數(shù)不符合要求的錯(cuò)誤號(hào)

MsgBox("必須輸入運(yùn)算符和第二個(gè)運(yùn)算數(shù)!", , "運(yùn)算數(shù)少")

Exit Sub

Case Else

'其它情況顯示錯(cuò)誤號(hào)和錯(cuò)誤原因

MsgBox("錯(cuò)誤號(hào)為" Err.Number Chr(10) Chr(13) "錯(cuò)誤原因:" Err.Description)

Exit Sub

End Select

End Sub

End Class

本文標(biāo)題:vb.net類計(jì)算 vbnet adodb
轉(zhuǎn)載來(lái)于:http://m.newbst.com/article4/doiheoe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊(cè)關(guān)鍵詞優(yōu)化移動(dòng)網(wǎng)站建設(shè)響應(yīng)式網(wǎng)站網(wǎng)站制作企業(yè)網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)