that all… let’s make a snipet day.
i know there is a lot of snippet here in the forum. but maybe it would be a good idea to upload all the snippets to codepad. i think it would be great to have it organized
Description
Here’s one that will let you convert a new Date object to Text, using a string to format the output… This is an extends method, so place it in a module…
Limitations
macOS only
Only uses current locale
Sample
DIM now As Xojo.Core.Date = Xojo.Core.Date.Now
MsgBox now.ToText("yyyy.MM.dd G 'at' HH:mm:ss zzz")
Outputs
2017.06.28 AD at 10:19:02 EDT
Code
[code]Public Function ToText(Extends d As Xojo.Core.Date, dateFormat As Text) as Text
DIM results As Text
#if TargetCocoa
// http://unicode.org/reports/tr35/tr35-4.html#Date_Format_Patterns
Declare Function Alloc Lib "Cocoa" Selector "alloc" (inClass As Ptr) As Ptr
Declare Function Init Lib "Cocoa" Selector "init" (inClass As Ptr) As Ptr
Declare Function NSClassFromString Lib "Cocoa" (className As CFStringRef) As Ptr
Declare Function DateWithTimeIntervalSince1970 Lib "Cocoa" Selector "dateWithTimeIntervalSince1970:" (classRef As Ptr, seconds As Double) As Ptr
Declare Function StringFromDate Lib "Cocoa" Selector "stringFromDate:" (inNSDateFormatter As Ptr, inNSDate As Ptr) As CFStringRef
Declare Sub SetDateFormat Lib "Cocoa" Selector "setDateFormat:" (inNSDateFormatter As Ptr, formatString As CFStringRef)
DIM NSDateClass As Ptr = NSClassFromString("NSDate")
DIM aNSDate As Ptr = DateWithTimeIntervalSince1970(NSDateClass, d.SecondsFrom1970)
DIM NSDateFormatterClass As Ptr = Init(Alloc(NSClassFromString("NSDateFormatter")))
SetDateFormat NSDateFormatterClass, dateFormat
results = StringFromDate(NSDateFormatterClass, aNSDate)
#endif
Return results
End Function
[/code]
here is my snippet to convert a number to string (only spanish)–> https://codepad.co/snippet/e8FgJYGk
here is a way to remove 960 lines from your “snippet”
Dim my_array() As String
my_array.Append("cero")
my_array.Append("uno")
my_array.Append("dos")
my_array.Append("tres")
my_array.Append("cuatro")
my_array.Append("cinco")
my_array.Append("seis")
my_array.Append("siete")
my_array.Append("ocho")
my_array.Append("nueve")
my_array.Append("diez")
my_array.Append("once")
my_array.Append("doce")
my_array.Append("trece")
my_array.Append("catorce")
my_array.Append("quince")
my_array.Append("dieciseis")
my_array.Append("diecisiete")
my_array.Append("dieciocho")
my_array.Append("diecinueve")
//
my_array.Append("veinte") //20
for i=1 to 9
my_array.Append("veinti")+my_array(i)
next i
for j=30 to 90 step 10
select case j
case 30
n="treinta"
case 40
s="cuarenta"
case 50
n="cincuenta"
case 60
n="sesenta"
case 70
n="setenta"
case 80
n="ochenta"
case 90
n="noventa"
end select
my_array.Append(n)
for i=1 to 9
my_array.Append(n+" y "+my_array(i))
next i
next j
//
my_array.Append("cien") // 100
for i=1 to 99
my_array.Append("ciento "+my_array(i))
next i
//
for j=2 to 9 // 200 to 900
n=my_array(i)+"cientos")
my_array.append n
for i=1 to 99
my_array.Append(n+" "+my_array(i))
next i
next j
thanks @Dave S !