百度
360搜索
搜狗搜索

简易vb代码大全,vb的简单记事本的代码详细介绍

本文目录一览: vb:简易计算器(加减乘除)代码

代码如下:
Dim t, t1 As Integer
Dim x, y As Double
Public Sub com()
x = Val(l1.Caption)
Select Case t1
Case Is = 1: y = y + x
Case Is = 2: y = y - x
Case Is = 3: y = y * x
Case Is = 4: y = y / x
End Select
t1 = 0
t = 0
l1.Caption = "0"
End Sub
Private Sub Form_Load()
x = 0
y = 0
t = 0
t1 = 1
End Sub
Private Sub c0_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "0"
Else
l1.Caption = l1.Caption + "0"
End If
End Sub
Private Sub C1_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "1"
Else
l1.Caption = l1.Caption + "1"
End If
End Sub
Private Sub c10_Click(Index As Integer)
If t = 0 Then
l1.Caption = l1.Caption + "."
t = 1
End If
End Sub
Private Sub C2_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "2"
Else
l1.Caption = l1.Caption + "2"
End If
End Sub
Private Sub C3_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "3"
Else
l1.Caption = l1.Caption + "3"
End If
End Sub
Private Sub C4_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "4"
Else
l1.Caption = l1.Caption + "4"
End If
End Sub
Private Sub C5_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "5"
Else
l1.Caption = l1.Caption + "5"
End If
End Sub
Private Sub C6_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "6"
Else
l1.Caption = l1.Caption + "6"
End If
End Sub
Private Sub C7_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "7"
Else
l1.Caption = l1.Caption + "7"
End If
End Sub
Private Sub C8_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "8"
Else
l1.Caption = l1.Caption + "8"
End If
End Sub
Private Sub C9_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "9"
Else
l1.Caption = l1.Caption + "9"
End If
End Sub
Private Sub z1_Click(Index As Integer)
com
t1 = 1
End Sub
Private Sub z2_Click(Index As Integer)
com
t1 = 2
End Sub
Private Sub z3_Click(Index As Integer)
com
t1 = 3
End Sub
Private Sub z4_Click(Index As Integer)
com
t1 = 4
End Sub
Private Sub z5_Click(Index As Integer)
tmp = Mid(l1.Caption, Len(l1.Caption), 1)
If tmp = "." Then
t = 0
End If
If Len(l1.Caption) = 1 Then
l1.Caption = "0"
Else
l1.Caption = Left(l1.Caption, Len(l1.Caption) - 1)
End If
End Sub
Private Sub z6_Click(Index As Integer)
l1.Caption = "0"
Form_Load
End Sub
Private Sub z7_Click(Index As Integer)
If (l1.Caption <> "0") Then
l1.Caption = "-" + l1.Caption
End If
End Sub
Private Sub z8_Click(Index As Integer)
com
l1.Caption = Str(y)
End Sub
扩展资料语言缺点
Visual Basic 语言具有不支持继承、无原生支持多线程、异常处理不完善等三项明显缺点,使其有所局限性(此些缺点皆已在 vb .net 获得改进)。
不支持继承
VB 5.0 和 VB 6.0 都是基于对象的编程语言,但是不包含继承特性。VB 中提供了特殊的类的功能,但是还是不能满足程序员的需求。
无原生支持多线程
Visual Basic 对于多线程无原生支持,只能通过Windows API的调用实现,且极其的不稳定。因为在API创建的线程中,并没有自动初始化运行时库,导致部分的函数无法使用。一般的,在VB6等早期的VB开发环境下,使用API创建线程的目的是完成容易使程序假死的大量数据或者逻辑的计算。
异常处理不完善
Visual Basic 中内置异常处理,即使未写异常处理代码,一旦用户出错也会弹出一个明确写出出错原因对话框,接着程序终止。
Visual Basic 中可以使用 Err.Raise抛出异常。对系统及用户抛出的异常的处理常用两种模式:一是使用 On Error Resume Next 处理错误;另一种是使用 On Error Goto 将运行引入错误处理代码。但相对 C++ 等语言而言,这样的异常处理破坏了代码的结构。
参考资料:百度百科-VB

求VB简易计算器的代码?

