资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vb.net常用代码集,VB常用代码

求VB.NET对任一excel表格查找替换的代码。

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

成都创新互联专注为客户提供全方位的互联网综合服务,包含不限于做网站、成都网站制作、会泽网络推广、小程序开发、会泽网络营销、会泽企业策划、会泽品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;成都创新互联为所有大学生创业者提供会泽建站搭建服务,24小时服务热线:18980820575,官方网址:www.cdcxhl.com

'On Error GoTo EXIT_ERROR

Dim strErrorPos As String = "F_TreatOne"

Dim strFileName As String

strFileName = "d:\test.xlsx"

Dim objExcelApp As New Microsoft.Office.Interop.Excel.Application

Dim objWorkBook As Microsoft.Office.Interop.Excel.Workbook

Dim objSheet As Microsoft.Office.Interop.Excel.Worksheet

objWorkBook = objExcelApp.Workbooks.Open(strFileName)

objSheet = objWorkBook.Worksheets(1)

objSheet.UsedRange.Replace("aaa", "bbb")

objWorkBook.Save()

objWorkBook.Close()

objExcelApp.Quit()

objWorkBook = Nothing

objExcelApp = Nothing

End Sub

需要的话,自已再适当修改修改.

项目中需要加对Microsoft.Office.Interop.Excel的引用.

用vb.net编写记事本源代码

Dim sFileName As String

Dim Search

Private Sub dateTimeMenu_Click()

Text1.Text = Now

End Sub

Private Sub deleteMenu_Click()

Text1.Text = Left(Text1.Text, Text1.SelStart) + Mid(Text1.Text, Text1.SelStart + Text1.SelLength + 1)

End Sub

Private Sub findMenu_Click()

Search = InputBox("请输入要查找的字词:")

Dim Where1 '获取需要查找的字符串变量

Text1.SetFocus '文本框获得焦点,以显示所找到的内容Search = InputBox("请输入要查找的字词:")

Where1 = InStr(Text1.Text, Search) '在文本中查找字符串

If Where1 Then

'若找到则设置选定的起始位置并使找到的字符串高亮

Text1.SelStart = Where1 - 1

Text1.SelLength = Len(Search)

' Me.Caption = Where1 '测试用

'否则给出提示

Else: MsgBox "未找到所要查找的字符串。", vbInformation, "提示"

End If

End Sub

Private Sub findNextMenu_Click()

Dim Where2

Dim StartMe As Integer '查找的起始位置变量

Text1.SetFocus '文本框获得焦点

StartMe = Text1.SelLength + Text1.SelStart + 1 '给变量赋值

Where2 = InStr(StartMe, Text1.Text, Search) '令其从上次找到的地方找起

If Where2 Then

Text1.SelStart = Where2 - 1

Text1.SelLength = Len(Search)

Else: MsgBox "未找到所要查找的字符串.", vbInformation, "提示"

End If

End Sub

Private Sub aboutMenu_Click()

MsgBox Space(2) "文本编辑器版本号1.0" Chr(13) "由西南财经大学天府学院" Chr(13) Space(5) "肖忠 开发" Chr(13) Space(2) "copyright:天府学院"

End Sub

Private Sub allMenu_Click()

Text1.SelStart = 0

Text1.SelLength = Len(Text1.Text)

End Sub

Private Sub backcolorMenu_Click() '设置背景色代码

Form1.CommonDialog1.Action = 3

Text1.BackColor = Form1.CommonDialog1.Color

End Sub

Private Sub colorMenu_Click() '改变文字颜色代码

Form1.CommonDialog1.Action = 3

Text1.ForeColor = Form1.CommonDialog1.Color

End Sub

Private Sub cutMenu_Click()

Clipboard.SetText Text1.SelText

Text1.Text = Left(Text1.Text, Text1.SelStart) + Mid(Text1.Text, Text1.SelStart + Text1.SelLength + 1)

End Sub

Private Sub exitMenu_Click()

End

End Sub

Private Sub fontMenu_Click() '字体菜单代码

Form1.CommonDialog1.Flags = 3 Or 256

Form1.CommonDialog1.Action = 4

If Len(Form1.CommonDialog1.FontName) = 0 Then

Form1.Text1.FontName = "宋体"

Else

Form1.Text1.FontName = Form1.CommonDialog1.FontName

End If

Form1.Text1.FontSize = Form1.CommonDialog1.FontSize

