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
Did you know?
- cogier
- Site Admin
- Posts: 1129
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Did you know?
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.
Re: Did you know?
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.
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
- cogier
- Site Admin
- Posts: 1129
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Did you know?
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.
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.
Re: Did you know?
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?
- cogier
- Site Admin
- Posts: 1129
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Did you know?
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 . 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'.
''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
- BruceSteers
- Posts: 1608
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Did you know?
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..
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)
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)
If at first you don't succeed , try doing something differently.
BruceS
BruceS
Re: Did you know?
great, i didn't know ... until now
Regards
Re: Did you know?
This if i knew it.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!
Re: Did you know?
or this
If sTemp1 Like sTemp2 Then Print "Yes" Else Print "No"
Re: Did you know?
I didn't know either, I'm liking this section more and more !!