代码是:码
跪求高人给代码!!!
我有更好回答
?
匿名用户
推荐于 2016-11-11
Private Sub Command1_Click()
Select Case Text2.Text
Case "+"
Text4.Text = Str(Val(Text1.Text) + Val(Text3.Text))
Case "-"
Text4.Text = Str(Val(Text1.Text) - Val(Text3.Text))
Case "*"
Text4.Text = Str(Val(Text1.Text) * Val(Text3.Text))
Visual Basic(简称VB)是Microsoft公司开发的一种通用的基于对象的程序设计语言,为结构化的、模块化的、面向对象的、包含协助开发环境的事件驱动为机制的可视化程序设计语言。是一种可用于微软自家产品开发的语言。
“Visual” 指的是开发图形用户界面 (GUI) 的方法——不需编写大量代码去描述界面元素的外观和位置,而只要把预先建立的对象add到屏幕上的一点即可。
“Basic”指的是 BASIC (Beginners All-Purpose Symbolic Instruction Code) 语言,是一种在计算技术发展历史上应用得最为广泛的语言。
Visual Basic源自于BASIC编程语言。VB拥有图形用户界面(GUI)和快速应用程序开发(RAD)系统,可以轻易的使用DAO、RDO、ADO连接数据库,或者轻松的创建Active X控件,用于高效生成类型安全和面向对象的应用程序。
程序员可以轻松的使用VB提供的组件快速建立一个应用程序。

求VB中颜色代码

使用颜色常数:Form1背景色=虚拟现实。
背景色=vbBlue'蓝色。
背景色=vbWhite'白色。
使用QBColor函数:form1。背景色=QBColor(n)n个值,从0到15。
使用RGB函数:form1。背景色=RGB(r,g,b)'r,b,值分别为0到255。
扩展资料:
VbGreen & HFF00 green
VbYellow & HFFFF黄色
VbBlue & HFF0000蓝色
vb品红色& HFF00FF品红色
VbCyan & HFFFF00青色
VbWhite & HFFFFFF white
VbGrayText &H80000011灰色(无效)文本
VbButtonText &H80000012按下按钮上文字的颜色
VbInactiveCaptionText &H80000013非活动标题中的文本颜色
Vb3DHighlight &H80000014高亮显示3d显示元素的颜色
Vb3DDKShadow &H80000015三维显示元素的最暗阴影颜色
在3d中,Vb3DLight和h80000016低于vb3Dhighlight
Vb3DFace &H8000000F文本表面颜色
Vb3DShadow &H80000010文本阴影颜色
VbInfoText &H80000017提示窗口文字颜色
VbInfoBackground &H80000018表示窗口中背景的颜色

VB做加减乘除的代码是什么?

代码如下 \x0d\x0a'已增加操作数正确性验证及 除数不能为0验证 \x0d\x0a\x0d\x0aPrivate Sub Command1_Click() \x0d\x0aIf IsNumeric(Text1.Text) And Text1.Text "" And IsNumeric(Text2.Text) And Text2.Text "" Then \x0d\x0aSelect Case Combo1.ListIndex \x0d\x0aCase 0 \x0d\x0aText3.Text = Val(Text1.Text) + Val(Text2.Text) \x0d\x0aCase 1 \x0d\x0aText3.Text = Val(Text1.Text) - Val(Text2.Text) \x0d\x0aCase 2 \x0d\x0aText3.Text = Val(Text1.Text) * Val(Text2.Text) \x0d\x0aCase 3 \x0d\x0aIf Val(Text1.Text) 0 Then \x0d\x0aText3.Text = Val(Text1.Text) / Val(Text2.Text) \x0d\x0aElse \x0d\x0aMsgBox "除数不能为0", , "错误" \x0d\x0aEnd If \x0d\x0aEnd Select \x0d\x0aElse \x0d\x0aMsgBox "请输入操作数", , "错误" \x0d\x0aEnd If \x0d\x0aEnd Sub \x0d\x0a\x0d\x0aPrivate Sub Form_Load() \x0d\x0aCombo1.AddItem "+" \x0d\x0aCombo1.AddItem "-" \x0d\x0aCombo1.AddItem "*" \x0d\x0aCombo1.AddItem "/" \x0d\x0aCombo1.ListIndex = 0 \x0d\x0aText1.Text = "" \x0d\x0aText2.Text = "" \x0d\x0aText3.Text = "" \x0d\x0aCommand1.Caption = "计算" \x0d\x0a\x0d\x0aEnd Sub

vb代码大全

