MicroStation VBA basics, microstationvba

Source: Internet
Author: User
Tags month name rtrim

MicroStation VBA basics, microstationvba

Intern Note 1

August 1, 2016

Option Explicit

By default, if a variable without declaration is used, it inherits the "Variant" type. In the General Declaration area of modules, forms, and classes, using "OptionExplicit" forces us to declare variables before using them.

Sample:

Option ExplicitSub test()X = 5End Sub

 

"Option Explicit" is declared in the General Declaration area ". An error is returned when you try to run the test macro.

This chapter review

1. Write code in a process, function, or user form event

2. Use required and optional parameters in procedures and functions

3. function return values, arrays, types, and objects

4. In the process and function, if the parameter is declared as "ByRef", you can change the variable passed as the parameter. Declaring the parameter as "ByVal" will keep the variable unchanged

4. variables can be declared in processes, functions, and events, or in the Universal Declaration area. The scope of these variables depends on where they are declared and the keywords used in the Declaration.

Chapter 6 variables

Option ExplicitSub tst () TTT = 5 MsgBox TTTEnd Sub 'integer Dim PageNumber As IntegerPageNumber = 84 'long integer Dim MySalary As LongMySalary = 123456' dual-precision Dim variant As partition = 36.25Sub VariableTestC () dim N As DoubleN = partition Sub 'boolean Dim ICanLearnThis As partition = true' date Dim XMReleaseDate As partition = "5/19/2006 8:00:00 AM" 'dim MYLevelName As StringMYLevelName = "utilatomicity "'object type Dim MyExcelApp As ObjectSet MyExcelApp = GetObject (, "Excel. application ") 'variantdim PointArray As variant' MicroStation-specific variable type 'application) dim MSAPP As ApplicationSet MSAPP = Application 'activedesignfile current design file 'activemodelreference current Model Reference 'activesetaskcurrent settings 'vbproject object & attributes object and attribute 'username username' get left, top, width, and height attribute 'designfile design file Dim MyDGN As DesignFileSet MyDGN = Application. activeDesignFile 'author Author, Client customer, Comments comment, Company, KeyWords, Manager, Subject topic, Title 'formatmajorversion main version FormatMinorVersion format secondary version 'levels layer, models model, Name, Path 'modelreference Model Reference Dim MyModel As ModelReferenceSet MyModel = Application. activeModelReference 'level layer Dim MyLevel As LevelSet MyLevel = Application. activeDesignFile. levels (1) 'description, ElementColor, ElementLineStyle, linear element, ElementLineWeight, IsActive, IsDisplayed, IsFrozen, locked, Name, number layer Number, Plot grating Plot 'lineelement line element Dim MyLine As ApplicationSet MyLine = Application. createLineElement2 (Nothing, Point3dFromXYZ (0, 0, 0), Point3dFromXYZ (4, 5, 6) Application. activeModelReference. addElement MyLine 'ellipseelement elliptical element Dim MyCircle As EllipseElementDim RotMatrix As Matrix3dSet MyCircle = CreateEllipseElement2 (Nothing, Point3dFromXYZ (0, 0, 0), 1.5, 1.5, RotMatrix Application. activeModelReference. addElement MyCircle 'arcelement arc element Dim MyArc As ready RotMatrix As Matrix3dSet MyArc = CreateArcElement2 (Nothing, Point3dFromXYZ (0, 0, 0), 1.75, 1.75, RotMatrix, Radians (45 ), radiands (90) Application. activeModelReference. addElement MyArc 'textelement text element Dim MyText As TextElementDim RotMatrix As Matrix3dSet MyText = CreateTextElement1 (Nothing, "MicroStation VBA", Point3dFromXYZ (0, 0, 0), RotMatrix) Application. activeModelReference. addElement mytext' value assignment and setting object Dim LevelName As StringLevelName = "Element" Dim EasementLevel As LevelSet EasementLevel = ActiveDesignFile. addNewLevel (LevelName) Dim StartPoint (0 To 2) As DoubleStartPoint (0) = 4.5 StartPoint (1) = 5.6 StartPoint (2) = 6.7Sub ArrayTestA () Dim MyVerticies (0 To 1) as Point3dDim MyLine As LineElementMyVerticies (0 ). X = 1 MyVerticies (0 ). Y = 2 MyVerticies (1 ). X = 3 MyVerticies (1 ). Y = 4 MyVerticies (2 ). X = 5 MyVerticies (2 ). Y = 6 Set MyLine = CreateLineElement1 (Nothing, MyVerticies) ActiveModelReference. addElement MyLineEnd SubSub VariableTestD () Dim MySalary As DoubleDim MySalary As region = 1234567 MyHourly = MySalary/52/40 MsgBox "My Hourly Rate is" & FormatCurrency (cost, 2, cost, cost, vbTrue) end Sub

 

This chapter review:

A variable is a name that saves a value or points to an object. Variables declared in a function, process, or event are local and can only be used in the function that declares it. They cannot be used outside the function. Variables declared in the form or code module common declaration area can be used anywhere in the form or code module that declares them. Variables declared as "Public" in the Code module can be used anywhere in the VBA project. variables declared as "public" in the class module become the read/write attributes of the class module.

Without variables, everything will be static and nothing will mean-the line is always painted from a fixed point to a fixed point, the text is always inserted at the same point and the content is always the same.

Chapter 7 Operation text

UCase capital Conversion Function Ucase (String) LCase lowercase Conversion Function Lcase (String) StrConv String Conversion Function StrConv (String, Conversion As VbStrConv, [LocaleID AS Long]) weekDayName week name WeekDay date to week Function WeekDayName (Weekday As Long, [Abbreviate As Boolean = False], [FirstDayOffWeek As VbDayOfWeek = vbUseSystemDayOfWeek]) as StringMonthNAme Month name Function MonthName (Month As Long, [Abbreviate As Boolean = False]) As StringLTrim left screenshot RTrim right screenshot Function LTrim (String) Function RTrim (String) function Trim (String) StrComp String comparison Function StrComp (String1, String2, [Compare As VbCompareMethod = vbBinaryCompare] Left String Function Left (String, Length As Long) right: String Function Right (String, Length As Long) Mid: String Function Mid (String, Start As Long, [Length]) Sub TextWork12 () dim BookTitle As StringBookTitle = "Learning MicroStation VBA" Debug. print Mid (BookTitle, 3, 6) Debug. print Mid (BookTitle, 6) Debug. print Mid (BookTitle, InStr (1, BookTitle, "") + 1) End Sub

 

'Note that there is a space in "" in the above InStr.

Running result:

Arning

Ing MicroStation VBA

MicroStation VBA

The first character starts with the third character and returns six characters.

The second character starts with the sixth character and returns each character after it.

The third is to use the Instr function to find the position of the first space in the variable BookTitle and add "1" as the starting point. This is actually from the end of the first space. If no length is specified, all content after space is obtained.

Replace Function Replace (Expression As String, Find As String, Replace As String, [Start As Long = 1], [Count As Long =-1], [Compare As VbCompareMethod = vbBinaryCompare]) AS StringSub TextWork13 () Dim FilePath As StringDim FilePath2 As StringFilePath = Application. activeDesignFile. fullNameFilePath2 = Replace (FilePath, "\", "//") MsgBox FilePath & "turns into" & vbCr & FilePath2End SubInStr substring position Function InStr ([Start], [String1], [String2], [Compare As VbCompareMethod = vbBinaryCompare]) reverse rev sub-String position Function Limit Rev (StringCheck As String, StringMatch As String, [Start As Long =-1], [Compare As VbCompareMethod = vbBinaryCompare]) As LongSplit and Join Function Split (Expression As String, [Delimiter], [Limit As Long =-1], [Compare As VbCompareMethod = vbBinaryCompare]) Function Join (SourceArray, [Delimiter]) as StringAsc character to ASCII code and Chr ASCII code to Function Asc (Stirng As String) As IntegerFunction Chr (CharCode As Long) FormatCurrency format currency Function FormatCurrency (Expression, [NumDigitaAfterDecimal As Long =-1], [IncludeLeadingDigit As VbTriState = vbUseDefault], [GroupDigits As VbTriState = vbUseDefault]) As StringFormatNumber FormatNumber (Expression, [NumDigitsAfterDecimal As Long =-1], [IncludeLeadingDigit As VbTriState = vbUseDefault], [same As VbTriState = vbUseDefault], [GroupDigits As VbTriState = vbUseDefault]) as StringFormatDateTime Format date Funcion FormatDateTime (Expression, [NamedFormat As VbDateTimeFormat = vbGeneralDate]) As StringFormat Format Function Format (Expression, [Format], [FirstDayOfWeek As VbDayOfWeek = vbSunday], [FirstWeekOfYear As VbFirstWeekOfYear = vbSunday], [FirstWeekOfYear As VbFirstWeekOfYear = vbFirstJan1])

 

& Connector

Used to connect strings

VbCr carriage return <Enter> key

VbTab <Tab> key

This chapter review:

A string is a single text block composed of texts, letters, numbers, and other characters. This chapter describes how to operate these strings, such as uppercase and lowercase conversions. Concatenate, format, and split strings.

<F8> one step is supported.

Chapter 4 operation numbers

Addition, subtraction, multiplication, division, square and index (^ 2 or ^ n), square root Sqr

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.