If Form1.CommonDialog1.FontBold = True Then

Form1.Text1.FontBold = True

Else

Form1.Text1.FontBold = False

End If

If Form1.CommonDialog1.FontItalic = True Then

Form1.Text1.FontItalic = True

Else

Form1.Text1.FontItalic = False

End If

Text1.ForeColor = Form1.CommonDialog1.Color

End Sub

Private Sub Form_Load()

Form1.Text1.Width = Form1.Width - 130

Form1.Text1.Height = Form1.Height

End Sub

Private Sub Form_Resize()

Form1.Text1.Width = Form1.Width - 130

Form1.Text1.Height = Form1.Height

End Sub

Private Sub help1Menu_Click()

Form1.CommonDialog1.HelpCommand = cdlHelpForceFile

Form1.CommonDialog1.HelpFile = "c:\windows\system32\winhelp.hlp"

CommonDialog1.ShowHelp

End Sub

Private Sub newMenu_Click()

If Len(Trim(Text1.Text)) = 0 Then

Form1.Caption = "我的记事本" "--" "未命名"

sFileName = "未命名"

Text1.FontSize = 15

Text1.FontName = "宋体"

Text1.Text = ""

Else

Call saveAsMenu_Click

Form1.Caption = "我的记事本" "--" "未命名"

sFileName = "未命名"

Text1.FontSize = 15

Text1.FontName = "宋体"

Text1.Text = ""

End If

End Sub

Private Sub openMenu_Click() '打开文件代码

If Len(Trim(Text1.Text)) = 0 Then

Form1.Caption = "我的记事本"

Form1.CommonDialog1.Filter = "文本文件|*.txt"

Form1.CommonDialog1.Flags = 4096

Form1.CommonDialog1.Action = 1

If Len(Form1.CommonDialog1.FileName) 0 Then

sFileName = Form1.CommonDialog1.FileName

Form1.Caption = Form1.Caption "--" Form1.CommonDialog1.FileTitle

Open sFileName For Input As #1

Text1.FontSize = 15

Text1.FontName = "宋体"

Do While Not EOF(1)

Line Input #1, Text$

All$ = All$ + Text$ + Chr(13) + Chr(10)

Loop

Text1.Text = All

Close #1

End If

Else

Call saveAsMenu_Click

Form1.Caption = "我的记事本"

Form1.CommonDialog1.Filter = "文本文件|*.txt"

Form1.CommonDialog1.Flags = 4096

Form1.CommonDialog1.Action = 1

If Len(Form1.CommonDialog1.FileName) 0 Then

sFileName = Form1.CommonDialog1.FileName

Form1.Caption = Form1.Caption "--" Form1.CommonDialog1.FileTitle

Open sFileName For Input As #1

Text1.FontSize = 15

Text1.FontName = "宋体"

Do While Not EOF(1)

Line Input #1, Text$

All$ = All$ + Text$ + Chr(13) + Chr(10)

Loop

Text1.Text = All

Close #1

End If

End If

End Sub

Private Sub pasteMenu_Click() '粘贴菜单代码

Text1.Text = Left(Text1.Text, Text1.SelStart) + Clipboard.GetText() + Mid(Text1.Text, Text1.SelStart + Text1.SelLength + 1)

End Sub

Private Sub printMenu_Click()

Form1.CommonDialog1.ShowPrinter

For i = 1 To CommonDialog1.Copies

Printer.Print Text1.Text

Printer.Print Text1.Text

Next

Printer.EndDoc

End Sub

Private Sub saveAsMenu_Click() '另存为菜单代码

If Len(Trim(Text1.Text)) 0 Then

Form1.CommonDialog1.DialogTitle = "保存文件"

Form1.CommonDialog1.InitDir = "D:\"

Form1.CommonDialog1.Filter = "文本文件|*.txt"

Form1.CommonDialog1.Flags = 2

Form1.CommonDialog1.ShowSave

If Len(Form1.CommonDialog1.FileName) 0 Then

sFileName = Form1.CommonDialog1.FileName

Open sFileName For Output As #1

whole$ = Text1.Text

Print #1, whole

Close #1

End If

End If

End Sub

Private Sub saveMenu_Click()

If Len(Trim(Text1.Text)) 0 Then

Form1.CommonDialog1.DialogTitle = "保存文件"

Form1.CommonDialog1.InitDir = "D:\"