Option Explicit
Function fc(a) As Boolean
Dim i As Long
For i = 2 To Int(a / 2)
If a Mod i = 0 Then
fc = False
Exit For
Else
fc = True
End If
Next i
End Function
Private Sub Form_Click()
Dim i, j, k, m, s, g, f As Integer
j = 0
k = 0
f = 0
Dim a(1 To 80) As Integer
Dim b(1 To 80) As Integer
Dim c(1 To 80) As Integer
Dim d(1 To 80) As Integer
For i = 1 To 80
a(i) = Int(Rnd() * 100)
if a(i)<10 then a(i)=a(i)+10
If a(i) Mod 2 = 0 Then
j = j + 1
b(j) = a(i)
Else
k = k + 1
c(k) = a(i)
End If
Next i
For i = 1 To j
For m = i + 1 To j
If b(i) < b(m) Then
s = b(m)
b(m) = b(i)
b(i) = s
End If
Next m
Next i
For i = 1 To k
For m = i + 1 To k
If b(i) < b(m) Then
s = c(m)
c(m) = c(i)
c(i) = s
End If
Next m
Next i
For i = 1 To 80
If fc(a(i)) = True Then
g = g + 1
d(g) = a(i)
End If
Next i
Print "随机数:"
For i = 1 To 80
f = f + 1
If f < 11 Then
Print " " & a(i);
Else
f = 1
Print
Print " " & a(i);
End If
Next i
Print
Print "偶数:"
f = 0
For i = 1 To j
f = f + 1
If f < 11 Then
Print " " & b(i);
Else
f = 1
Print
Print " " & b(i);
End If
Next i
Print
Print "奇数:"
f = 0
For i = 1 To k
f = f + 1
If f < 11 Then
Print " " & c(i);
Else
f = 1
Print
Print " " & c(i);
End If
Next i
Print
Print "素数:"
f = 0
For i = 1 To g
f = f + 1
If f < 11 Then
Print " " & d(i);
Else
f = 1
Print
Print " " & d(i);
End If
Next i
s = 0
Print
Print "素数个数:" & g
For i = 1 To g
s = s + d(i)
Next i
Print "素数总和:" & s
End Sub

阅读更多 >>>  caption什么意思,vb中caption是什么意思?

各一个最简单的vb打字游戏代码

46. 键盘打字练习程序
  本程序用于打字练习,训练和提高打字速度。可选择小写字母、大写字母、大小写混合字母、特殊字符、数字、混合字符、汉字等 7 种练习方式。  程序启动后,字符不断随机出现并落下,如果练习者键入的字符正确,该字符变红变大,随后快速缩小,最终消失。  程序可显示练习者的成绩、正确率和每分钟的打字速度。练习中双击窗口,可清除数据,重新开始。注意进行字母或汉字输入练习时,要将输入法切换到正确的状态。
