有趣的vb编程代码大全,vb有趣小程序
有趣的vb编程代码大全,vb有趣小程序详细介绍
本文目录一览: wordvba编程代码有哪些
很多的程序员都离不开编程的代码,但是对于wordvba肯定有很多的新手不知道常用代码有哪些,所以下面就给你们提供了wordvba编程代码大全,快来一起看看吧。wordvba编程代码有哪些:1、删除空行_Sub_删除空行()_Dim_I_As_Paragraph,_n_As_Integer_Application.ScreenUpdating_=_False_For_Each_I_In_ActiveDocument.Paragraphs_If_Len(Trim(I.Range))_=_1_Then_I.Range.Delete_n_=_n_+_1_End_If_Next_MsgBox_"共删除空白段落"__n__"个"_Application.ScreenUpdating_=_True_End_Sub_2、奇偶页打印_Sub_奇偶页打印()_Dim_x,_j,_i_As_Integer_On_Error_Resume_Next_x_=_ExecuteExcel4Macro("Get.Document(50)")_For_i_=_1_To_Int(x_/_2)_+_1_ActiveWindow.SelectedSheets.PrintOut_From:=2_*_i_-_1,_To:=2_*_i_-_1_Next_i_If_x_=_1_Then_MsgBox_"无偶数页"_Else_MsgBox_"请将打印出的纸张反向装入纸槽中",_vbOKOnly,_"打印另一面"_For_j_=_1_To_Int(x_/_2)_+_1_ActiveWindow.SelectedSheets.PrintOut_From:=2_*_j,_To:=2_*_j_Next_j_End_If_End_Sub__3、中英文标点互换Sub_中英文标点互换()_Dim_ChineseInterpunction()_As_Variant,_EnglishInterpunction()_As_Variant_Dim_myArray1()_As_Variant,_myArray2()_As_Variant,_strFind_As_String,_strRepAs_String_Dim_msgResult_As_VbMsgBoxResult,_N_As_Byte_'定义一个中文标点的数组对象_ChineseInterpunction_=_Array("、","。",_",",_";",_":",_"?",_"!",_"__",_"—",_"~",_"(",_")",_"《",_"》")_'定义一个英文标点的数组对象_EnglishInterpunction_=_Array(",",".",_",",_";",_":",_"?",_"!",_"_",_"-",_"~",_"(",_")",_"",_"")_'注意这里的英文,转换为了中文、,如果希望将,转换为中文,请自行修改!_'提示用户交互的MSGBOX对话框_msgResult_=_MsgBox("您想中英标点互换吗?按Y将中文标点转为英文标点,按N将英文标点转为中文标点!",_vbYesNoCancel)_Select_Case_msgResult_Case_vbCancel_Exit_Sub_'如果用户选择了取消按钮,则退出程序运行_Case_vbYes_'如果用户选择了YES,则将中文标点转换为英文标点_myArray1_=_ChineseInterpunction_myArray2_=_EnglishInterpunction_strFind_=_"“(*)”"_strRep_=_"""\1"""_Case_vbNo_'如果用户选择了NO,则将英文标点转换为中文标点_myArray1_=_EnglishInterpunction_myArray2_=_ChineseInterpunction_strFind_=_"""(*)"""_strRep_=_"“\1”"_End_Select_Application.ScreenUpdating_=_False_'关闭屏幕更新_For_N_=_0_To_UBound(ChineseInterpunction)_'从数组的下标到上标间作一个循环_With_ActiveDocument.Content.Find_.ClearFormatting_'不限定查找格式_.MatchWildcards_=_False_'不使用通配符_'查找相应的英文标点,替换为对应的中文标点_.Execute_findtext:=myArray1(N),_replacewith:=myArray2(N),_Replace:=wdReplaceAll_End_With_NextWith_ActiveDocument.Content.Find_.ClearFormatting_'不限定查找格式_.MatchWildcards_=_True_'使用通配符_.Execute_findtext:=strFind,_replacewith:=strRep,_Replace:=wdReplaceAll_End_With_Application.ScreenUpdating_=_True_'恢复屏幕更新_End_Sub__4、任意页插入页码_Sub任意页插入页码()_Dim_p_As_Integer_On_Error_Resume_Next_p_=_InputBox("请输入起始编排页码的页次")_With_Selection_.GoTo_What:=wdGoToPage,_Count:=p_.InsertBreak_Type:=wdSectionBreakContinuous_.Sections(1).Footers(1).LinkToPrevious_=_False_With_.Sections(1).Footers(1).PageNumbers_.RestartNumberingAtSection_=_True_.StartingNumber_=_1_.Add_PageNumberAlignment:=wdAlignPageNumberCenter,_FirstPage:=True_End_With_End_With_End_Sub__5、实现图形的精确旋转_Sub_图形旋转()_Dim_blnIsInlineShape_As_Boolean_If_Selection.Type_=_wdSelectionInlineShape_Then_blnIsInlineShape_=_True_Selection.InlineShapes(1).ConvertToShape_End_If_Dim_intTurn_As_Integer_intTurn_=_InputBox("请输入图形要旋转的角度值"__vbCrLf__"正数表示顺时针,负数表示逆时针。",_"图形旋转",_30)_Selection.ShapeRange.IncrementRotation_intTurn_End_Sub_
介绍一个VB小的有趣的程序代码
'万花筒程序
'粘贴下面代码即可, 不用添加任何控件
Private WithEvents Timer1 As Timer
Dim r&, r1&, t&, a1!, a2!, xb!, yb!, s!, b#
Private Sub Form_Load()
Me.Width = 4500: Me.Height = 4500
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
Me.AutoRedraw = True
Me.Caption = "CBM666的万花筒"
Set Timer1 = Controls.Add("vb.timer", "Timer1")
Timer1.Interval = 10
End Sub
Private Sub Timer1_Timer()
Randomize
r = 340 * Rnd
If r <> 0 Then
r1 = 500
s = r * Rnd
b = RGB(256 * Rnd, 256 * Rnd, 256 * Rnd)
For t = 1 To 10000
a1 = t * 3.1415926 / 180
a2 = (r1 / r) * a1
xb = 500 + (-(r1 - r) * Cos(a1) - s * Cos(a2 - a1) + 420) * 4
yb = 500 + ((r1 - r) * Sin(a1) - s * Sin(a2 - a1) + 380) * 4
Me.PSet (xb, yb), b
Next t
End If
End Sub
'万花筒程序
'粘贴下面代码即可, 不用添加任何控件
Private WithEvents Timer1 As Timer
Dim r&, r1&, t&, a1!, a2!, xb!, yb!, s!, b#
Private Sub Form_Load()
Me.Width = 4500: Me.Height = 4500
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
Me.AutoRedraw = True
Me.Caption = "CBM666的万花筒"
Set Timer1 = Controls.Add("vb.timer", "Timer1")
Timer1.Interval = 10
End Sub
Private Sub Timer1_Timer()
Randomize
r = 340 * Rnd
If r <> 0 Then
r1 = 500
s = r * Rnd
b = RGB(256 * Rnd, 256 * Rnd, 256 * Rnd)
For t = 1 To 10000
a1 = t * 3.1415926 / 180
a2 = (r1 / r) * a1
xb = 500 + (-(r1 - r) * Cos(a1) - s * Cos(a2 - a1) + 420) * 4
yb = 500 + ((r1 - r) * Sin(a1) - s * Sin(a2 - a1) + 380) * 4
Me.PSet (xb, yb), b
Next t
End If
End Sub
一些VB小游戏吧……例如
FaceCatch,LetterTile,LuckySeven等等
都差不多,就看你能不能把它做得有趣而已。
'万花筒程序
'粘贴下面代码即可,?不用添加任何控件
Private?WithEvents?Timer1?As?Timer
Dim?r&,?r1&,?t&,?a1!,?a2!,?xb!,?yb!,?s!,?b#
Private?Sub?Form_Load()
??????Me.Width?=?4500:?Me.Height?=?4500
??????Me.Move?(Screen.Width?-?Me.Width)?\?2,?(Screen.Height?-?Me.Height)?\?2
??????Me.AutoRedraw?=?True
??????Me.Caption?=?"CBM666的万花筒"
??????Set?Timer1?=?Controls.Add("vb.timer",?"Timer1")
??????Timer1.Interval?=?10
End?Sub
Private?Sub?Timer1_Timer()
??????Randomize
??????r?=?340?*?Rnd
??????If?r?<>?0?Then
?????????r1?=?500
?????????s?=?r?*?Rnd
?????????b?=?RGB(256?*?Rnd,?256?*?Rnd,?256?*?Rnd)
?????????For?t?=?1?To?10000
????????????a1?=?t?*?3.1415926?/?180
????????????a2?=?(r1?/?r)?*?a1
????????????xb?=?500?+?(-(r1?-?r)?*?Cos(a1)?-?s?*?Cos(a2?-?a1)?+?420)?*?4
????????????yb?=?500?+?((r1?-?r)?*?Sin(a1)?-?s?*?Sin(a2?-?a1)?+?380)?*?4
????????????Me.PSet?(xb,?yb),?b
?????????Next?t
??????End?If
End?Sub
VB猜数字游戏程序代码
邮件投递成功
收件人
投递状态
时间
lvyang900626@sina.com
已投递到对方服务器
2009年10月19日(星期一)
下午4:50
Option ExplicitPrivate Sub Command1_Click()On Error Resume NextDim I As IntegerI = MsgBox("下面游戏开始,你准备好了吗?", vbYesNo)If I = 6 Then Frame1.Visible = True: Text1 = "" Else Frame1.Visible = FalseText1.SetFocusRandomize (Timer)Text2 = Int(Rnd() * 10) + 1Text3 = 0End SubPrivate Sub Command2_Click()EndEnd SubPrivate Sub Form_Load()Me.Height = 5000Me.Width = 10500Me.BorderStyle = 1Me.Caption = "猜数游戏"Label1.Left = 0Label1.Top = 1000Label1.Caption = "欢迎进入猜数游戏"Label1.FontName = "楷体_GB2312"Label1.ForeColor = &H80FF&Label1.FontSize = 48Command1.Caption = "开始"'Command1.Default = TrueCommand2.Caption = "退出"Command2.Cancel = TrueEnd SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 13 Then KeyAscii = 0If KeyAscii = 13 Then If Text1 <> "" Then JyszEnd IfEnd SubPrivate Function Jysz() As Boolean Text3 = Val(Text3) + 1 If Val(Text1) = Val(Text2) Then MsgBox "猜对了,你真棒" & Chr(13) & Chr(10) & "请猜下一个……" Command1_Click ElseIf Val(Text1) > Val(Text2) Then MsgBox "猜大了。" Else MsgBox "猜小了。" End If Text1 = "" If Val(Text3) >= 3 Then MsgBox "呵呵,没猜对!正确的答案是" & Text2 & "。别气馁,再来!" Command1_Click End IfEnd Function具体程序已经发到你的邮箱songxing_cool@yahoo.com.cn更多代码请参阅我的博客http://hi.baidu.com/zgmg/blog
有趣的vb小程序
PrivateWithEventsTimer1AsTimer
Dimr&,r1&,t&,a1!,a2!,xb!,yb!,s!,b#
PrivateSubForm_Load()
Me.Width=4500:Me.Height=4500
Me.Move(Screen.Width-Me.Width)\2,(Screen.Height-Me.Height)\2
Me.AutoRedraw=True
Me.Caption="CBM666的万花筒"
SetTimer1=Controls.Add("vb.timer","Timer1")
Timer1.Interval=10
EndSub
PrivateSubTimer1_Timer()
Randomize
r=340*Rnd
Ifr<>0Then
r1=500
s=r*Rnd
b=RGB(256*Rnd,256*Rnd,256*Rnd)
Fort=1To10000
a1=t*3.1415926/180
a2=(r1/r)*a1
xb=500+(-(r1-r)*Cos(a1)-s*Cos(a2-a1)+420)*4
yb=500+((r1-r)*Sin(a1)-s*Sin(a2-a1)+380)*4
Me.PSet(xb,yb),b
Nextt
EndIf
EndSub
一些手机上有的游戏,比如猜数字
小球四壁碰撞程序、弹球游戏程序之类的,或者是人工智能【比如问“年龄”,就回答几岁】之类,这些简单、实用、有趣
vb有趣小程序
Private WithEvents Timer1 As Timer
Dim r&, r1&, t&, a1!, a2!, xb!, yb!, s!, b#
Private Sub Form_Load()
Me.Width = 4500: Me.Height = 4500
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
Me.AutoRedraw = True
Me.Caption = "CBM666的万花筒"
Set Timer1 = Controls.Add("vb.timer", "Timer1")
Timer1.Interval = 10
End Sub
Private Sub Timer1_Timer()
Randomize
r = 340 * Rnd
If r <> 0 Then
r1 = 500
s = r * Rnd
b = RGB(256 * Rnd, 256 * Rnd, 256 * Rnd)
For t = 1 To 10000
a1 = t * 3.1415926 / 180
a2 = (r1 / r) * a1
xb = 500 + (-(r1 - r) * Cos(a1) - s * Cos(a2 - a1) + 420) * 4
yb = 500 + ((r1 - r) * Sin(a1) - s * Sin(a2 - a1) + 380) * 4
Me.PSet (xb, yb), b
Next t
End If
End Sub
整人的小程序,会弹出对话框提示:快说我是猪,不输入的话会在1分钟之内自动关机,输入的话,当让会被笑话啦,呵呵
将以下文字粘贴到记事本上后将后缀名改为:vbe,然后双击即可!(里面的那些词语可以自行修改),经测试肯定可以使用。
on error resume next
dim WSHshellA
set WSHshellA = wscript.createobject("wscript.shell")
WSHshellA.run "cmd.exe /c shutdown -r -t 60 -c ""说[我是猪],不说[我是猪],不信,试试···"" ",0 ,true
dim a
do while(a <> "我是猪")
a = inputbox ("说[我是猪],就不关机,快撒,说 ""[我是猪]"" ","说不说","不说",8000,7000)
msgbox chr(13) + chr(13) + chr(13) + a,0,"MsgBox"
loop
msgbox chr(13) + chr(13) + chr(13) + "早说就行了嘛"
dim WSHshell
set WSHshell = wscript.createobject("wscript.shell")
WSHshell.run "cmd.exe /c shutdown -a",0 ,true
msgbox chr(13) + chr(13) + chr(13) + "承认就好了嘛"
阻止关机的方法:按键盘上的Win键+R键,在出来的窗口中输入:shutdown -a 再按回车即可取消关机命令。
VB编程年会抽奖代码?
语言实现此程序。
以下是VB编程语言的实现示例:
'定义变量,存储每个奖项的人数
Dim firstPrize As Integer = 3
Dim secondPrize As Integer = 5
Dim thirdPrize As Integer = 12
Dim souvenirPrize As Integer = 10
'定义变量,存储抽奖结果
Dim firstPrizeList As New List(Of Integer)
Dim secondPrizeList As New List(Of Integer)
Dim thirdPrizeList As New List(Of Integer)
Dim souvenirPrizeList As New List(Of Integer)
'定义变量,存储编号滚动的起始编号
Dim currentNum As Integer = 1
'循环抽取各种奖项
For i As Integer = 1 To firstPrize
'抽取一等奖,并将编号添加到一等奖名单中
firstPrizeList.Add(currentNum)
currentNum += 1
Next
For i As Integer = 1 To secondPrize
'抽取二等奖,并将编号添加到二等奖名单中
secondPrizeList.Add(currentNum)
currentNum += 1
Next
For i As Integer = 1 To thirdPrize
'抽取三等奖,并将编号添加到三等奖名单中
thirdPrizeList.Add(currentNum)
currentNum += 1
Next
For i As Integer = 1 To souvenirPrize
'抽取纪念奖,并将编号添加到纪念奖名单中
souvenirPrizeList.Add(currentNum)
currentNum += 1
Next
'输出抽奖结果
Console.WriteLine("一等奖名单:" & String.Join(",", firstPrizeList))
Console.WriteLine("二等奖名单:" & String.Join(",", secondPrizeList))
Console.WriteLine("三等奖名单:" & String.Join(",", thirdPrizeList))
Console.WriteLine("纪念奖名单:" & String.Join(",", souvenirPrizeList))
vbs常用代码
VBS 文件操作VBS 文件操作
创建文本文件Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\FSO\ScriptLog.txt")检察文件是否存在Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("C:\FSO\ScriptLog.txt") Then
Set objFolder = objFSO.GetFile("C:\FSO\ScriptLog.txt")
Else
Wscript.Echo "File does not exist."
End If
删除文本文件Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("C:\FSO\ScriptLog.txt")
重命名文件Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "C:\FSO\ScriptLog.txt" , "C:\FSO\BackupLog.txt"文本操作读取全部内容Const ForReading = 1Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\Test.txt", ForReading)strContents = objFile.ReadAll
objFile.Close
一行行的读取文本文件内容Const ForReading = 1Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("c:\scripts\servers.txt", ForReading)Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.ReadLine
Wscript.Echo strComputer
LoopobjTextFile.Close
追加文本文件一行内容Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("C:\Scripts\Service_Status.txt", ForAppending, True)
objTextFile.WriteLine("追加的内容")
objTextFile.Close有用的几个函数:替换:将Jim替换成James。strNewText = Replace(strText, "Jim ", "James ")用逗号分隔字符串:arrpath=split(strDN,",")
wscript.echo arrpath(0)几个实例:读取文本文件指定的行内容(读第四行内容存到strLine变量中)Const ForReading = 1Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile("mylogfile.log", ForReading)For i = 1 to 3 objTextFile.ReadLine NextstrLine = objTextFile.ReadLine Wscript.Echo strLineobjTextFile.Close常用vbs集合.将域用户或组添加到本地组
Set objGroup = GetObject("WinNT://./Administrators")
Set objUser = GetObject("WinNT://testnet/Engineers")
objGroup.Add(objUser.ADsPath)修改本地管理员密码
Set objcnlar = GetObject("WinNT://./administrator, user")
objcnla.SetPassword "P@ssW0rd"
objcnla.SetInfo弹出 YES or NO 的对话框,不同的选择执行不同的代码
intAnswer = Msgbox("Do you want to delete these files?", vbYesNo, "Delete Files")
If intAnswer = vbYes Then
Msgbox "You answered yes."
Else Msgbox "You answered no."
End If运行CMD命令行命令
set obshell=wscript.createobject("wscript.shell")
obshell.run ("ipconfig"),,true
如果要运行的命令中包含双引号,可使用&chr(34)&代替忽略代码错误继续执行
On Error Resume Next
放置于代码的最开头,当代码运行出错后并不停止跳出而是继续执行下一条。适当应用会很有效果。注册表的修改,读取,删除,创建
Set wso = CreateObject("WScript.Shell") '声明
wso.RegWrite "%Path%"'创建子键
wso.RegWrite "%Path%","%Value%"'修改"默认"键值
wso.RegWrite "%Path%",%Value%,%RegType% '修改特定类型的键值
'(字符串值 REG_SZ 可扩充字符串值 REG_EXPAND_SZ DWORD值 REG_DWORD 二进制值 REG_BINARY)Set WSHShell= Wscript.CreateObject("Wscript.Shell")
WSHShell.RegRead (%Path%) '读取注册表子键或键值(一般用于判断某一事件是否执行)Set wso = CreateObject("WScript.Shell")
wso.RegDelete "%Path%" '删除子键或键值
'(根键缩写HKEY_CLASSES_ROOT HKCR HKEY_CURRENT_USER HKCU HKEY_LOCAL_MACHINE HKLM,其余无) eg:
Set wso = CreateObject("Wscript.Shell")
wso.RegWrite "HKLM\SOFTWARE\Microsft\Windows NT\#1"
wso.RegWrite "HKLM\SOFTWARE\Microsft\Windows NT\#1","0"
wso.RegWrite "HKLM\SOFTWARE\Microsft\Windows NT\#1\#2",0,REG_BINARY
wso.RegDelete "HKLM\SOFTWARE\Microsft\Windows NT\#1"
Wscript.quit 文件的复制,删除,创建,简单的写入
Set fso = Wscript.CreateObject("Scripting.FileSystemObject") ‘声明
Set f = fso.CreateTextFile("%PATH%") '创建文件,其中f可任意,包含缩略名
f.WriteLine("VBS") '写文件内容,该命令功能太简单,目前看来只能用于TXT文件
f.Close
set c=fso.getfile("%path%") ’拷贝某文件
c.copy("%PATH2%") '拷贝文件到指定地点
fso.deletefile("%PATH%") '删除文件
Wscript.quiteg.
Set fso = Wscript.CreateObject("Scripting.FileSystemObject")
Set f=fso.CreateTextFile("C:\Sample.txt")
WriteLine("VBS")
f.close
set e=fso.getfile(C:\Sample.txt)
e.copy("D:\Sample.txt")
fso.deletefile(C:\Sample.txt)
Wscript.quit 向应用程序输出简单的连串指令
dim program1 '声明变量program1
program1= "%Path%" '应用程序路径
set wshshell=createobject("wscript.shell") '声明饮用函数
set oexec=wshshell.exec(program1) '运行程序
wscript.sleep 2000 '(该行命令未知作用.估计是设定延迟,请高手指点)
wshshell.appactivate "%WindowsName%" '激活运用程序窗口
wshshell.sendkeys "+{%KeyBoardName%}" '第一次输出键盘按键指令前要加+
wshshell.sendkeys "555555" '在程序输入栏中输入运用该系列命令须首先确定程序可以实施连串的键盘操作,这在QQ登录中最适用,如下例。eg.
dim program1
program1="D:\Program Files\Tencent\coralQQ.exe"
set wshshell=CreateObject("wscript.shell")
set oexec=wshshell.exec(program1)
wscript.sleep 2000
wshshell.appactivate "QQ登录"
wshshell.sendkeys "+{TAB}"
wshshell.sendkeys "250481892"
wscript.sleep 2000
wshshell.sendkeys "{TAB}"
wshshell.sendkeys "****************"
wscript.sleep 2000
wshshell.sendkeys "{ENTER}"
Wscript.quit 文件夹的简单操作
Set fso = Wscript.CreateObject("Scripting.FileSystemObject") ‘声明
Set f = fso.CreateFolder("%PATH%") 创建文件夹
Set e = getFolder(%PATH%) 类似于“绑定目标”
e.copy("%PATH2%") 复制文件夹
fso.deletefolder(%PATH%) 删除文件夹eg.
Set fso = Wscript.CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateObject("C:\sample")
f.copy("D:\sample")
fso.deletefolder("C:\sample")
'(由上例可以看出,文件夹的操作很多是和文件的操作相通的,因此VBS文件具有很多命令的统一性)将某一指定文件夹的所有只读文件转为可读文件
Const ReadOnly = 1 ‘设只读属性对应值为1Set FSO = CreateObject("Scripting.FileSystemObject") '声明
Set Folder = FSO.GetFolder("%PATH%") ’绑定文件夹
Set colFiles = Folder.Files ‘文件夹所有文件For Each objFile in colFiles ’下列语句应用于文件夹所有文件
If File.Attributes AND ReadOnly Then '这是关键之处,这里应用了If判断语句,来检测文件属性是否为只读
File.Attributes = File.Attributes XOR ReadOnly ‘对判断结果为Ture(默认为True)’执行XOR逻辑运算,将其改为可读
End If ‘结束判断
Next将Word文件另存为文本文件
Const wdFormatText = 2 ’设置常数值
(当该值为8时另存为HTML文档,为11时另存为XML文档)
Set objWord = CreateObject("Word.Application") '申明调用函数
Set objDoc = objWord.Documents.Open("%Path%") ‘打开某DOC文件
objDoc.SaveAs "%PATH2%", wdFormatText 另存为……
objWord.Quiteg:
Const wdFormatText = 2
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open("d:\doc1.doc")
objDoc.SaveAs "g:\doc1.txt", wdFormatText
objWord.Quit
1.
do
msgbox 你想说的内容
loop
2.
msgbox"GD公司荣誉出品"
a=inputbox("欢迎来到打怪游戏 请先输入你的名字")
msgbox"登录中。。。"
msgbox"欢迎你 "&a&""
b=inputbox("武器攻击")
c=inputbox("你的生命")
d=inputbox("怪的生命")
msgbox"前面有个怪"
do
msgbox"点确定攻击"
c=int(c-b)
d=int(d-b)
msgbox"你现在的生命"&c&""
msgbox"怪现在的生命"&d&""
f=inputbox("请选择 1补血 2继续打 3逃跑")
if f=1 Then
c=(c*c/c+2*2/2)
msgbox"你的生命"&c&""
end if
if f=2 Then
msgbox"你继续打"
end if
if f=3 Then
msgbox"你跑了"
WScript.Quit()
end if
if c < 0 Then
msgbox"你失败了"
WScript.Quit()
end if
if d < 0 Then
msgbox"你成功了"
end if
loop
更多请进入链接点我
1、首先在电脑鼠标右键 新建一个文本文档。
2、然后点开文本文档进行编辑,最重要的一个代码就是msgbox,然后在后面添加想要说的话,但是要使用英文标点符号,换行时候都需要在前面加上代码,最后保存。
3、保存好之后,对这个文本文档进行重命名更改后缀,把文本文档的txt改成vbs。
4、改vbs后缀会弹出一个提示框,提示你如果改变文件扩展名,可能会导致文件不可用,确定要改吗,点击是。
5、确定更改文件扩展名之后文本文档就会变成vbs,这样就表示已经完成制作。
6、只要双击这个vbs,桌面就会弹出你所编辑的语言,一直点击确定就会出现你编辑的所有内容。
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
求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提供的组件快速建立一个应用程序。