Form1.CommonDialog1.FileName = "新建文本"

Form1.CommonDialog1.Filter = "文本文件|*.txt"

Form1.CommonDialog1.Flags = 2

Form1.CommonDialog1.ShowSave

If Len(Form1.CommonDialog1.FileName) 0 Then

sFileName = Form1.CommonDialog1.FileName

Open sFileName For Output As #1

whole$ = Text1.Text

Print #1, whole

Close #1

End If

End If

End Sub

Private Sub statusMenu_Click()

End Sub

vb.net vs2008中,如何把常用代码编写成一个模块,然后在不同的窗体中调用?

我的思路是,新建一个“类库”项目,在项目里编写一个类,然后生成,就会得到dll文件。在别的项目里,添加对这个dll文件的引用,就可以使用我们编写的类了。

求vb.net的源代码,最好说明其解决问题,越多越好,满意加50分。

下面这段代码,是我用来计算每个月存500元进银行,连续30年,最后连本带利能有多少钱。这里面涉及复利计算。界面中右边的文本框用来输出每一次计算的结果。

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

  Dim nianxian As Integer '年限变量

  Dim dingcun As Integer '定存变量

  Dim fuli_big As Long '大复利

  Dim fuli_small As Long '小复利

  Dim i As Integer '循环变量

  Dim DATAstring As String '数据字符串

  nianxian = Val(年限_TextBox.Text)

  dingcun = Val(定存_TextBox.Text)

  DATAstring = ""

  For i = 1 To nianxian

      fuli_small = dingcun * (1 + 0.1875)

      dingcun = fuli_small

      fuli_big = fuli_big + fuli_small

      DATAstring = DATAstring + "[" + Trim(Str(i)) + "]" + Str(fuli_big) + Chr(13) + Chr(10)

      'DATAstring = DATAstring + "[" + Trim(Str(i)) + "]" + Str(fuli_small) + Chr(13) + Chr(10)

  Next

  'fuli_big = fuli_small

  TextBox1.Text = DATAstring

  结果_TextBox.Text = Str(fuli_big) + "元"

End Sub

vb.net编写的贪吃蛇游戏,带代码的

需用VB实现,代码如下

'定义蛇的运动速度枚举值

Private Enum tpsSpeed

QUICKLY = 0

SLOWLY = 1

End Enum

'定义蛇的运动方向枚举值

Private Enum tpsDirection

D_UP = 38

D_DOWN = 40

D_LEFT = 37

D_RIGHT = 39

End Enum

'定义运动区域4个禁区的枚举值

Private Enum tpsForbiddenZone

FZ_TOP = 30

FZ_BOTTOM = 5330

FZ_LEFT = 30

FZ_RIGHT = 5730

End Enum

'定义蛇头及身体初始化数枚举值

Private Enum tpsSnake

SNAKEONE = 1

SNAKETWO = 2

SNAKETHREE = 3

SNAKEFOUR = 4

End Enum

'定义蛇宽度的常量

Private Const SNAKEWIDTH As Integer = 100

'该过程用于显示游戏信息

Private Sub Form_Load()

Me.Show

Me.lblTitle = "BS贪食蛇 — (版本 " App.Major "." App.Minor "." App.Revision ")"

Me.Caption = Me.lblTitle.Caption

frmSplash.Show 1

End Sub

'该过程用于使窗体恢复原始大小

Private Sub Form_Resize()

If Me.WindowState 1 Then

Me.Caption = ""

Me.Height = 6405 '窗体高度为 6405 缇

Me.Width = 8535 '窗体宽度为 8535 缇

Me.Left = (Screen.Width - Width) \ 2

Me.Top = (Screen.Height - Height) \ 2

End If

End Sub

'该过程用于重新开始开始游戏

Private Sub cmdGameStart_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Beep

msg = MsgBox("您确认要重新开始游戏吗?", 4 + 32, "BS贪食蛇")

If msg = 6 Then Call m_subGameInitialize

End Sub

'该过程用于暂停/运行游戏

Private Sub chkPause_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Me.chkPause.Caption = "暂停游戏(P)" Then

Me.tmrSnakeMove.Enabled = False

Me.tmrGameTime.Enabled = False

Me.picMoveArea.Enabled = False

Me.lblPauseLab.Visible = True

Me.chkPause.Caption = "继续游戏(R)"

Else

Me.tmrSnakeMove.Enabled = True