' '下面是窗体代码,在 VB6.0 调试通过:'在窗体上放置下面 6 个控件:' Option1: 用于进行字符类型选择' Label1: 用于显示下落的字符' Label2: 用于显示游戏信息' Timer1: 用于移动字符' Picture1:下落字符的背景' Text1: 用于显示游戏者键入的字符'在属性窗口将 Option1 和 Label1 的 Index 属性设置为 0,其他控件及属性不必设置,采用默认属性即可。'如果要进行汉字打字练习,在工程所在目录下用记事本建立一个文本文件,文件名为:HanZi.txt' 在此文本文件中输入练习所用的汉字,如:汉字=中华人民共和国,伟大的奥运会!' 注意,输入的字符前面三个必须是:汉字='本人原创,转载请注明来源:http://hi.baidu.com/100bd/blog/item/633b6467dbfdd828aa184cdb.htmlDim ctY As Single, ctCount As Long, ctFinish As Long, ctTime As SingleDim ctSize As Single, ctStr As String, ctStrS As Long, ctNoCheck As BooleanPrivate Sub Form_Load() Dim I As Long Me.KeyPreview = True: Me.Caption = "键盘打字速度练习" Text1.Text = "": ctSize = 36 '显示字符大小 Me.BackColor = RGB(50, 50, 155): Picture1.BackColor = RGB(100, 100, 255) Label2.BackColor = Me.BackColor: Label2.ForeColor = &HFFFFFF Label2.Caption = "成绩: 0%": Label2.AutoSize = True: '用于显示成绩信息 Me.Move Screen.Width * 0.1, Screen.Height * 0.1, Screen.Width * 0.8, Screen.Height * 0.8 Set Label1(0).Container = Picture1 Label1(0).Font.Bold = True: Label1(0).BackStyle = 0 '用于显示下落的字符 Label1(0).UseMnemonic = False: Label1(0).AutoSize = True For I = 0 To 4 '同时出现的字符个数,这里设置为 5,可修改 If I > 0 Then Load Label1(I) Next Option1(0).BackColor = Me.BackColor: Option1(0).ForeColor = &HFFFFFF For I = 0 To 6 If I > 0 Then Load Option1(I) Next Option1(0).Caption = "小写字母": Option1(1).Caption = "大写字母" Option1(2).Caption = "大小写混合字母": Option1(3).Caption = "特殊字符" Option1(4).Caption = "数字": Option1(5).Caption = "混合字母和字符" Option1(6).Caption = "汉字": For I = 0 To Option1.Count - 1 Option1(I).Visible = True Next Option1(0).Value = True Call StartPlay ctY = Picture1.ScaleY(5, 3, Picture1.ScaleMode) '字符下落速度(这里为 5 个像素),可修改 Timer1.Enabled = True: Timer1.Interval = 50End SubPrivate Sub Form_Activate() On Error Resume Next Text1.SetFocusEnd SubPrivate Sub Text1_Change() Dim I As Long If ctNoCheck Or Len(Text1.Text) < 11 Then Exit Sub ctNoCheck = True I = Text1.SelStart: If I = 0 Then I = 1 Text1.Text = Mid(Text1.Text, I, 1) Text1.SelStart = Len(Text1.Text) ctNoCheck = FalseEnd SubPrivate Sub Form_KeyPress(KeyAscii As Integer) Dim I As Long, nStr As String, T As Single nStr = Chr(KeyAscii) If nStr = " " Then nStr = "(空格)" For I = 0 To Label1.Count - 1 If nStr = Label1(I).Caption And Label1(I).Tag = "1" Then Label1(I).ForeColor = 255: Label1(I).Tag = "2" Label1(I).Font.Size = ctSize * 4 T = Picture1.ScaleHeight - Label1(I).Height If Label1(I).Top > T Then Label1(I).Top = T ctFinish = ctFinish + 1: Call ShowInf Exit Sub End If NextEnd SubPrivate Sub ShowInf() Dim nStr As String, T As Long, M As Long, H As Long, StrT As String, V As Long If ctCount > 0 Then nStr = Format(ctFinish / ctCount * 100, "0.0") Else ctCount = "0" nStr = "正确率:" & nStr & "%" nStr = "总数:" & ctCount & vbCrLf & vbCrLf & "正确:" & ctFinish & vbCrLf & vbCrLf & nStr T = Int(Timer - ctTime) If T > 0 Then V = ctFinish / T * 60 H = T \ 3600: T = T Mod 3600 M = T \ 60: T = T Mod 60 If H > 0 Then StrT = H & ":" If H > 0 Or M > 0 Then StrT = StrT & M & "'" 'StrT = "12:34'"'****调试代码 nStr = nStr & vbCrLf & vbCrLf & "时间:" & StrT & T & """" Label2.Caption = nStr & vbCrLf & vbCrLf & "速度:" & V & "字/分"End SubPrivate Sub Form_Resize() Dim I As Long, L As Single, T As Single, W As Single, H As Single, MaxW As Single Text1.Font.Size = 16: Label2.Font.Size = 12 H1 = Me.TextHeight("1") L = H1: T = H1 For I = 0 To Option1.Count - 1 Option1(I).Visible = True: W = Me.TextWidth(Option1(I).Caption & "123456") If MaxW < W Then MaxW = W Option1(I).Move L, T, W, H1 * 1.25 T = T + H1 * 1.5 Next Label2.Move L * 0.8, T + H1 H = Me.ScaleHeight - Text1.Height L = L + MaxW: W = Me.ScaleWidth - L If W > 0 And H > 0 Then Picture1.Move L, 0, W, H W = Me.ScaleWidth - L If W > 0 Then Text1.Move L, Picture1.Height, WEnd SubPrivate Sub Picture1_Click() Text1.SetFocusEnd SubPrivate Sub Picture1_DblClick() Call StartPlayEnd SubPrivate Sub StartPlay() ctFinish = 0: ctCount = 0: ctTime = Timer For I = 0 To Label1.Count - 1 Label1(I).Tag = "": Label1(I).Visible = False NextEnd SubPrivate Sub Option1_Click(Index As Integer) GetStr Index Call StartPlay On Error Resume Next Text1.SetFocusEnd SubPrivate Sub GetStr(nMode As Integer) Dim Str1 As String, Str2 As String, Str3 As String Str1 = " abcdefghijklmnopqrstuvwxyz" Str2 = " ~!@#$%^&*()_+|-=\{}:""<>?[];',./" Str3 = "0123456789" Select Case nMode Case 1: ctStr = UCase(Str1) '大写字母 Case 2: ctStr = Str1 & UCase(Str1) '大小写混合字母 Case 3: ctStr = Str2: '特殊字符 Case 4: ctStr = Str3: '数字 Case 5: ctStr = Str1 & UCase(Str1) & Str2 & Str3 '大小写混合和特殊字符 Case 6: ctStr = ReadText(): '汉字 Case Else: ctStr = Str1: '小写字母 End Select ctStrS = Len(ctStr)End SubPrivate Function ReadText() As String '从文本文件中读出要进行汉字练习的字符 Dim F As String, H As Long, nStr As String On Error GoTo cuo F = App.Path If Right(F, 1) <> "\" Then F = F & "\" F = F & "HanZi.txt" H = FreeFile Open F For Input As #H Line Input #H, nStr Close #H If Left(nStr, 3) <> "汉字=" Then GoTo cuo '检查文件标记 nStr = Trim(Mid(nStr, 4)) If nStr = "" Then GoTo cuo ReadText =nStr 'ReadText = "中华人民共国" ' ****调试代码 Exit Functioncuo: ReadText = "错误"End FunctionPrivate Sub RndStr(I As Long) '随机字符和位置 Static xUp As Single Dim x As Single, W As Single, S As Long If Label1(I).Tag <> "" Then Exit Sub Label1(I).Font.Size = ctSize: Label1(I).ForeColor = &HFFFFFF Randomize: S = 1 + Int(Rnd * ctStrS): Label1(I).Caption = Mid(ctStr, S, 1) '随机字符 If Label1(I).Caption = " " Then Label1(I).Caption = "(空格)" Randomize W = Picture1.ScaleWidth Do '随机位置:确保不重叠 x = Rnd * (W - Label1(I).Width) S = S + 1 If S > 100 Or W < Label1(I).Width * 2 Then Exit Do If Abs(xUp - x) > Label1(I).Width Then Exit Do Loop Label1(I).Move x, -ctY xUp = x Label1(I).Visible = True: Label1(I).Tag = "1" ctCount = ctCount + 1: Call ShowInfEnd SubPrivate Sub Timer1_Timer() Dim I As Long, NextI As Long, S As Single, Have1 As Boolean, T As Long For I = 0 To Label1.Count - 1 If Label1(I).Tag <> "" Then Have1 = True Label1(I).Top = Label1(I).Top + ctY If Label1(I).Tag = "2" Then '已击中的字符 S = Label1(I).Font.Size * 0.7 If S > 3 Then Label1(I).Font.Size = S Else Label1(I).Tag = "": Label1(I).Visible = False End If If Label1(I).Top > Picture1.ScaleHeight Then Label1(I).Tag = "": Label1(I).Visible = False If Label1(I).Top > Picture1.ScaleHeight * 0.2 Then '超过窗体高度 1/5 ,下一个字符出现 NextI = I + 1 If NextI > Label1.Count - 1 Then NextI = 0 RndStr NextI End If End If Next If Not Have1 Then RndStr 0 '已全部消失 T = T + Timer1.Interval If T > 200 Then T = 0: Call ShowInfEnd Sub'本人原创,转载请注明来源:http://hi.baidu.com/100bd/blog/item/633b6467dbfdd828aa184cdb.html参考:http://hi.baidu.com/100bd

