Did you know?

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

Re: Did you know? - For Writers

Post by Quincunxian »

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: 518
Joined: Monday 20th March 2017 6:06pm

Did you know? The TAB Key

Post by stevedee »

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 5th January 2021 4:33pm, edited 1 time in total.
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Did you know? Procedure Folding

Post by stevedee »

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, hold down <shift> key then 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.

Hold down <shift> key then click on the plus (+) to the left of a procedure to re-display the full procedure.
Last edited by stevedee on Friday 10th December 2021 4:38pm, edited 2 times in total.
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Did you know?

Post by cogier »

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: 518
Joined: Monday 20th March 2017 6:06pm

Did you know? Using Keyboard Shortcuts

Post by stevedee »

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: 518
Joined: Monday 20th March 2017 6:06pm

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

Post by stevedee »

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")
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Did you know?

Post by BruceSteers »

level: Beginner
category: Editor
subject: Setting Help text



Did you know you can provide text to the help system about your module/class functions and variables using 2 single quotes?

'' <- that's 2 single quotes '

You can add a comment before the function/variable definition using 2 single quotes and use markdown syntax too then the popup object list from another file will show the info in the help.

so if you consider this...

' Gambas module file

'' The file to save the log to.
Public LogFile As String

Public ProcRC As Integer


'' Start the **compilation process** from the beginning<br>Or from a point via the **right click menu** options.

Public Sub Begin(Optional SingleCommand As Integer = -1, Optional bRunFrom As Boolean)
  Dim sTime As Date = Now
  File.Save(LogFile, "Gambas Compiler Utility log.\nStarted " & Now & "\n\n")
  ProcRC = 0
  DoStuff()
End

' rest of code.....
Will produce this...
Snap1.png
And this...
Snap2.png
If at first you don't succeed , try doing something differently.
BruceS
User avatar
PJBlack
Posts: 184
Joined: Tuesday 9th June 2020 10:26pm
Location: Florstadt, Hessen, Germany

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

Post by PJBlack »

stevedee wrote: Sunday 10th January 2021 11:28am But it is much simpler to use the .Read() & .Write() methods:-
  Settings.Read(Me, "theWindow")
...and:-
    Settings.Write(Me, "theWindow")
there is one more advantage of that ... in the settings file the screen number is stored as last parameter
[FMain]
theWindow=[0,0,952,1052,0]
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Did you know? ...always use a default with Select Case

Post by stevedee »

level: Beginner
category: Language
subject: Select Case



Select Case is my favourite way to code a choice between a number of options. Its so much neater than a string of If...Then...Else If...Then...Else If...

Although you can use Select Case with just the cases you think your code will encounter, like this:-
Private Sub Colour()
  
  Select Case LCase(TextBox1.Text)
    Case "black"
      Me.Background = Color.Black
       
    Case "white"
      Me.Background = Color.White
      
  End Select
End

Public Sub Button1_Click()

  Colour()

End
...its good coding practice to ensure that you will never accidentally drop through this code without making a selection, for example by using Case Else:-
Private Sub Colour()
  
  Select Case LCase(TextBox1.Text)
    Case "black"
      Me.Background = Color.Black
       
    Case "white"
      Me.Background = Color.White
      
    Case Else
      Me.Background = Color.Gray
      
  End Select
End

Public Sub Button1_Click()

  Colour()

End
I seem to struggle to remember if its Case Else or Else Case, so I recommend you simply use the key word Default:-
Private Sub Colour()
  
  Select Case LCase(TextBox1.Text)
    Case "black"
      Me.Background = Color.Black
       
    Case "white"
      Me.Background = Color.White
      
    Default
      Me.Background = Color.Gray
      
  End Select
End

Public Sub Button1_Click()

  Colour()

End
progger
Posts: 4
Joined: Monday 15th February 2021 8:16am

Re: Did you know?

Post by progger »

If you create a comment that starts with "TODO:" then that comment shows up in you Notes list. This is a nice way to keep track of your ToDo-list :)
Gamabs ToDo-list.png
Gamabs ToDo-list.png (74.93 KiB) Viewed 33508 times
Post Reply