- Creating Behavior Without Programming
- Using the Code Editor to Write REALbasic Code
- Getting Help with the REALbasic Language
- Mastering Dim and Assignment Statements
- Making Tests and Comparisons
- Writing Code that Branches
- Writing Code that Repeats
- Writing Your Own Methods
- Extending the HTML Editor
- Creating the Indent Menu Item
- Removing Existing Indentation
- Inserting Indentation Before Tags
- Handling the Indent Level
- Extending the Project
Creating the Indent Menu Item
Before you create the Indent method, you need to think about the user interface. How will the user invoke your Indent method? The most obvious way is via an Indent menu item (Figure 4.39).
To create the Indent menu item:
In the Project window, double-click the Menu icon to open the Menu Editor.
Click the Edit menu.
Click the blank menu item.
In the Properties window, enter Indent for the Text property, and accept (or enter) EditIndent as the Name property.
Close the Menu Editor.
With the Code Editor open, choose Edit > New Menu Handler.
In the dialog that appears, choose EditIndent from the pop-up menu, and click OK.
In the browser pane of the Code Editor, click the disclosure triangle next to Menu Handlers.
Click EditIndent to open the EditIndent menu handler in the editor pane.
Enter this code in the EditIndent menu handler in the editor pane:
dim Lt as string Lt = "<" HtmlField.text = Indent(HtmlField. → text,Lt)
You've coded the Indent menu item. When the user selects it, this code will define a variable Lt, assign to it the single character <, and replace the text in HtmlField with the result returned by the Indent method. Now you can create the Indent method.
To create the Indent method:
With the Code Editor open, choose Edit > New Method.
In the New Method dialog, enter Indent for the method's name.
In the Parameters field, enter T as String, C as String.
In the Return Type field, enter String.
Click OK
You've created a method named Indent that takes two string parameters and returns a string value. From the way you call this method in the menu handler you created earlier, you can see what these parameters and return value are all about: You call Indent like this:
HtmlField.text = Indent(HtmlField.text,Lt)
So the first parameter will be the HTML text; the second parameter will be the < character; and the value returned will be the HTML text, properly indented. Knowing this, you can write the code for the Indent method.