阅读更多 >>>  vb基础知识试题及答案,vb基本操作题答案

vb的最简单代码

插入三个文本框a1、a2、a3来接收输入的三个数,插入一个按钮a4来执行操作,最后用三个文本框来显示结果。
Private Sub a4_Click()
Dim v1, v2, v3, t As Single
v1 = a1.Value
v2 = a2.Value
v3 = a3.Value
If (v1 < v2) Then
t = v1
v1 = v2
v2 = t
End If
If (v1 < v3) Then
t = v1
v1 = v3
v3 = t
End If
If (v2 < v3) Then
t = v2
v2 = v3
v3 = t
End If
a1.Value = v1
a2.Value = v2
a3.Value = v3
End Sub

急!!vb简易的小游戏代码,不要太复杂,不过石头剪刀布那种就算了

简易三国志
创建9个command,1个timer,时间20000,9个text,6个farm。
布置如图
代码如下
Private Sub Form_Load()
Text1.Text = "100" '我方剩余士兵
Text2.Text = "170" '对方剩余士兵
Text3.Text = "180" '对方剩余士兵
Text4.Text = "200" '对方剩余士兵
Text5.Text = "500" '金钱
Text6.Text = "170" '武将血量
Text7.Text = "120" '武将血量
Text8.Text = "150" '武将血量
Text9.Text = "151" '武将血量
End Sub
Private Sub command1_click()
If Text1.Text < "0" Or Text6.Text < "0" Then
MsgBox "无法攻击!"
Else:
Do
Text1.Text = Text1.Text - 5
Text2.Text = Text2.Text - 10
Text6.Text = Text6.Text - 10 '你的攻击力暂定为200
Text7.Text = Text7.Text - 5 '你的攻击力暂定为200
Loop Until Text2.Text = "0" Or Text7.Text = "0"
MsgBox "本轮进攻胜利!"
Text5.Text = Text5.Text + 500
End If
End Sub
Private Sub command2_click()
If Text1.Text < "0" Or Text6.Text < "0" Then
MsgBox "无法攻击!"
Else:
Do
Text1.Text = Text1.Text - 10
Text3.Text = Text3.Text - 10
Text6.Text = Text6.Text - 10 '你的攻击力暂定为200
Text8.Text = Text8.Text - 10
Loop Until Text3.Text = "0" Or Text7.Text = "0"
MsgBox "本轮进攻胜利!"
Text5.Text = Text5.Text + 300
End If
End Sub
Private Sub command3_click()
If Text1.Text < "0" Or Text6.Text < "0" Then
MsgBox "无法攻击!"
Else:
Do
Text1.Text = Text1.Text - 20
Text4.Text = Text4.Text - 10
Text6.Text = Text6.Text - 10 '你的攻击力暂定为200
Text9.Text = Text9.Text - 10
Loop Until Text4.Text = "0" Or Text7.Text = "0"
MsgBox "本轮进攻胜利!"
Text5.Text = Text5.Text + 700
End If
End Sub
Private Sub command4_click()
Text1.Text = Text1.Text + 100
Text5.Text = Text5.Text - 50
If Text5.Text = "0" Then
MsgBox "没钱了!"
If Text1.Text = "0" Then
MsgBox "没兵了!"
End If
End If
End Sub
Private Sub command5_click()
Text6.Text = Text1.Text + 300
Text5.Text = Text5.Text - 100
If Text5.Text = "0" Then
MsgBox "没钱了!"
If Text6.Text = "0" Then
MsgBox "没血了!"
End If
End If
End Sub
Private Sub command6_click()
Text6.Text = Text1.Text + 1000
Text5.Text = Text5.Text - 500
If Text5.Text = "0" Then
MsgBox "没钱了!"
If Text6.Text = "0" Then
MsgBox "没可买的了!"
End If
End If
End Sub
Private Sub command7_click()
MsgBox "城市名;洛阳 黄金500 兵马170 守城大将张飞!"
End Sub
Private Sub command8_click()
MsgBox "城市名;长安 黄金400 兵马180 守城大将孙权!"
End Sub
Private Sub command9_click()
MsgBox "城市名;合肥 黄金700 兵马200 守城大将姜维!"
End Sub
Private SubIf Timer1 = "0" Then
MsgBox "台风来啦!"
Text1.Text = Text1.Text - 100
Text5.Text = Text5.Text - 100
End Sub

