vb programming lab report 2

各位哥哥姐姐帮忙写下VB实验报告写1程序代码和实验过程2结果分析谢谢拉

‘1.新建个vb6工程,一个窗体文件;

‘2.复制下面代码到新窗体的代码页中:

OptionExplicit

PrivateDeclareFunctionSHFileOperationLib”shell32.dll”Alias”SHFileOperationA”(lpFileOpAsSHFILEOPSTRUCT)AsLong

PrivateConstFO_MOVE=&H1

PrivateConstFO_COPY=&H2

PrivateConstFO_DELETE=&H3

PrivateConstFO_RENAME=&H4

PrivateConstFOF_MULTIDESTFILES=&H1

PrivateConstFOF_CONFIRMMOUSE=&H2

PrivateConstFOF_SILENT=&H4’don’tcreateprogress/report

PrivateConstFOF_RENAMEONCOLLISION=&H8

PrivateConstFOF_NOCONFIRMATION=&H10’Don’tprompttheuser.

PrivateConstFOF_WANTMAPPINGHANDLE=&H20’FillinSHFILEOPSTRUCT.hNameMappings

PrivateTypeSHFILEOPSTRUCT

hwndAsLong

wFuncAsLong

pFromAsString

pToAsString

fFlagsAsInteger

fAbortedAsBoolean

hNameMapsAsLong

sProgressAsString

EndType

‘————————————————————

PrivateConstmstrPathExeFromAsString=”E:\TestExe.exe”‘pathofsourceexefile

PrivateConstmstrPathTxtFromAsString=”E:\TestTxt.txt”‘pathofsourcetxtfile

PrivateConstmstrPathExeToAsString=”C:\Test”‘pathoftargetexefile

PrivateConstmstrPathTxtToAsString=”C:\TestTxt”‘pathoftargettxtfile

PrivateConstmlngNumberAsLong=100’numberofcopy

PrivateConstmstrExtentionExe=”.exe”

PrivateConstmstrExtentionTxt=”.txt”

‘copyfunction

FunctionShellFileOP(sFileArrayAsString,sDestinationAsString,iFlgAsInteger)AsLong

DimrAsLong

DimsFilesAsString

DimSHFileOpAsSHFILEOPSTRUCT

Debug.PrintsFileArray

WithSHFileOp

SelectCaseiFlg

Case1

.wFunc=FO_COPY

Case2

.wFunc=FO_MOVE

CaseElse

EndSelect

.pFrom=sFileArray

.pTo=sDestination

.fFlags=FOF_SILENT+FOF_NOCONFIRMATION

EndWith

ShellFileOP=SHFileOperation(SHFileOp)

DoEvents

EndFunction

PrivateSubForm_Load()

DimnretAsLong

DimiAsLong

OnErrorGoToERR_TRAP

‘copytoC:\

Fori=1TomlngNumber

‘ExeFile

nret=ShellFileOP(mstrPathExeFrom,mstrPathExeTo&i&mstrExtentionExe,1)

‘TxtFile

nret=ShellFileOP(mstrPathTxtFrom,mstrPathTxtTo&i&mstrExtentionTxt,1)

Nexti

‘projectclose

End

ExitSub

ERR_TRAP:

MsgBoxErr.Number&”:”&Err.Description,vbCritical,”saveerror”

ExitSub

EndSub

‘3.按照实际情况,更改上面几个文件的路径和名称

VB Programming Lab Report – Procedures and Functions, seek expert help, urgent, I want to program design interface, program code, run results.

PrivateFunctionADD(ByRefxAsInteger,ByRefyAsInteger)AsInteger

ADD=x+y

EndFunction

PrivateFunctionMulti( xAsInteger,yAsInteger)AsInteger

Multi=x*y

EndFunction

PrivateSubCommand1_Click()

x=CInt(InputBox(“Please enter the value of x:” , “Assign”))

y=CInt(InputBox(“Please enter the value of y: “, “Assign”))

Sum=ADD(Int(x),Int(y))

Text1.Text=CStr(x)+”+”+”+CStr(y)+”=”+CStr(Sum)

EndSub

PrivateSubCommand2_Click()

x=CInt(InputBox(“Please enter the value of x:”, “Assign”))

y=CInt(InputBox(“Please enter the value of y:”, “Assign”))

cheng=Multi(Int(x),Int(y))

Text1.Text=CStr(x)+”*”+CStr(y)+”=”+CStr(cheng)

EndSub

VB实验报告

DeclareFunctionFindWindowLib”user32″Alias”FindWindowA”(ByVallpClassNameAsString,ByVallpWindowNameAsString)AsLong

DeclareFunctionPostMessageLib”user32″Alias”PostMessageA”(ByValhwndAsLong,ByValwMsgAsLong,ByValwParamAsLong,lParamAsAny)AsLong

PublicConstWM_CLOSE=&H10

PrivateSubForm_Load()

DimwinHwndAsLong

DimRetValAsLong

winHwnd=FindWindow(vbNullString,”foxmail.exe”)

Debug.PrintwinHwnd

IfwinHwnd<>0Then

RetVal=PostMessage(winHwnd,WM_CLOSE,0&,0&)

IfRetVal=0Then

MsgBox”ÖÃÈëÏûÏ¢´íÎ󣡔

EndIf

Else

MsgBox”CalculatorûÓдò¿ª£¡”

EndIf

EndSub

用来关闭FOXMAIL系统进程的!