GehryTechnologyDigitalProjectVBA代碼編寫教程課件_第1頁(yè)
GehryTechnologyDigitalProjectVBA代碼編寫教程課件_第2頁(yè)
GehryTechnologyDigitalProjectVBA代碼編寫教程課件_第3頁(yè)
GehryTechnologyDigitalProjectVBA代碼編寫教程課件_第4頁(yè)
GehryTechnologyDigitalProjectVBA代碼編寫教程課件_第5頁(yè)
已閱讀5頁(yè),還剩253頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

VBAinDPWithexcerptfrom‘HowtoThinkLikeaComputerScientist’byJeffreyElkner,AllenB.Downey,andChrisMeyersVBAinDPWithexcerptfrom‘HoThingstoConsiderinProgrammingVBAinDPThingstoConsiderinProgrammProgrammingforDesignersLetcomputertodomundaneworkandsavetime/resourcesGenerate(parametric)designswithlotsofvariationsNewwayofdesign,orconstruction::Lookscool,mayearnmore?ProgrammingforDesignersLetcTimetothinkinadifferentwayFormulateproblemsGoalInput/OutputDriving/DrivenThinkcreativelyaboutsolutionsMethodologyProcedureRepresentasolutionclearlyandaccuratelyDiagramDictationTimetothinkinadifferentwProgrammingLanguageNaturallanguageWhatpeoplespeakEnglish,French,Korean,…FormallanguageDesignedforspecificapplicationsMathematicalformula,ChemicalstructureProgramminglanguage,ofcourseProgrammingLanguageNaturallaVBA–VisualBasicforApplicationVBforApplicationIntegratedintohostapplicationAutomateprocessesVisualBasicHighlevelprogramminglanguagedesignedtobelearnedandusedeasilyOneoftheprogramminglanguagesforDPCATScript,VBA,.NET,…VBAisincludedinastandardDPinstallationVBA–VisualBasicforApplicaVBA–VisualBasicforApplicationInterpreterCompilerVBA–VisualBasicforApplicaProgramAsequenceofinstructionsspecifyingcomputationsInstructionsInputOutputMathConditionalexecutionRepetitionProgramAsequenceofinstructiDebuggingFixingerrorsErrorsSyntaxerrorRuntimeerrorSemanticerrorDebuggingFixingerrorsGlossaryAlgorithmAgeneralprocessforsolvingacategoryofproblemsExceptionAnothernameforaruntimeerrorScriptAprogramstoredinafile(usuallyonethatwillbeinterpreted)GlossaryAlgorithmVariables,ExpressionsandStatementsVBAinDPVariables,ExpressionsandStaValueandDataTypesValueLetter,number,…Abc,aaa,…1,2,3,…,DatatypesString,Integer,Double,…ValueandDataTypesValueVariablesAnamethatreferstoavalueVariablenamesaa=1bb=“names”Keywordand,if,for,while,sub,function,...VariablesAnamethatreferstoStatementsStatementisacompleteinstructionthatcancontainkeywords,operators,variables,constants,andexpressions.Operators:+,-,*,/,…Constant:fixed(constant)variable SetpartDocument1=CATIA.ActiveDocumentDeclarationstatementsnameavariable,constant,orprocedureandcanalsospecifyadatatypeDimpartDocument1AsPartDocumentExecutablestatementsinitiateactionsselect1.Search("name='Optimization.MinimumValue',all")StatementsStatementFunctionsVBAinDPFunctionsVBAinDPFunctionAnamedsequenceofstatementsthatperformsadesiredoperation.ThisoperationisspecifiedinafunctiondefinitionSubmySubName()MsgBox"Hello"EndSubSubmySubwithParameter(myParameter)MsgBoxmyParameterEndSubFunctionAnamedsequenceofsSub/FunctionSubNoreturnvalueFunctionWithareturnvalueSubmySubName()MsgBox"Hello"EndSubFunctionmyFunction()myFunction="Hi"EndSubSubcallFunction()MsgboxmyFunctionEndSubSub/FunctionSubSubmySubNameConditionalExecutionVBAinDPConditionalExecutionVBAinDPConditionalExecutionDoingdifferentcomputationsdependingon(boolean)conditionsIf…Then…(ElseIf…Then..)(Else…)EndifSelectCase…Case…CaseElse…EndSelectConditionalExecutionDoingdifBooleanconditionAnumericexpressionorstringexpressionthatevaluatestoTrueorFalseComparisonOperatorsUsedtocompareexpressions.<,<=,>,>=,=,<>Var1<Var2And,Or,Not,XorOperatorVar1<Var2AndVar1>Var3BooleanconditionAnumericexpIF…Then…ElseStatementIfconditionThenstatements[Elseelsestatements]'Or,youcanusetheblockformsyntax:IfconditionThen