vb的简单记事本的代码

请确保commonDialog控件已拖放到form上,具体步骤为:在vb的project菜单下,打开components子菜单,在弹出窗口中的controls标签页下,找到Microsoft
Common
Dialog
?.0(SP?)打上勾后确定,确定之后在控件选择那个栏位表会出现一个新加入的图标,鼠标移上去会出现CommonDialog字样,将它点击拖入你建立的窗体上,再尝试运行
没有在窗体添加
CommonDialog
控件
Ctrl+T,选择
microsoft
common
dialog..
再在工具箱中将其拖到窗体即可
http://download.csdn.net/sort/tag/%E8%AE%B0%E4%BA%8B%E6%9C%AC%EF%BC%8Cvb%EF%BC%8C%E6%BA%90%E4%BB%A3%E7%A0%81
CSDN的下载 需要先注册会员 我下载过 基本实现记事本的需求
以前做过.并不难实现,VB有个控件rich textbox,记事本的基本功能都能用它实现
'窗体代码
Option Explicit
Dim filename As String
Dim FileType As String
Dim FiType As String
Dim sFind As String
Dim result As String
Dim bWrap As Boolean
Dim ask As Boolean
Dim msgtext As String
Dim Flag As String
Private Sub Form_Load()
ask = False
RichText.Text = ""
filename = "无标题-记事本"
Form1.Caption = "无标题-记事本"
RichText.Height = Form1.ScaleHeight
RichText.Width = Form1.ScaleWidth
StatusBar1.Visible = False
StatusBar1.Panels(1).Text = Time
mnucopy.Enabled = False
mnucut.Enabled = False
mnufound.Enabled = False
mnufoundnext.Enabled = False
mnudel.Enabled = False
mnucancel.Enabled = False
mnuwordwrap.Checked = True
mnugoto.Enabled = False
If Clipboard.GetText <> "" Then
mnuplaster.Enabled = True
Else
mnuplaster.Enabled = False
End If
App.HelpFile = App.Path & "\notepad.chm"
End Sub
Private Sub Form_Resize()
RichText.Height = Form1.ScaleHeight
RichText.Width = Form1.ScaleWidth
End Sub
Private Sub Form_Unload(Cancel As Integer)
msgtext = "文件" & filename & "的文字已经改变。" & Chr(10) & Chr(13) & "想保存文件吗?"
If ask = True Then
Flag = MsgBox(msgtext, 35, "记事本") ' 35=32+3
If Flag = vbYes Then mnusave_Click '选择了确定则保存之
If Flag = vbCancel Then Cancel = True
If Flag = vbNo Then Unload Me
End If