Me.tmrGameTime.Enabled = True

Me.picMoveArea.Enabled = True

Me.lblPauseLab.Visible = False

Me.chkPause.Caption = "暂停游戏(P)"

End If

End Sub

'该过程用于显示游戏规则

Private Sub cmdGameRules_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Beep

MsgBox " BS贪食蛇:一个规则最简单的趣味游戏,您将用键盘" Chr(13) _

"上的4个方向键来控制蛇的运动方向。在运动过程中蛇" Chr(13) _

"不能后退,蛇的头部也不能接触到运动区域的边线以外" Chr(13) _

"和蛇自己的身体,否则就游戏失败。在吃掉随机出现的" Chr(13) _

"果子后,蛇的身体会变长,越长难度越大。祝您好运!!", 0 + 64, "游戏规则"

End Sub

'该过程用于显示游戏开发信息

Private Sub cmdAbout_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Beep

MsgBox "BS贪食蛇" "(V-" App.Major "." App.Minor "版本)" Chr(13) Chr(13) _

"" Chr(13) Chr(13) _

"由PigheadPrince设计制作" Chr(13) _

"CopyRight(C)2002,BestSoft.TCG", 0, "关于本游戏"

End Sub

'该过程用于退出游戏

Private Sub cmdExit_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Beep

msg = MsgBox("您要退出本游戏吗?", 4 + 32, "BS贪食蛇")

Select Case msg

Case 6

End

Case 7

Me.chkWindowButton(2).Value = 0

Exit Sub

End Select

End Sub

'该过程用于拖动窗体_(点击图标)

Private Sub imgWindowTop_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

ReleaseCapture

SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MOVE, 0

End Sub

'该共用过程用于处理窗体控制按钮组的相关操作_(锁定、最小化、退出)

Private Sub chkWindowButton_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button 1 Then Exit Sub

Select Case Index

Case 0 '锁定窗体

If Me.chkWindowButton(0).Value = 1 Then

Me.imgWindowTop.BorderStyle = 0

Me.imgWindowTop.Enabled = False

Else

Me.imgWindowTop.BorderStyle = 1

Me.imgWindowTop.Enabled = True

End If

Case 1 '最小化

Me.WindowState = 1

Me.chkWindowButton(1).Value = 0

Me.Caption = "BS贪食蛇 — (V-" App.Major "." App.Minor "版本)"

Case 2 '退出

Beep

msg = MsgBox("您要退出本游戏吗?", 4 + 32, "BS贪食蛇")

Select Case msg

Case 6

End

Case 7

Me.chkWindowButton(2).Value = 0

Exit Sub

End Select

End Select

End Sub

'该过程用于设置蛇运动速度的快慢

Private Sub hsbGameSpeed_Change()

Me.tmrSnakeMove.Interval = Me.hsbGameSpeed.Value

End Sub

'该过程用于通过键盘的方向键改变蛇的运动方向

Private Sub picMoveArea_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case g_intDirection

Case D_UP

If KeyCode = D_DOWN Then Exit Sub

Case D_DOWN

If KeyCode = D_UP Then Exit Sub

Case D_LEFT

If KeyCode = D_RIGHT Then Exit Sub

Case D_RIGHT

If KeyCode = D_LEFT Then Exit Sub

End Select

g_intDirection = KeyCode

End Sub

'该计时循环过程用于计算游戏耗费的秒数并显示

Private Sub tmrGameTime_Timer()

g_lngGameTime = g_lngGameTime + 1

Me.lblGameTime.Caption = g_lngGameTime "秒"

End Sub

'该计时循环过程用于控制蛇的行动轨迹

Private Sub tmrSnakeMove_Timer()

Dim lngSnakeX As Long, lngSnakeY As Long, lngSnakeColor As Long

Dim lngPointX As Long, lngPointY As Long, lngPointColor As Long

Randomize

Me.picMoveArea.SetFocus

Me.picMoveArea.Cls

'确认蛇头的运动方向并获取新的位置

Select Case g_intDirection

Case D_UP '向上运动

g_udtSnake(SNAKEONE).Snake_CurX = g_udtSnake(SNAKEONE).Snake_OldX

g_udtSnake(SNAKEONE).Snake_CurY = g_udtSnake(SNAKEONE).Snake_OldY

g_udtSnake(SNAKEONE).Snake_CurY = g_udtSnake(SNAKEONE).Snake_CurY - SNAKEWIDTH

