Did you know?

Post your Gambas programming questions here.
User avatar
Quincunxian
Posts: 104
Joined: Sunday 25th June 2017 12:14am
Location: Western Australia

Re: Did you know? - For Writers

Post by Quincunxian » Sunday 06th December 2020 6:09am

If you wish to clean up the text imported from a document created in open office format (the only ones I've tried) then this will remove
all of the punctuation, dialogues tags and other formatting codes so that you can write analysis functions on the remaining text.
I'm 'trying' to create a Gambas application to help me in my SciFi/Fantasy story writing organisation.
{Bit of a cross between 'World Anvil & Grammerly'}
Private Function CleanTextLine(InLine As String) As String

  InLine = Replace(InLine, String.Chr(34), "")   'Unicode Character 'QUOTATION MARK' (U+0022)
  InLine = Replace(InLine, ",", "")              'Normal comma
  InLine = Replace(InLine, ".", "")              'Normal period
  InLine = Replace(InLine, "...", "")            'Unicode Character 'HORIZONTAL ELLIPSIS' (U+2026)
  InLine = Replace(InLine, "'", "")              'Normal single quote
  InLine = Replace(InLine, String.Chr(8220), "") 'Left slanted double quote
  InLine = Replace(InLine, String.Chr(8221), "") 'Right slanted double quote
  InLine = Replace(InLine, String.Chr(8217), "") 'Left single quote
  InLine = Replace(InLine, String.Chr(8218), "") 'Right single quote
  InLine = Replace(InLine, "?", "")              'Question mark
  InLine = Replace(InLine, Gb.NewLine, "")       '/n
  InLine = Replace(InLine, String.Chr(9), "")    'Tab
  InLine = Replace(InLine, String.Chr(160), "")  'Unicode Character 'NO-BREAK SPACE' (U+00A0)
  InLine = Replace(InLine, String.Chr(8211), "") 'Unicode Character 'EN DASH' (U+2013)
  InLine = Replace(InLine, String.Chr(8212), "") 'Unicode Character 'EM DASH' (U+2014)

  Return InLine

End

Importing the .odt document to html so that you can use it in a WebView control
There is a bit of useless 'swarf' imported with the code and I've found removing in bulk helps:
 Exec ["soffice", "--headless", "--convert-to", "html:HTML", {TargetFilePath}] Wait
TmpText = File.Load({TargetFilePath})
MyWebViewControl.HTML = TmpText
To remove:

style="margin-bottom: 0cm; line-height: 100%"
style="font-style: normal"
<span style="background: transparent">
</span>
Cheers - Quin.
I code therefore I am

User avatar
stevedee
Posts: 305
Joined: Monday 20th March 2017 6:06pm

Did you know? The TAB Key

Post by stevedee » Wednesday 30th December 2020 11:40am

level: Beginner
category: Editor
subject: the TAB key

=================
If you highlight a line or more of code in the Gambas Editor, and then hit the <TAB> key, you might expect to delete the text.

But no, this will indent the marked text by the number of spaces set in the Editor preferences "default tab size".

If you use <shift><TAB> the marked text will be de-indented by the number of spaces set by "default tab size".

In fact you can be very careless and just highlight a few characters in a line or block of code and <TAB> or <shift><TAB> will still indent correctly.
Last edited by stevedee on Tuesday 05th January 2021 4:33pm, edited 1 time in total.

User avatar
stevedee
Posts: 305
Joined: Monday 20th March 2017 6:06pm

Did you know? Procedure Folding

Post by stevedee » Thursday 31st December 2020 2:07pm

level: Beginner
category: Editor
subject: Procedure Folding


As your program grows, it may become more difficult to see-the-wood-for-the-trees!

Procedure Folding is a great way to temporarily hide clutter in your editor.

First of all go to menu Tools > Preferences > Editor and ensure that Procedure Folding is enabled.


In the code Editor, click on the minus (-) to the left of the procedure to fold it. All text in the procedure will now be hidden, with just the procedure declaration and a plus sign (+) visible.

Click on the plus (+) to the left of a procedure to re-display the full procedure.
Last edited by stevedee on Tuesday 05th January 2021 4:32pm, edited 1 time in total.

User avatar
cogier
Site Admin
Posts: 584
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Did you know?

Post by cogier » Sunday 03rd January 2021 5:24pm

Do you know what the Spacing Property does?

When using a HSplit or VSplit try the Spacing Property

Without Spacing: -

Image

With Spacing: -

Image

User avatar
stevedee
Posts: 305
Joined: Monday 20th March 2017 6:06pm

Did you know? Using Keyboard Shortcuts

Post by stevedee » Tuesday 05th January 2021 4:30pm

level: Beginner
category: Editor
subject: using keyboard shortcuts


At the "hobby" level, its very much a personal choice whether you use the editor menu for simple copy/paste type operations or use keyboard shortcuts.

However, the more you code, the more the benefits of using keyboard shortcuts become apparent.

There are only five key combinations that you need to remember and these are pretty much universal for most text editors, word processors and development environments:-


cut <ctrl>x

copy <ctrl>c

paste <ctrl>v

undo <ctrl>z

redo <ctrl>y

User avatar
stevedee
Posts: 305
Joined: Monday 20th March 2017 6:06pm

Did you know? Settings.Read() & Settings.Write()

Post by stevedee » Sunday 10th January 2021 11:28am

level: Intermediate
category: Language
subject: gb.Settings



Although the Gambas wiki shows an example of how to save a window size and position, there is as easier method.

The wiki example saves settings like this:-
  Settings["Window/Top"] = Me.Top
  Settings["Window/Left"] = Me.Left
  Settings["Window/Height"] = Me.Height
  Settings["Window/Width"] = Me.Width

...and retrieves and sets the form/window like this:-
  Me.Top = Settings["Window/Top", Me.Top]
  Me.Left = Settings["Window/Left", Me.Left]
  Me.Height = Settings["Window/Height", Me.Height]
  Me.Width = Settings["Window/Width", Me.Width]
But it is much simpler to use the .Read() & .Write() methods:-
  Settings.Read(Me, "theWindow")
...and:-
    Settings.Write(Me, "theWindow")

Also note that when using:-
  Me.Top = Settings["Window/Top", Me.Top]
...you must supply a default in case the data cannot be found from the .conf file.

However, you do not need to provide a default value when using the .Read() method.

The Settings.Read() and .Write() methods are also very useful when working with any controls that have a .Setting property, including; FileChooser, FileView, SidePanel, ColumnView, h & vSplit

Example:-
  Settings.Read(FileChooser1, "Files")
    Settings.Write(FileChooser1, "Files")

Post Reply