[statements][ElseIfcondition-nThen

[elseifstatements]]...[Else

[elsestatements]]EndIfIfA>10Then A=A-10ElseIfA<10Then A=A+10Else A=0EndIfIF…Then…ElseStatementIfSelectCaseStatementSelectCasetestexpression

[Caseexpressionlist-n

[statements-n]]...

[CaseElse

[elsestatements-n]]EndSelectDimColor,MyVarSubChangeBackground(Color)MyVar=lcase(Color)SelectCaseMyVarCase"red"document.bgColor="red"Case"green"document.bgColor="green"Case"blue"document.bgColor="blue"CaseElseMsgBox"pickanothercolor"EndSelectEndSubSelectCaseStatementSelectCIterationVBAinDPIterationVBAinDPIterationArepetitionofaprocessFor…NextForEach…NextDo…LoopWhile..WendIterationArepetitionofaproFor…Nextj=0Fori=0to10 j=j+iNextMsgBox"TheJis"&jFori=0to10Step2 j=j+iNextMsgBox"TheJisnow"&jFor…Nextj=0For...NextStatementForcounter=startToend[Stepstep]

[statements]

[ExitFor]

[statements]NextForI=1To10ForJ=1To10ForK=1To10...NextNextNextFor...NextStatementForcountWhile…WendCounter=0WhileCounter<10 Counter=Counter+1WendMsgBox“Counterisnow“&CounterWhile…WendCounter=0Do...LoopStatementDo[{While|Until}condition]

[statements]

[ExitDo]

[statements]LoopDo

[statements]

[ExitDo]

