Did you know?

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

Re: Did you know?

Post by cogier » Sunday 08th November 2020 5:13pm

If you would like some text in the background of a TextBox so the user knows what is expected of him/her then use the 'Placeholder' Property.
Public Sub Form_Open()

  Dim TextBox1 As TextBox

  With Me
    .h = 45
    .W = 220
    .Padding = 5
    .Arrangement = Arrange.Vertical
  End With

  With Textbox1 = New TextBox(Me)
    .H = 28
    .Placeholder = "Enter your text here"
  End With

End

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

Re: Did you know?

Post by stevedee » Monday 09th November 2020 7:09pm

The "Boxed Strings" feature that crept into Gambas at v3.12 is a curious one, as its only mentioned in the help documentation if you happen to look at Len or Mid

Its quite useful if you are working with a fixed format data file, where the number of characters in each field is constant.

In this example I've just taken one line (record) from my internet speed CSV file and put it in a text box, then extracted the 'time' field as shown.
Public Sub Button1_Click()

  TextBox2.Text = TextBox1.Text[11, 8]

End
BoxedString.png
BoxedString.png (12.77 KiB) Viewed 190 times

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

Re: Did you know?

Post by cogier » Tuesday 10th November 2020 11:05am

Hi Steve.

Yes I have used this as well but you have to remember that the first character in a string is 1 when using Len & Mid whereas using this method it is 0.

And just to be controversial ;) I would have used 'TextBox2.Text = Split(TextBox1.Text)[1]' in your example and that way the length of the string is immaterial.

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

Re: Did you know?

Post by stevedee » Tuesday 10th November 2020 12:04pm

cogier wrote:
Tuesday 10th November 2020 11:05am
...And just to be controversial ;) ...
Yes you are right Charlie, there is more than one way to skin a cat!

...and my example was not very good, as for a CSV file I would have used the CsvFile Class: https://forum.gambas.one/viewtopic.php?f=4&t=819

Can you think of a good use for Boxed Strings?

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

Re: Did you know?

Post by cogier » Tuesday 10th November 2020 4:59pm

stevedee wrote:
Tuesday 10th November 2020 12:04pm
Can you think of a good use for Boxed Strings?

You mustn't ask me these questions :o. My mind went off and came up with the code below.
The use of Boxed String is on Line 13 and here it is very useful. It could be done with a 'Mid' statement but this is more elegant.
The code should work without the attached font but to get the best install the font first. (Use your phone to scan the barcode below, it works!)
Just run the code in a Gambas 'Graphical application'.

Image

''Requires Font 'code128' to be installed to work as intended

TextBoxIN As TextBox                                                                      'To create a TextBox
LabelBC As Label                                                                          'To create a Label

Public Sub TextBoxIN_change()                                                             'If the TextBox text changes then..

  Dim sCheckSumList As New String[]                                                       'Creates an array for the Checksum character
  Dim sBarcode As String = "Ì" & TextBoxIN.Text & "[CHECKSUM]" & "Î"                      'The easy bit, create a strind with the Start code, the text an area for the CheckSum and the End code
  Dim iLoop, iCheckSum As Integer                                                         'iLoop for loops and iChecksum to work out the CheckSum

  For iLoop = 0 To Len(TextBoxIN.Text) - 1                                                'Loop through the entered text
    iCheckSum += (Asc(TextBoxIN.Text[iLoop]) - 32) * (iLoop + 1)                          'Get the Ascii value of the character less 32 and multiply by its position in the string
  Next

  iCheckSum = (iCheckSum + 104) Mod 103                                                   'Add 104 to the checksum and MOD it by 103 (It's not my fault, see https://www.precisionid.com/code-128-faq/)

  For iLoop = 32 To 126                                                                   'Create the start of the Checksum charater list
    sCheckSumList.Add(Chr(iLoop))
  Next

  sCheckSumList.Insert(["Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î"])      'Add the extended Ascii charaters to the Checksum list

  LabelBC.Text = Replace(sBarcode, "[CHECKSUM]", sCheckSumList[iCheckSum])                'Get the single charater from the Checksum list and add it as the Checksum

End

