Search found 1576 matches
- Tuesday 13th July 2021 8:43pm
- Forum: General
- Topic: How to generate an ordinal number
- Replies: 19
- Views: 9547
Re: How to generate an ordinal number
I have a habit of ditching as many single use variables as I can. It's amazing the way you can use the dot . To pass all sorts of things in one line of text. If you need to re-use the variable a lot then it makes sense to create one. The big speed increase in cogiers ordinal method was in the use of...
- Saturday 10th July 2021 9:23pm
- Forum: General
- Topic: How to generate an ordinal number
- Replies: 19
- Views: 9547
Re: How to generate an ordinal number
I got home from work and was able to test and the ad-hoc string array does work :) So my final input on this is this tested and working one liner that works on any number value.. Public Sub OrdinalString(Value As Integer) As String Return Str(Value) & ["th", "st", "nd&qu...
- Saturday 10th July 2021 6:34pm
- Forum: General
- Topic: How to generate an ordinal number
- Replies: 19
- Views: 9547
Re: How to generate an ordinal number
No idea, I've always used iif.
it exists in a few languages.
I'm rubbish with gambas
In the wiki iif is written before if so what's the chicken and what's the egg? , it's the same command whatever
http://gambaswiki.org/wiki/lang/iif
it exists in a few languages.
I'm rubbish with gambas
In the wiki iif is written before if so what's the chicken and what's the egg? , it's the same command whatever
http://gambaswiki.org/wiki/lang/iif
- Saturday 10th July 2021 3:51pm
- Forum: General
- Topic: How to generate an ordinal number
- Replies: 19
- Views: 9547
Re: How to generate an ordinal number
Oops I've messed up with one problem ...
The 11st
Dang and it was so perfect ,
easily fixed with an iif()
So a 2 liner..
Dim ss As String = ["th","st","nd","rd","th"]
Return(Iif(v % 100 = 11, "th", ss[Min(4, v % 10)]))
The 11st
Dang and it was so perfect ,
easily fixed with an iif()
So a 2 liner..
Dim ss As String = ["th","st","nd","rd","th"]
Return(Iif(v % 100 = 11, "th", ss[Min(4, v % 10)]))
- Saturday 10th July 2021 2:16pm
- Forum: General
- Topic: How to generate an ordinal number
- Replies: 19
- Views: 9547
Re: How to generate an ordinal number
I like shorter, as short as can be is best for me... I got it to a one liner 🙂 Public Sub GetOrdinal(v as Integer) As String Return(["th","st","nd","rd","th"][Min(4, v % 10)]) End Not sure if defining a string[] ad-hoc like that works though (cant te...
- Saturday 10th July 2021 11:24am
- Forum: General
- Topic: How to generate an ordinal number
- Replies: 19
- Views: 9547
Re: How to generate an ordinal number
Not so dirty...
Dim ss as string[] = ["th","st","nd","rd","th"]
Dim v as Integer = value % 10
Return Str(value) & ss[Min(v,4)]
Dim ss as string[] = ["th","st","nd","rd","th"]
Dim v as Integer = value % 10
Return Str(value) & ss[Min(v,4)]
- Saturday 10th July 2021 11:18am
- Forum: General
- Topic: How to generate an ordinal number
- Replies: 19
- Views: 9547
Re: How to generate an ordinal number
No, 5 is Integer, 5th is String. It's a simple function... Public nth(v as integer, Textonly as Boolean) Dim s as string =iif(textonly,"",str(v)) Dim n as Integer = v Ùª 10 Select n Case 1 S &= "st" Case 2 S &= "nd" Case 3 S &= "rd" Case else S &...
- Friday 9th July 2021 2:18pm
- Forum: General
- Topic: [SOLVED] Gambas Style Guide
- Replies: 3
- Views: 2359
Re: Gambas Style Guide
I'd agree, when it comes to style just go with what makes you comfortable. I started helping with gambas development so that involved learning Benoits style. So my style has adapted somewhat. Using iVar for Integer sVar for String etc makes sense and makes for more understandable code (6 months late...
- Thursday 8th July 2021 5:00pm
- Forum: Component
- Topic: Any simple DBus examples?
- Replies: 8
- Views: 5743
Re: Any simple DBus examples?
A solution to what? I thought it was about preventing the application from starting multiple times ... sorry if I missed something aah i see , no i've already been there.. https://forum.gambas.one/viewtopic.php?f=13&t=943 using pgrep is better than PID files but Dbus is even better as it handle...
- Thursday 8th July 2021 11:55am
- Forum: Component
- Topic: Any simple DBus examples?
- Replies: 8
- Views: 5743