End Sub
Private Sub mnuabout_Click()
MsgBox "记事本", vbOKOnly, "关于"
End Sub
Private Sub mnuall_Click()
RichText.SelStart = 0
RichText.SelLength = Len(RichText.Text)
End Sub
Private Sub mnucancel_Click()
MsgBox "请点击鼠标右键撤销!", vbOKOnly, "提示"
End Sub
Private Sub mnucopy_Click()
Clipboard.Clear
Clipboard.SetText RichText.SelText
End Sub
Private Sub mnucut_Click()
Clipboard.Clear
Clipboard.SetText RichText.SelText
RichText.SelText = ""
End Sub
Private Sub mnudel_Click()
RichText.SelText = ""
End Sub
Private Sub mnuedit_Click()
If RichText.SelText <> "" Then
mnuopen.Enabled = True
mnucut.Enabled = True
mnudel.Enabled = True
mnucopy.Enabled = True
End If
If Len(RichText.Text) <> 0 Then
mnufound.Enabled = True
mnufoundnext.Enabled = True
End If
If ask = True Then mnucancel.Enabled = True
End Sub
Private Sub mnuexit_Click()
Unload Me
End Sub
Private Sub mnufont_Click()
On Error Resume Next
CommonDialog1.flags = &H3 Or &H1 Or &H2 Or &H100
CommonDialog1.Action = 4
RichText.Font.Name = CommonDialog1.FontName
RichText.Font.Size = CommonDialog1.FontSize
RichText.Font.Bold = CommonDialog1.FontBold
RichText.Font.Italic = CommonDialog1.FontItalic
RichText.Font.Underline = CommonDialog1.FontUnderline
RichText.SelColor = CommonDialog1.Color