Public Sub Form_Open()                                                                    'This adds and formats the FMain form

  With Me                                                                                 'FMain properties
    .H = 150                                                                              'Set the Height
    .W = 750                                                                              'Set the Width
    .Arrangement = Arrange.Vertical                                                       'Set the Arrangement
    .Padding = 5                                                                          'Add a little Padding
    .Text = "Barcoder"                                                                    'Add a title
  End With

  With TextBoxIN = New TextBox(Me) As "TextBoxIN"                                         'Add a TextBox
    .H = 28                                                                               'Set the Height
    .Placeholder = "Enter some text here"                                                 'Set the Placeholder
  End With

  With LabelBC = New Label(Me) As "LabelBC"                                               'Add a Label
    .H = 200                                                                              'Set the Height
    .Background = Color.White                                                             'Set the Background
    .Alignment = Align.Center                                                             'Align the text
    .Alignment = Align.Top                                                                'Align the text
    .Font = Font["code128,70"]                                                            'Set up the Font
  End With

End
code128.ttf.tar.gz
(2.16 KiB) Downloaded 8 times

User avatar
BruceSteers
Posts: 214
Joined: Thursday 23rd July 2020 5:20pm

Re: Did you know?

Post by BruceSteers » Saturday 14th November 2020 8:01pm

Not sure if this is covered but i've just discovered shell style escape colour codes in strings work with Print.

Ie
Print "This is normal \e[31mBut This Is Red \e[0m"
Prints..
This is normal But This Is Red
works in a terminal and in the IDE console.
I'm gonna have fun with that :)

I made this simple alias and put it in my /etc/bash.bashrc file..
#
alias ColList='CN=0; for C in {1..11}; do for C2 in {1..10}; do echo -ne "\e["$CN"m $CN #@\e[0m\t";((CN++)); done;echo ""; done'
#
proper useful that for fancy messages , or warning messages n stuff

CN=0; for C in {1..11}; do for C2 in {1..10}; do echo -ne "\e["$CN"m $CN #@\e[0m\t";((CN++)); done;echo ""; done

It does the following....
(Ps. some texts are flashing but you can't see that)
snap.png
snap.png (77.84 KiB) Viewed 132 times
If at first you don't succeed , try it differently.

User avatar
tincho
Posts: 18
Joined: Wednesday 10th July 2019 1:12pm

Re: Did you know?

Post by tincho » Tuesday 17th November 2020 11:02pm

cogier wrote:
Saturday 04th February 2017 3:13pm
I have discovered another short cut I didn't know about.
If you hold down the [Ctrl] key and click on a Gambas reserved word (e.g. Public, New, For, etc) the relevant help page is displayed.
But you all knew that didn't you?
great, i didn't know ... until now
Regards

User avatar
tincho
Posts: 18
Joined: Wednesday 10th July 2019 1:12pm

Re: Did you know?

Post by tincho » Tuesday 17th November 2020 11:08pm

cogier wrote:
Thursday 16th March 2017 3:28pm
I have found another little gem I thought I would pass on (even though you know it already!)
Open preferences [Ctrl]+[Alt]+P and switch on Local variable automatic declaration then in your empty 'Sub' type iCount = 6 and hey presto a Dim iCount as Integer automatically appears!
This if i knew it. :D

User avatar
tincho
Posts: 18
Joined: Wednesday 10th July 2019 1:12pm

Re: Did you know?

Post by tincho » Tuesday 17th November 2020 11:12pm

cogier wrote:
Wednesday 29th March 2017 3:19pm
You can shorten the line: -
If String.Comp(sTemp1, sTemp2, gb.IgnoreCase) = 0 Then Print "yes" Else Print "No"
To: -
If Comp(sTemp1, sTemp2, 1) Then Print "No" Else Print "yes"
Unless you particularly wanted to compare two UTF-8 strings
or this
If sTemp1 Like sTemp2 Then Print "Yes" Else Print "No"

User avatar
tincho
Posts: 18
Joined: Wednesday 10th July 2019 1:12pm

Re: Did you know?

Post by tincho » Tuesday 17th November 2020 11:22pm

cogier wrote:
Tuesday 26th June 2018 3:02pm
Did you know you can easily move a line, or multiple lines, of code up or down in the editor. Just place the cursor on the line, or highlight the lines, you want to move and press [Alt]+[Up Arrow] (or [Down Arrow]). 8-)
I didn't know either, I'm liking this section more and more !!

Post Reply