Case D_DOWN '向下运动

g_udtSnake(SNAKEONE).Snake_CurX = g_udtSnake(SNAKEONE).Snake_OldX

g_udtSnake(SNAKEONE).Snake_CurY = g_udtSnake(SNAKEONE).Snake_OldY

g_udtSnake(SNAKEONE).Snake_CurY = g_udtSnake(SNAKEONE).Snake_CurY + SNAKEWIDTH

Case D_LEFT '向左运动

g_udtSnake(SNAKEONE).Snake_CurX = g_udtSnake(SNAKEONE).Snake_OldX

g_udtSnake(SNAKEONE).Snake_CurX = g_udtSnake(SNAKEONE).Snake_CurX - SNAKEWIDTH

g_udtSnake(SNAKEONE).Snake_CurY = g_udtSnake(SNAKEONE).Snake_OldY

Case D_RIGHT '向右运动

g_udtSnake(SNAKEONE).Snake_CurX = g_udtSnake(SNAKEONE).Snake_OldX

g_udtSnake(SNAKEONE).Snake_CurX = g_udtSnake(SNAKEONE).Snake_CurX + SNAKEWIDTH

g_udtSnake(SNAKEONE).Snake_CurY = g_udtSnake(SNAKEONE).Snake_OldY

End Select

'根据新的位置绘制蛇头

lngSnakeX = g_udtSnake(SNAKEONE).Snake_CurX

lngSnakeY = g_udtSnake(SNAKEONE).Snake_CurY

lngSnakeColor = g_udtSnake(SNAKEONE).Snake_Color

Me.picMoveArea.PSet (lngSnakeX, lngSnakeY), lngSnakeColor

'移动蛇身体其他部分的位置

For i = 2 To g_intSnakeLength

g_udtSnake(i).Snake_CurX = g_udtSnake(i - 1).Snake_OldX

g_udtSnake(i).Snake_CurY = g_udtSnake(i - 1).Snake_OldY

lngSnakeX = g_udtSnake(i).Snake_CurX

lngSnakeY = g_udtSnake(i).Snake_CurY

lngSnakeColor = g_udtSnake(i).Snake_Color

Me.picMoveArea.PSet (lngSnakeX, lngSnakeY), lngSnakeColor

Next i

'更新蛇旧的坐标位置

For j = 1 To g_intSnakeLength

g_udtSnake(j).Snake_OldX = g_udtSnake(j).Snake_CurX

g_udtSnake(j).Snake_OldY = g_udtSnake(j).Snake_CurY

Next j

'判断蛇在移动中是否到了禁区而导致游戏失败

If m_funMoveForbiddenZone(g_udtSnake(SNAKEONE).Snake_CurX, g_udtSnake(SNAKEONE).Snake_CurY) Then

Beep

MsgBox "您的蛇移动到了禁区,游戏失败!", 0 + 16, "BS贪食蛇"

Me.tmrSnakeMove.Enabled = False

Me.tmrGameTime.Enabled = False

Me.picMoveArea.Visible = False

Exit Sub

End If

'判断蛇在移动中是否碰到了自己的身体而导致游戏失败

If m_funTouchSnakeBody(g_udtSnake(SNAKEONE).Snake_CurX, g_udtSnake(SNAKEONE).Snake_CurY) Then

Beep

MsgBox "您的蛇在移动中碰到了自己的身体,游戏失败!", 0 + 16, "BS贪食蛇"

Me.tmrSnakeMove.Enabled = False

Me.tmrGameTime.Enabled = False

Me.picMoveArea.Visible = False

Exit Sub

End If

'判断蛇是否吃到了果子

If m_funEatPoint(g_udtSnake(SNAKEONE).Snake_CurX, g_udtSnake(SNAKEONE).Snake_CurY) Then

'累加玩家的得分并刷新得分显示

g_intPlayerScore = g_intPlayerScore + 1

Me.lblYourScore.Caption = g_intPlayerScore "分"

Call m_subAddSnake '加长蛇的身体

Call m_subGetPoint '获取下一个果子的位置和颜色

Else

'绘制果子

lngPointX = g_udtPoint.Point_X

lngPointY = g_udtPoint.Point_Y

lngPointColor = g_udtPoint.Point_Color

Me.picMoveArea.PSet (lngPointX, lngPointY), lngPointColor

End If

End Sub

'该私有子过程用于初始化游戏