阅读更多 >>>  fontweightbold什么意思,li.sub ) a{ font-weight:bold; background:#ffe; }代码中的)是什么意思

End Sub
Private Sub mnufound_Click()
sFind = InputBox("请输入要查找的字、词:", "查找内容", sFind)
RichText.Find sFind
End Sub
Private Sub mnufoundnext_Click()
RichText.SelStart = RichText.SelStart + RichText.SelLength + 1
RichText.Find sFind, , Len(RichText)
End Sub
Private Sub mnuhelptopic_Click()
SendKeys "{F1}"
End Sub
Private Sub mnunewfile_Click()
On Error Resume Next
Dim n As Integer
msgtext = "文件" & filename & "的文字已经改变。" & Chr(10) & Chr(13) & "想保存文件吗?"
If Len(RichText.Text) <> 0 Then
If filename = "无标题-记事本" Then
Flag = MsgBox(msgtext, 35, "记事本") '给予提示
If Flag = vbYes Then
mnusaveas_Click
RichText.Text = ""
Form1.Caption = "无标题-记事本"
filename = "无标题-记事本"
End If
If Flag = vbCancel Then Exit Sub
If Flag = vbNo Then
RichText.Text = ""
Form1.Caption = "无标题-记事本"
filename = "无标题-记事本"
End If
End If
End If
End Sub
Private Sub mnuopen_Click()
msgtext = "文件" & filename & "的文字已经改变。" & Chr(10) & Chr(13) & "想保存文件吗?"
On Error Resume Next
If ask = True Then
Flag = MsgBox(msgtext, 35, "记事本") '给予提示
If Flag = vbYes Then mnusave_Click '选择了确定则保存之
If Flag = vbCancel Then Exit Sub
If Flag = vbNo Then GoTo L1
End If
ask = False

L1: CommonDialog1.Filter = "文本文档(*.txt)|*.txt|RTF文档(*.rtf)|*.rtf|所有文件(*.*)|*.*"
CommonDialog1.ShowOpen
RichText.Text = "" '清空文本框
filename = CommonDialog1.filename
RichText.LoadFile filename
result = GetFileTitle(filename)
Me.Caption = "" & result & "-记事本"
End Sub
Private Sub mnupagesetup_Click()
psdlg.lStructSize = Len(psdlg)
psdlg.hwndOwner = hwnd
PageSetupDlg psdlg
End Sub
Private Sub mnuplaster_Click()
RichText.SelText = Clipboard.GetText(1)
End Sub
Private Sub mnuprint_Click()
Dim f As Integer, t As Integer
Dim i As Integer
CommonDialog1.CancelError = True
CommonDialog1.Max = 1000
CommonDialog1.Min = 1
On Error Resume Next
CommonDialog1.ShowPrinter

For f = CommonDialog1.FromPage To t = CommonDialog1.ToPage
Do While i < CommonDialog1.Copies + 1
Printer.Print RichText.Text
i = i + 1
Loop
Next
Printer.EndDoc
Cancel:
If Err.Number = 32755 Then
Exit Sub
End If
End Sub
Private Sub mnusave_Click()
CommonDialog1.Filter = "文本文档(*.txt)|所有文件(*.*)|*.*"
On Error Resume Next
filename = CommonDialog1.filename '保存文件
If filename <> "" Then
RichText.SaveFile filename, rtfText
Else
mnusaveas_Click
End If
ask = False
End Sub
Private Sub mnusaveas_Click()
CommonDialog1.Filter = "文本文档(*.txt)|所有文件(*.*)|*.*"
On Error Resume Next

CommonDialog1.ShowSave
filename = CommonDialog1.filename
RichText.SaveFile filename, rtfText

result = GetFileTitle(filename)
Me.Caption = "" & result & "-记事本"
ask = False
End Sub
Private Sub mnustatusbar_Click()
If mnustatusbar.Checked Then
StatusBar1.Visible = False
mnustatusbar.Checked = False
Else
StatusBar1.Visible = True
mnustatusbar.Checked = True
End If

End Sub
Private Sub mnutimedate_Click()
RichText.SelText = Format(Now, "h:mm ddddd")
End Sub
Private Sub mnuwordwrap_Click()
WrapTextLine RichText, bWrap
bWrap = Not bWrap
If mnuwordwrap.Checked = False Then
HScroll1.Enabled = True
mnuwordwrap.Checked = True

Else
HScroll1.Enabled = False
mnuwordwrap.Checked = False

End If

End Sub
Private Sub RichText_Change()
ask = True
End Sub
Private Sub Timer1_Timer()
If StatusBar1.Panels(1).Text <> CStr(Time) Then
StatusBar1.Panels(1).Text = Time
End If
End Sub
'模块代码
Option Explicit
Const WM_USER = &H400
Const EM_SETTARGETDEVICE = (WM_USER + 72)
Type POINTAPI
x As Long
y As Long
End Type
Type RECT
left As Long
right As Long
top As Long
bottom As Long
End Type
Public Type PageSetupDlg
lStructSize As Long
hwndOwner As Long
hDevMode As Long
hDevNames As Long
flags As Long
ptPaperSize As POINTAPI
rtMinMargin As RECT
rtMargin As RECT
hInstance As Long
lCustData As Long
lpfnPageSetupHook As Long
lpfnPagePaintHook As Long
lpPageSetupTemplateName As String
hPageSetupTemplate As Long
End Type
Public psdlg As PageSetupDlg
Declare Function PageSetupDlg Lib "comdlg32.dll" Alias "PageSetupDlgA" (pPagesetupdlg As PageSetupDlg) As Long
Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Dim bWrap As Boolean '// 换行标记'// 自定义一个换行的过程
Public Sub WrapTextLine(ByRef RichText As RichTextBox, ByVal bWrapSwitch As Boolean)
On Error Resume Next
If bWrapSwitch Then '// 设置 RichTextBox 自动换行
SendMessage RichText.hwnd, EM_SETTARGETDEVICE, GetDC(RichText.hwnd), RichText.Width / 15
RichText.RightMargin = IIf(RichText.RightMargin = 0, 1, 0)
Else
'// 设置 RichTextBox 不自动换行
SendMessage RichText.hwnd, EM_SETTARGETDEVICE, 0, 1
End If
End Sub
Function GetFileTitle(OldStr As String) As String
On Error Resume Next
Dim n As Integer, m As Integer '声明字符串变量
Dim i As String, r As String
Dim p As Integer
i = "\" '要查找的指定字符
For n = 1 To Len(OldStr) '用Len函数计算已知字符串的字节数
m = InStrRev(OldStr, i, -1) '"\"所在的位置(其中的-1是默认的)
Next n '找下去!
'截取最后一个"\"后面的字符串
r = right(OldStr, Len(OldStr) - m) '获取Title
p = InStrRev(r, ".", -1) '"."所在位置
GetFileTitle = left(r, p - 1) '去掉后缀
End Function

网站数据信息

"简易vb代码大全,vb的简单记事本的代码"浏览人数已经达到19次,如你需要查询该站的相关权重信息,可以点击进入"Chinaz数据" 查询。更多网站价值评估因素如:简易vb代码大全,vb的简单记事本的代码的访问速度、搜索引擎收录以及索引量、用户体验等。 要评估一个站的价值,最主要还是需要根据您自身的需求,如网站IP、PV、跳出率等!