[statements]Loop[{While|Until}condition]Do...LoopStatementDo[{WhileDo...LoopStatementDoUntilDefResp=vbNoMyNum=Int(6*Rnd+1) 'Generatearandomintegerbetween1and6.DefResp=MsgBox(MyNum&"Doyouwantanothernumber?",vbYesNo)LoopDimCheck,CounterCheck=True:Counter=0'Initializevariables.Do'Outerloop.DoWhileCounter<20'Innerloop.Counter=Counter+1'IncrementCounter.IfCounter=10Then'IfconditionisTrue...Check=False'setvalueofflagtoFalse.ExitDo'Exitinnerloop.EndIfLoopLoopUntilCheck=False'Exitouterloopimmediately.Do...LoopStatementDoUntilDeArrayDimstudents(6)AsIntegerArrayDimstudents(6)AsIntegeObjectOrientedProgrammingVBAinDPObjectOrientedProgrammingVBAObjectOrientedProgrammingOOPisallaboutprogrammingusingsomethingcalledanobjectOOPconsistsofdesigningabunchofclassesmostofwhichwillbeusedastemplatestomakeobjectsTheobjectswillbeusedtoholddataandwillbeinitializedwithconstructorsandperformusefulfunctionsbybeingaskedtoruntheirmethodsFromCS1322lectureslideObjectOrientedProgrammingOOPWhatisanobject?Achunkofmemorywhichcontainssomedataandmethodswhichcanoperateonthedata.Somethingthatwhencreatedmayhavehadspecialcoderuntoinitializeit.SomethingwhichhasadditionalbehaviordefinedbymethodswhichcanBepasseddataviaparametersPerformcalculations/operationswhichmayChangesomeofitsdataPerformsomedesiredoperationReturnthevalueofsomeofitsdataReturntheresultsofcalculationsusingbothdatapassedinanddatacontainedintheobjectFromCS1322lectureslideWhatisanobject?AchunkofmHowdowedefinedifferenttypesofobjects?Foreachdifferenttypeofobjectwewriteaclass.NewclassesmaybebasedonexistingclassestoallowcodereuseAclassservesasablueprintortemplatedefininghowallobjectsmadefromthisclassoperateandwhatdatatheyhold.OneclassmaybeusedtomakeoneormanyobjectsFromCS1322lectureslideHowdowedefinedifferenttypClass:Itdescribestheformofanobject.Itisatemplateorblueprint.Itspecifiesdatarepresentation,behavior,andinheritance

(viavariables,methodsandparents)Object:Itisaninstanceofaclass.Ithasauniquecopyofeverynon-staticvariable.(i.e.,the“instancevariables”butnottheclassvariables(thoselabeledwith“static”).NamingConventions:

Classes:Identifiersbeginwithcaplettersforeachwordintheidentifier,e.g.,classGraduateStudent

Objects:Identifiersbeginswithlowercaseletter,thencapsforotherwordsinidentifier,e.g.,graduateStudentPresident

Differencebetween“aclassandanobjectofthatclass”isanalogoustothedifferencebetween“atypeandavariableofthattype”.KeyIdeaClassesandObjectsFromCS1322lectureslideClass:Object:NamingConvention3keyfeaturesAbstractdatatypesEncapsulationofdataandbehaviorClassesastemplatesusedtoproduce1ormoreinstancesorobjectsInheritanceProvidesforcode-reusePolymorphism/DynamicBindingDifferentobjectsinthesamefamilymayhaveidenticallynamedmethodsThelanguagetakescareofsortingoutthecorrectmethodtoinvokeforusFromCS1322lectureslide3keyfeaturesAbstractdatatyClassTemplateforanobject.Class...EndClassconstructVariablePropertiesMethodEventClassTemplateforanobject.ClassConstructClass...EndClassClassclassname ClassdefinitionEndClassInstantiationanobjectofaclassSetobjc=newclassnameClassConstructClass...EndClaClassVariablesClasshasvariablesDimvarName1[,varName2...]PrivatevarName1[,varName2...]PublicvarName1[,varName2...]Dim,PublicOpentooutsidePrivateClosedtooutsideClassVariablesClasshasvariaClassPropertiesAccess“wrapper”forprivatevariablesPropertyGetPropertyLet:valuePropertySet:referenceClassPropertiesAccess“wrappeClassPropertiesClassComputer PrivatemodStrType PrivateoOS PublicPropertyLetComputerType(strType) modStrType=strType EndProperty PublicPropertyGetComputerType() ComputerType=modStrType EndProperty PublicPropertySetOperatingSystem(oObj) SetoOS=oObj EndProperty PublicPropertyGetOperatingSystem() SetOperatingSystem=oOS EndPropertyEndClassClassPropertiesClassComputerClassMethodFunctionsorsubroutinesinaclassClassLaptopComputer PrivatemodOwner PublicPropertyLetCompOwner(strOwner) modOwner=strOwner EndProperty PublicPropertyGetCompOwner() CompOwner=modOwner EndProperty PublicFunctionGetOwner() GetOwner=modOwner EndFunctionEndClassClassMethodFunctionsorsubroClassEventTwoeventsareautomaticallyassociatedwitheveryclassyoucreateClass_InitializeisfiredwheneveryouinstantiateanobjectbasedonthisclassClass_TerminateiscalledwhenthescriptenginedeterminesthattherearenoremainingreferencesonanobjectClassEventTwoeventsareautoClassesinthecodeDimdocuments1AsDocumentsSetdocuments1=CATIA.DocumentsDimpartDocument1AsPartDocumentSetpartDocument1=documents1.Add("Part")PropertyMethodClassesinthecodeDimdocumenSetStatementAssignsanobjectreferencetoavariableorproperty.Setdocuments1=CATIA.DocumentsSetStatementAssignsanobjectSetStatementYoumustuseSetonlyifthereturnedvalueisanobject,butnotifitisacharacterstringoranumber.Nevertheless,characterstringandnumberdefinedasCATIAliteralsareobjectsandSetmustbeusedifaFunctionreturnsaliteralobject.Finally,youdon'thavetouseSetifyoustoreyourreturnvalueinaProperty:myObject.aggregatedObject=Object.Function(arg1,arg2,arg3)becausethereisnoactualaggregatedObjectvariable,apropertyisasyntacticalshortcutforaccessormethods,hereget_aggregatedObjectandset_aggregatedObject,allowingtopresentthosemethodsasanattributeoftheobject.Theprevioussyntaxissoequivalentto:myObject.set_aggregatedObject(Object.Function(arg1,arg2,arg3))andnoSetisrequired.SetStatementYoumustuseSetClassesinDPVBAinDPClassesinDPVBAinDPDigitalProjectClassesApplicationDocumentsPartDocumentsPartHybridShapeFactoryHybridBodiesHybridBodyReferecence..AndmoreDigitalProjectClassesApplicaSubCATMain()Dimdocuments1AsDocumentsSetdocuments1=CATIA.DocumentsDimpartDocument1AsPartDocumentSetpartDocument1=documents1.Add("Part")Dimpart1AsPartSetpart1=partDocument1.PartDimhybridShapeFactory1AsHybridShapeFactorySethybridShapeFactory1=part1.HybridShapeFactoryDimhybridShapePointCoord1AsHybridShapePointCoordSethybridShapePointCoord1=hybridShapeFactory1.AddNewPointCoord(100#,100#,100#)SubCATMain()ApplicationTherootobjectforallCATIAmacrosisApplication.ThiscorrespondstotheCATIAframewindow.TheCATIAapplicationisalwaysnamedCATIAforin-processaccess,andyoushouldonlyrefertoitsinceitalreadyexistswhenyourunanin-processmacro.Dimdocuments1AsDocumentsSetdocuments1=CATIA.DocumentsApplicationTherootobjectforDocumentsObjectACollectionofDocumentobjects.Dimdocuments1AsDocumentsSetdocuments1=CATIA.DocumentsDocumentsObjectACollectionoPartDocumentRole:WhenaPartDocumentobjectiscreated,aPartobjectisalsocreated.ThisPartobjectistherootobjectofthePartstructure.AreferenceProductobjectisalsocreatedineachPartDocument.ItisusedtoaccessPublications,PartNumber.DimpartDocument1AsPartDocumentSetpartDocument1=documents1.Add("Part")PartDocumentRole:WhenaPartPartTherootlevelobjectinsideaPartDocumentobject.

Role:Itaggregatesalltheobjectsmakingupthepartdocument.

Itprovidesmanyfactoriesandcollections.Thecollectionslistonlythedirectchildrenofthepart.Selection.Searchallowstogetallobjectsofonetype.Dimpart1AsPartSetpart1=partDocument1.PartPartTherootlevelobjectinsiHybridShapeFactoryInterfacetocreateallkindsofHybridShapeobjectsthatmaybeneededinwireframeandsurfacedesign.DimhybridShapeFactory1AsHybridShapeFactorySethybridShapeFactory1=part1.HybridShapeFactoryHybridShapeFactoryInterfacetHybridShapePointCoordPointdefinedbycoordinates.

Role:Toaccessdataofthepointfeaturecreatedwithitscartesiancoordinates.DimhybridShapePointCoord1AsHybridShapePointCoordSethybridShapePointCoord1=hybridShapeFactory1.AddNewPointCoord(100#,100#,100#)HybridShapePointCoordPointdeAxisSystemsAcollectionofalltheAxisSystemobjectscontainedinthepart.

DimaxisSystems1AsAxisSystemsSetaxisSystems1=part1.AxisSystemsAxisSystemsAcollectionofallAxisSystemTheobjectAxisSystemAaxissystemhasgotoneoriginpointandthreeorthogonalaxes,crossingattheoriginpoint.

DimaxisSystem1AsAxisSystemSetaxisSystem1=axisSystems1.Item("AbsoluteAxisSystem")AxisSystemTheobjectAxisSysReferenceRepresentsanobjectpointingtoanotherobject.ThisotherobjectcanbeeitherawireframeGeometricElementobjectsuchasaplaneoraline,oraboundaryrepresentationobjectsuchasaface,avertexoranedge.Itmaybe,inparticular,aBoundaryobject.Referencesarecreatedusingappropriatemethodsforparts.Theyarethenpassedtoanobjecttoenableassociativitywiththereferencedobject.Dimreference1AsReferenceSetreference1=part1.CreateReferenceFromObject(axisSystem1)Dimreference2AsReferenceSetreference2=part1.CreateReferenceFromObject(hybridShapePointCoord1)ReferenceRepresentsanobjectHybridBodiesAcollectionoftheHybridBodyobjects.DimhybridBodies1AsHybridBodiesSethybridBodies1=part1.HybridBodiesHybridBodiesAcollectionofthHybridBodyTheobjectisahybridbody.Thehybridbodymanagesasetofgeometricelements,asetofhybridshapes,asetofbodiesandasetofhybridbodies.

ItbelongstotheHybridBodiescollectionofaPartor@refCATIABodyorHybridBodyobject.DimhybridBody1AsHybridBodySethybridBody1=hybridBodies1.Item("GeometricalSet.1")HybridBodyTheobjectisahybHybridBody.AppendHybridShapeAppendsahybridshapetothehybridbody.Parameters:

iHybriShapeThehybridshapetoappend.Example:

ThisexampleappendsthehybridshapehybridShapetothehybridbodyhybridBody:hybridBody.AppendHybridShapehybridShapehybridBody1.AppendHybridShapehybridShapePointCoord1hybridBody1.AppendHybridShapehybridShapeLinePtDir1HybridBody.AppendHybridShapeApSampleprogramVBAinDPSampleprogramVBAinDPGehryTechnologyDigitalProjectVBA代碼編寫教程課件WorkflowinwritingcodeinDPVBAThinkabouttheprocessofgeneratingtheshapeUsemacrorecordingtogetsamplecodeSetuserinputsCleanupunnecessarycodeModifythesamplecodewithVBstatementsDebugAddDialogboxforbetterUIAddmoreadditionalfunctionsWorkflowinwritingcodeinDPGehryTechnologyDigitalProjectVBA代碼編寫教程課件For...NextStatementForcounter=startToend[Stepstep]

[statements]

[ExitFor]

[statements]NextForI=1To10ForJ=1To10ForK=1To10...NextNextNextFor...NextStatementForcountWorkflowincreatingasurfaceCreatecontrolpointsLocationofpointsDistancebetweenpointsNumberofpointsCreatecontrolcurvesDistancebetweencurvesNumberofcurvesCreatesurfaceWorkflowincreatingasurfaceGehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件DocumentGenerationDocumentGenerationGeneratingpointCommentoutGeneratingpointCommentoutAddinghybridbody(gemetricalset)Addinghybridbody(gemetricalAddingsplineAddingsplineAddingsurfaceAddingsurfaceUserinputsasvariablesUserinputsasvariablesConversionofaddingpointsNumberofpointsneededNumberofpoints*numberofcurvesUsetwoloopsOneforpointsOneforcurvesFor…Next…Wheretokeepgeneratedpoints?CreatenewgeometricalsetandkeeppointsforonecurveConversionofaddingpointsNumAddingnewhybridbodyAddingnewhybridbodySetinitialvaluesforvariablesSetinitialvaluesforvariablDebuggingDebuggingGehryTechnologyDigitalProjectVBA代碼編寫教程課件StopDebuggingStopDebuggingGehryTechnologyDigitalProjectVBA代碼編寫教程課件AddingnewhybridBodyAddingnewhybridBodyFunctionforchangingnameStrFunctionReturnsaVariant(String)representationofanumber.LenFunctionReturnsaLongcontainingthenumberofcharactersinastringorthenumberofbytesrequiredtostoreavariable.-1:becauseof\OattheendofstringinDPVBA(?)FunctionforchangingnameStrDeclaringvariablesforpointDeclaringvariablesforpointDirectionofcurves:YaxisDirectionofarrayofcurves:XaxisDirectionofcurves:YaxisDiX,YvaluesX,YvaluesZvaluewithRnd(random)valueZvaluewithRnd(random)valuCleanupcodesforotherpointsCleanupcodesforotherpointAddtwoloopsforcurvesAddtwoloopsforcurvesAdjustexistingcodeforcurvegenMovedMovedCommentoutordeleteCommentoutordeleteAdjustexistingcodeforcurveAddingcreatedpointChangethisoneintoproperpointAddingcreatedpointChangethiAccessingcreatedpointsTemporaryvariabledeclarationforpointsAccessingthroughpropertiesandmethodsReplaceintooPointtocreatereferenceAccessingcreatedpointsTemporDebuguptohereDebuguptohereDeleteothersplinerelatedcodesDeleteuptohereDeleteothersplinerelatedcoChangenameofhybridbodyandaddloopChangenameofhybridbodyandAccessingcreatedcurvesTemporaryvariabledeclarationforcurvesAccessingthroughpropertiesandmethodsReplaceintooCurvetocreatereferenceAccessingcreatedcurvesTemporDeleteunnecessarycodeDeleteunnecessarycodeAddmoretouchesHidepointsandcurvesZoomtofitallinAddDialogboxesAddmoretouchesHidepointsanHidepointsandcurvesDimselection1AsSelectionSetselection1=partDocument1.Selectionselection1.AddhybridBody1selection1.AddhybridBody2DimvisPropertySet1AsVisPropertySetSetvisPropertySet1=selection1.VisPropertiesvisPropertySet1.SetShowcatVisPropertyNoShowAttrselection1.ClearHidepointsandcurvesDimseleZoomtofitallinCATIA.ActiveWindow.ActiveViewer.ReframeIfthisdoesn’tworkCATIA.StartCommand"FitAllIn"ZoomtofitallinGehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件GehryTechnologyDigitalProjectVBA代碼編寫教程課件ModifycodeintotwoSubsAndputSGenForm.showintheCATMainModifycodeintotwoSubsModifypredefinedvaluesintoForminputvaluesModifypredefinedvaluesintoGehryTechnologyDigitalProjectVBA代碼編寫教程課件VBAinDPWithexcerptfrom‘HowtoThinkLikeaComputerScientist’byJeffreyElkner,AllenB.Downey,andChrisMeyersVBAinDPWithexcerptfrom‘HoThingstoConsiderinProgrammingVBAinDPThingstoConsiderinProgrammProgrammingforDesignersLetcomputertodomundaneworkandsavetime/resourcesGenerate(parametric)designswithlotsofvariationsNewwayofdesign,orconstruction::Lookscool,mayearnmore?ProgrammingforDesignersLetcTimetothinkinadifferentwayFormulateproblemsGoalInput/OutputDriving/DrivenThinkcreativelyaboutsolutionsMethodologyProcedureRepresentasolutionclearlyandaccuratelyDiagramDictationTimetothinkinadifferentwProgrammingLanguageNaturallanguageWhatpeoplespeakEnglish,French,Korean,…FormallanguageDesignedforspecificapplicationsMathematicalformula,ChemicalstructureProgramminglanguage,ofcourseProgrammingLanguageNaturallaVBA–VisualBasicforApplicationVBforApplicationIntegratedintohostapplicationAutomateprocessesVisualBasicHighlevelprogramminglanguagedesignedtobelearnedandusedeasilyOneoftheprogramminglanguagesforDPCATScript,VBA,.NET,…VBAisincludedinastandardDPinstallationVBA–VisualBasicforApplicaVBA–VisualBasicforApplicationInterpreterCompilerVBA–VisualBasicforApplicaProgramAsequenceofinstructionsspecifyingcomputationsInstructionsInputOutputMathConditionalexecutionRepetitionProgramAsequenceofinstructiDebuggingFixingerrorsErrorsSyntaxerrorRuntimeerrorSemanticerrorDebuggingFixingerrorsGlossaryAlgorithmAgeneralprocessforsolvingacategoryofproblemsExceptionAnothernameforaruntimeerrorScriptAprogramstoredinafile(usuallyonethatwillbeinterpreted)GlossaryAlgorithmVariables,ExpressionsandStatementsVBAinDPVariables,ExpressionsandStaValueandDataTypesValueLetter,number,…Abc,aaa,…1,2,3,…,DatatypesString,Integer,Double,…ValueandDataTypesValueVariablesAnamethatreferstoavalueVariablenamesaa=1bb=“names”Keywordand,if,for,while,sub,function,...VariablesAnamethatreferstoStatementsStatementisacompleteinstructionthatcancontainkeywords,operators,variables,constants,andexpressions.Operators:+,-,*,/,…Constant:fixed(constant)variable SetpartDocument1=CATIA.ActiveDocumentDeclarationstatementsnameavariable,constant,orprocedureandcanalsospecifyadatatypeDimpartDocument1AsPartDocumentExecutablestatementsinitiateactionsselect1.Search("name='Optimization.MinimumValue',all")StatementsStatementFunctionsVBAinDPFunctionsVBAinDPFunctionAnamedsequenceofstatementsthatperformsadesiredoperation.ThisoperationisspecifiedinafunctiondefinitionSubmySubName()MsgBox"Hello"EndSubSubmySubwithParameter(myParameter)MsgBoxmyParameterEndSubFunctionAnamedsequenceofsSub/FunctionSubNoreturnvalueFunctionWithareturnvalueSubmySubName()MsgBox"Hello"EndSubFunctionmyFunction()myFunction="Hi"EndSubSubcallFunction()MsgboxmyFunctionEndSubSub/FunctionSubSubmySubNameConditionalExecutionVBAinDPConditionalExecutionVBAinDPConditionalExecutionDoingdifferentcomputationsdependingon(boolean)conditionsIf…Then…(ElseIf…Then..)(Else…)EndifSelectCase…Case…CaseElse…EndSelectConditionalExecutionDoingdifBooleanconditionAnumericexpressionorstringexpressionthatevaluatestoTrueorFalseComparisonOperatorsUsedtocompareexpressions.<,<=,>,>=,=,<>Var1<Var2And,Or,Not,XorOperatorVar1<Var2AndVar1>Var3BooleanconditionAnumericexpIF…Then…ElseStatementIfconditionThenstatements[Elseelsestatements]'Or,youcanusetheblockformsyntax:IfconditionThen

[statements][ElseIfcondition-nThen

[elseifstatements]]...[Else

[elsestatements]]EndIfIfA>10Then A=A-10ElseIfA<10Then A=A+10Else A=0EndIfIF…Then…ElseStatementIfSelectCaseStatementSelectCasetestexpression

[Caseexpressionlist-n

[statements-n]]...

[CaseElse

[elsestatements-n]]EndSelectDimColor,MyVarSubChangeBackground(Color)MyVar=lcase(Color)SelectCaseMyVarCase"red"document.bgColor="red"Case"green"document.bgColor="green"Case"blue"document.bgColor="blue"CaseElseMsgBox"pickanothercolor"EndSelectEndSubSelectCaseStatementSelectCIterationVBAinDPIterationVBAinDPIterationArepetitionofaprocessFor…NextForEach…NextDo…LoopWhile..WendIterationArepetitionofaproFor…Nextj=0Fori=0to10 j=j+iNextMsgBox"TheJis"&jFori=0to10Step2 j=j+iNextMsgBox"TheJisnow"&jFor…Nextj=0For...NextStatementForcounter=startToend[Stepstep]

[statements]

[ExitFor]

[statements]NextForI=1To10ForJ=1To10ForK=1To10...NextNextNextFor...NextStatementForcountWhile…WendCounter=0WhileCounter<10 Counter=Counter+1WendMsgBox“Counterisnow“&CounterWhile…WendCounter=0Do...LoopStatementDo[{While|Until}condition]

[statements]

[ExitDo]

[statements]LoopDo

[statements]

[ExitDo]

[statements]Loop[{While|Until}condition]Do...LoopStatementDo

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論