Private Sub m_subGameInitialize()

Erase g_udtSnake '清空蛇的结构数组

g_intPlayerScore = 0 '清空玩家的得分

g_lngGameTime = 0 '清空游戏耗费的秒数

g_intDirection = D_DOWN '设定蛇的初始运动方向为下

g_intSnakeLength = 4 '设定蛇的初始长度

ReDim g_udtSnake(1 To g_intSnakeLength) '重新定义蛇的长度

'定义蛇头部的数据

With g_udtSnake(SNAKEONE)

.Snake_OldX = 530

.Snake_OldY = 530

.Snake_Color = vbBlack

End With

'定义蛇身第2节的数据

With g_udtSnake(SNAKETWO)

.Snake_OldX = 530

.Snake_OldY = 430

.Snake_Color = vbGreen

End With

'定义蛇身第3节的数据

With g_udtSnake(SNAKETHREE)

.Snake_OldX = 530

.Snake_OldY = 330

.Snake_Color = vbYellow

End With

'定义蛇身第4节的数据

With g_udtSnake(SNAKEFOUR)

.Snake_OldX = 530

.Snake_OldY = 230

.Snake_Color = vbRed

End With

Me.picMoveArea.Visible = True

Me.lblYourScore.Caption = g_intPlayerScore "分"

Me.lblGameTime.Caption = g_lngGameTime "秒"

Me.tmrSnakeMove.Interval = Me.hsbGameSpeed.Value

Me.tmrSnakeMove.Enabled = True

Me.tmrGameTime.Enabled = True

Call m_subGetPoint '获取第一个果子的位置和颜色

End Sub

vb.net 四则运算代码

Dim s1!, s2!, a$ '为小数点的叠加,s1,s2必须定义为单精度型

Dim flag As Boolean 'flag它是过程及的变量,在通用里必须声明

'在数字按钮控件单击数组单击事件中获取操作数(没有区分是哪一个操作数)

Private Sub Command1_Click(Index As Integer)

x = Text1.Text

If flag = True Or x = "0" Then '查看数字是否输入完毕或者是否清零了

Text1.Text = CStr(Index) 'CStr将数值转换字符

Else

Text1.Text = Text1.Text + CStr(Index) '"+"在这里这个是对字符串的操作的叠加,CStr(Index)是接的数据

End If

flag = False '时刻准备数字的输入

End Sub

'2.单击运算符,确定s1,并且要选定运算

Private Sub Command2_Click(Index As Integer)

flag = True

s1 = Val(Text1.Text)

Select Case Index

Case 0

a = "+"

Case 1

a = "-"

Case 2

a = "*"

Case 3

a = "/"

End Select

End Sub

'3."="的单击事件

Private Sub Command3_Click()

flag = True

s2 = Val(Text1.Text)

Select Case a

Case "+"

Text1.Text = s1 + s2

Case "-"

Text1.Text = s1 - s2

Case "*"

Text1.Text = s1 * s2

Case "/"

Text1.Text = s1 / s2 '分母不能为0

End Select

s1 = 0: s2 = 0: a = ""

End Sub

'4.清屏

Private Sub Command4_Click()

Text1.Text = "0"

s1 = 0

s2 = 0

a = ""

flag = False

End Sub

'5.删除最后输入的一个字符,换句话说,将本文框中的字符串取字符(从左往右取left(string,length)),将最后一个字符不取就先行

Private Sub Command5_Click()

If Text1.Text = "" Then

Else

Command5.Enabled = True

Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)

'len求字符串的长度,left(text1.len(text1)-1减1是取字符串从左往右减去一个字符串

End If

End Sub

'小数点 1)显示出"."(注意前面输入过的整数必须显示) 2)小数后能继续接受数字的输入

Private Sub Command6_Click()

Text1 = Text1 "."

End Sub

'7加入正负号--单击“+、-”,产生一个"-",而且处于一种等待数字输入的一种状态

Private Sub Command7_Click()

Dim temp As Double

temp = -Val(Text1.Text)

Text1.Text = temp

If d = " " Then s1 = temp Else s2 = temp

End Sub

Private Sub Command8_Click() '退出

End

End Sub

Private Sub Form_Load() '窗体初始化

Text1.Text = 0

Text1.Locked = True

End Sub


标题名称:vb.net常用代码集,VB常用代码
浏览地址:http://cdkjz.cn/article/hohsod.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220