VBvb记事本程序问题

vb中程序错误类型主要有哪三种?_百度知道温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
一个具有十足耐力和不屈不挠精神的人,
一个有高度责任感以及惊人持久力的人。
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(3680)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_083',
blogTitle:'VB程序错误处理方法小结',
blogAbstract:'大家知道,即使程序员抱有最好的愿望,而且计划工作做得非常周密,也无法避免代码出现错误。实际上可能出现的程序错误是很多的,但是它们基本上可以分为两种类型:一种是编译错误;另一种是运行期错误。编译错误是指使得Visual Bacsic(下面简称VB)的编译器无法对代码进行编译的错误。如果一个过程中包含了编译错误,VB将不执行该过程,并且我们也不能向用户提供带有编译错误的运行期版本应用程序,大多数编译错误是句法错误造成的。
  一、VB的编译选项
  VB有两个柚孟罨嵩诤艽蟪潭壬嫌跋煳颐谴唇ǚ浅<崾档拇氲哪芰ΑR桓錾柚孟钍荂ompile On Demand(按需要进行编译),另一个设置项是Backgroun',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:4,
publishTime:2,
permalink:'blog/static/',
commentCount:1,
mainCommentCount:1,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'一个具有十足耐力和不屈不挠精神的人,\r\n一个有高度责任感以及惊人持久力的人。',
hmcon:'0',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
For i = 1 To 20 '虽然要求是20,但是在i=10的时候long型就已经越界了,所以不可能达到20,当然代码就是这样,要是想试试效果把20改成9,运行下就好了
TextBox1.Text = TextBox1.Text & & & & Process(i)
Private Function Process(ByVal index As Integer)
If index = 1 Then
Process = 1
ElseIf index = 2 Then
Process = 2
Dim a As Long, b As Long
a = Process(index - 1)
b = Process(index - 2)
Process = a * a - b * b
End Function
附近的朋友等待您的帮助
包打听移动版vb中调用exe程序的问题*(要求主程序等待exe执行结束) -VB- TryCatch
>> Content
vb中调用exe程序的问题*(要求主程序等待exe执行结束)
vb中调用公司做的exe程序,我用的shell,要求主程序等待exe执行结束后继续执行,怎么实现呢?
------Solutions------
Private&Declare&Function&TerminateProcess&Lib&"kernel32"&(ByVal&ApphProcess&As&Long,&ByVal&uExitCode&As&Long)&As&LongPrivate&Declare&Function&OpenProcess&Lib&"kernel32.dll"&(ByVal&dwDesiredAccess&As&Long,&ByVal&bInheritHandle&As&Long,&ByVal&dwProcessId&As&Long)&As&LongPrivate&Declare&Function&GetExitCodeProcess&Lib&"kernel32.dll"&(ByVal&hProcess&As&Long,&ByRef&lpExitCode&As&Long)&As&LongPrivate&Declare&Sub&Sleep&Lib&"kernel32.dll"&(ByVal&dwMilliseconds&As&Long)Private&Const&PROCESS_QUERY_INFORMATION&As&Long&=&(&H400)Private&Const&STILL_ACTIVE&As&Long&=&&H103Dim&mProcID&As&LongSub&ShellWait(FileName&As&String,&IsWait&As&Boolean)Dim&hShell&As&LongDim&hProc&As&LongDim&lExit&As&LonghShell&=&Shell(FileName,&vbNormalFocus)mProcID&=&hShellhProc&=&OpenProcess(PROCESS_QUERY_INFORMATION,&False,&hShell)If&IsWait&=&True&Then&&&&Do&&&&&&&&GetExitCodeProcess&hProc,&lExit&&&&&&&&Delay&0.1&&&&Loop&While&lExit&=&STILL_ACTIVEEnd&IfEnd&SubPrivate&Sub&Delay(ss&As&Single)Dim&I&As&SingleFor&I&=&0.1&To&ss&Step&0.1&&&&Sleep&100&&&&DoEventsNext&IEnd&SubPrivate&Sub&Command1_Click()ShellWait&"C:\WINNT\system32\calc.exe",&TrueMsgBox&"运行完毕!"End&Sub
------Solutions------
http://studio.imagemagick.org/pipermail/magick-users/2002-May/002847.html通过waitforsingleobject来等待命令执行结束。
------Solutions------
/search?hl=zh-CN&q=shell+%26+wait+vb&btnG=Google+%E6%90%9C%E7%B4%A2&lr=
------Solutions------
如何判定VB调用的一个EXE程序已经结束.回答:新建一个项目,添加命令按钮和标签各一个,加上以下代码,然后运行....Option&ExplicitDim&DemoFile$Private&Const&NORMAL_PRIORITY_CLASS&=&&H20&'如果进程位于前台,则基本值是9;如果在后台,则优先值为7Private&Const&INFINITE&=&&HFFFFFFFFPrivate&Const&WAIT_TIMEOUT&=&&H102&&'对象保持未发出信号的状态,但等待超时时间已经超过&'说明∶PROCESS_INFORMATION结构由CreateProcess函数将关于新建立的进程和'主要线索的信息写入其中成员变量Private&Type&PROCESS_INFORMATION&'hProcess&As&LonghThread&As&LongdwProcessId&As&LongdwThreadId&As&LongEnd&Type&'说明∶STARTUPINFO结构用在CreateProcess函数中指定为新进程建立的新窗口的主要属性。这一'一信息影响由CreateWindows函数建立的第一个窗口Private&Type&STARTUPINFOcb&As&LonglpReserved&As&StringlpDesktop&As&StringlpTitle&As&StringdwX&As&LongdwY&As&LongdwXSize&As&LongdwYSize&As&LongdwXCountChars&As&LongdwYCountChars&As&LongdwFillAttribute&As&LongdwFlags&As&LongwShowWindow&As&IntegercbReserved2&As&IntegerlpReserved2&As&LonghStdInput&As&LonghStdOutput&As&LonghStdError&As&LongEnd&Type&Private&Declare&Function&CloseHandle&Lib&"kernel32"&(ByVal&hObject&As&Long)&As&LongPrivate&Declare&Function&WaitForSingleObject&Lib&"kernel32"&(ByVal&hHandle&As&Long,&ByVal&dwMilliseconds&As&Long)&As&LongPrivate&Declare&Function&CreateProcess&Lib&"kernel32"&Alias&"CreateProcessA"&(ByVal&lpApplicationName&As&String,&ByVal&lpCommandLine&As&String,&ByVal&lpProcessAttributes&As&Long,&ByVal&lpThreadAttributes&As&Long,&ByVal&bInheritHandles&As&Long,&ByVal&dwCreationFlags&As&Long,&lpEnvironment&As&Any,&ByVal&lpCurrentDirectory&As&String,&lpStartupInfo&As&STARTUPINFO,&lpProcessInformation&As&PROCESS_INFORMATION)&As&LongPrivate&Declare&Function&WaitForInputIdle&Lib&"user32"&(ByVal&hProcess&As&Long,&ByVal&dwMilliseconds&As&Long)&As&Long&&&&Private&Sub&command1_Click()Dim&res&Dim&sinfo&As&STARTUPINFODim&pinfo&As&PROCESS_INFORMATIONsinfo.cb&=&Len(sinfo)sinfo.lpReserved&=&vbNullStringsinfo.lpDesktop&=&vbNullStringsinfo.lpTitle&=&vbNullStringsinfo.dwFlags&=&0&Label1.Caption&=&"正在启动程序"Label1.Refresh'&CreateProcess函数,用于创建一个新的进程res&=&CreateProcess(DemoFile,&vbNullString,&0,&0,&True,&_NORMAL_PRIORITY_CLASS,&ByVal&0&,&vbNullString,&sinfo,&pinfo)If&res&ThenLabel1.Caption&=&"程序正在运行"WaitForTerm&pinfoEnd&IfLabel1.Caption&=&"程序已经结束"&End&Sub&Private&Sub&WaitForTerm(pinfo&As&PROCESS_INFORMATION)Dim&res&'&等待指定的进程进入空闲状态,,空闲(Idle)指的是进程准备处理'一条消息、但目前暂时没有消息需要处理的一种状态Call&WaitForInputIdle(pinfo.hProcess,&INFINITE)'&关闭指定进程Call&CloseHandle(pinfo.hThread)Command1.Enabled&=&FalseLabel1.RefreshDo'等待发出信号res&=&WaitForSingleObject(pinfo.hProcess,&0)If&res&&&&WAIT_TIMEOUT&Then&'如果对象发出了信号Exit&DoEnd&IfDoEventsLoop&While&TrueCommand1.Enabled&=&TrueCall&CloseHandle(pinfo.hProcess)End&Sub&Private&Sub&Form_Load()DemoFile&=&InputBox$("请输入需要运行的程序名",&,&"C:\WINDOWS\notepad.exe")End&Sub-星泽(xing)&&回答二:例程如下:&Option&Explicit&Private&Declare&Function&OpenProcess&Lib&"kernel32"&(ByVal&dwDesiredAccessAs&Long,&_ByVal&bInheritHandle&As&Long,&ByVal&dwProcessId&As&Long)&As&LongPrivate&Declare&Function&GetExitCodeProcess&Lib&"kernel32"&(ByVal&hProcessAs&Long,&_lpExitCode&As&Long)&As&LongPrivate&Declare&Function&CloseHandle&Lib&"kernel32"&(ByVal&hObject&As&Long)As&Long&Private&Const&PROCESS_QUERY_INFORMATION&=&&H400Private&Const&STATUS_PENDING&=&&H103&Private&Sub&RunShell(cmdline&As&String)Dim&hProcess&As&LongDim&ProcessId&As&LongDim&ExitCode&As&LongProcessId&=&Shell(cmdline,&1)hProcess&=&OpenProcess(PROCESS_QUERY_INFORMATION,&False,&ProcessId)DoCall&GetExitCodeProcess(hProcess,&ExitCode)DoEventsLoop&While&ExitCode&=&STATUS_PENDINGCall&CloseHandle(hProcess)MsgBox&cmdline&&&"已经关闭"End&Sub&Private&Sub&Command1_Click()RunShell&"c:\windows\notepad.exe"End&Sub
------Solutions------
同意,用WAITFORSINGLEOBJECT这个API。
------Solutions------
收集的资料:希望某一&VB&程序利用&Shell&执行某一个外部程序(假设是&notepad.exe)之后,就一直等到此一程序结束执行时,&才回到&VB&程序继续执行,&该怎么办到呢?  当我们调用&Shell&时,&会传回一个数值,&此一数值称为&Process&Id,&利用此一&Process&Id,&我们可以调用&OpenProcess&API&取得&Process&Handle,&然后再利用&Process&Handle&调用&WaitForSingleObject,&即可等待被&Shell&执行的程序执行完毕,&才继续向下执行。细节如下:  1.&API&的声明:  Const&SYNCHRONIZE&=&&H100000  Const&INFINITE&=&&HFFFFFFFF  Private&Declare&Function&OpenProcess&Lib&"kernel32"&(ByVal&dwDesiredAccess&As&Long,&ByVal&   bInheritHandle&As&Long,&ByVal&dwProcessId&As&Long)&As&Long  Private&Declare&Function&CloseHandle&Lib&"kernel32"&(ByVal&hObject&As&Long)&As&Long  Private&Declare&Function&WaitForSingleObject&Lib&"kernel32"&(ByVal&hHandle&As&Long,&ByVal&  dwMilliseconds&As&Long)&As&Long  注:如果以上的声明放在「一般模块」底下,&应将&Declare&之前的&Private&保留字去掉,&并且在&Const&之前加上&Public&保留字。  2.&程序范例:(以执行&Notepad&程序为例)  Dim&pId&As&Long,&pHnd&As&Long&'&分别声明&Process&Id&及&Process&Handle&变数  pId&=&Shell("Notepad",&vbNormalFocus)&'&Shell&传回&Process&Id  pHnd&=&OpenProcess(SYNCHRONIZE,&0,&pId)&'&取得&Process&Handle  If&pHnd&&&&0&Then  Call&WaitForSingleObject(pHnd,&INFINITE)&'&无限等待,直到程序结束  Call&CloseHandle(pHnd)  End&Ifvb程序问题_百度知道

我要回帖

更多关于 vb记事本程序 的文章

 

随机推荐