## Search found 1033 matches

Nov 11, 2017 9:33
Forum: Tips and Tricks
Topic: LeapYear Function (Boolean eval.)
Replies: 126
Views: 4454

### Re: LeapYear Function (Boolean eval.)

I don't know why I did this because I agree with St_W The idea is to 'pull out' at the earliest opportunity. On my machine I am coming in at just over one second. Function drLeapYear ( Year As Ulong ) As Boolean If Year Mod 4 = 0 Andalso _ Year Mod 100 > 0 Orelse _ Year Mod 400 = 0 Then Return true...
Nov 11, 2017 4:00
Forum: Tips and Tricks
Topic: LeapYear Function (Boolean eval.)
Replies: 126
Views: 4454

### Re: LeapYear Function (Boolean eval.)

I have added the result test: Start = Timer lyears=0 for i = 1 to years if LeapYearA(i) then lyears=lyears+1 next print "elapsed A:"; Timer - Start;", ";lyears;" leap years found" elapsed C: 23.28389780238103, 194000000 leap years found elapsed B: 22.93290822826214, 194...
Nov 11, 2017 2:43
Forum: Tips and Tricks
Topic: Data-Type, conversion Array's and Overloaded Function's (in a nutshell)
Replies: 39
Views: 1626

### Re: Data-Type, conversion Array's and Overloaded Function's (in a nutshell)

Munair wrote:I will post the test with results shortly.
Proposal for a testbed:

Code: Select all

`  dim as double t=timer  dim as long lym  lym=0  for n as long=1 to 400000000   if IsLeapYearM(n) then lym=lym+1  next  print timer-t;" seconds for finding ";lym;" leap years"`
Nov 11, 2017 1:57
Forum: Tips and Tricks
Topic: Data-Type, conversion Array's and Overloaded Function's (in a nutshell)
Replies: 39
Views: 1626

### Re: Data-Type, conversion Array's and Overloaded Function's (in a nutshell)

A macro would do for leap year. But it's a long wait to be really sure. (I've modified your macro somewhat) ... : #Define IsLeapYear(N) CBool( (N Mod 4 = 0 Andalso N Mod 100 <> 0) OrElse (N Mod 400 = 0) ) That could be interesting for some timing tests. Here is the disassembly (M like 'Macro')): #D...
Nov 06, 2017 14:51
Forum: Tips and Tricks
Topic: Data-Type, conversion Array's and Overloaded Function's (in a nutshell)
Replies: 39
Views: 1626

### Re: Data-Type, conversion Array's and Overloaded Function's (in a nutshell)

dodicat wrote:I have experimented in the past adding a bom with chr(X,X,X) (forget which X's) to a saved text file with differing results, usually the wrong ones.

UTF-8 works fine with BOM, and prints non-English text, too. The problem is limited to string(ct, "x").
Nov 06, 2017 14:48
Forum: Tips and Tricks
Topic: Data-Type, conversion Array's and Overloaded Function's (in a nutshell)
Replies: 39
Views: 1626

### Re: Data-Type, conversion Array's and Overloaded Function's (in a nutshell)

For Windows, GetDateFormat is available: I don't want to rely on a platform specific API, if it can be done: multi platform, aka: pure FB. Valid argument, of course. Maybe Linux has a GetDateFormat equivalent? Is there something like #IF LINUX ... #ELSE ... #ENDIF for conditional compilation? One a...
Nov 06, 2017 11:25
Forum: Tips and Tricks
Topic: Data-Type, conversion Array's and Overloaded Function's (in a nutshell)
Replies: 39
Views: 1626

### Re: Data-Type, conversion Array's and Overloaded Function's (in a nutshell)

' initialized arrays to convert numbers (array index), to String Dim As String * 9 mnth(1 To 12) = { "January", "February", "March", "April", "May", _ "June", "July", "August", "September", _ "October&quo...
Nov 06, 2017 8:43
Forum: Tips and Tricks
Topic: Data-Type, conversion Array's and Overloaded Function's (in a nutshell)
Replies: 39
Views: 1626

### Re: Data-Type, conversion Array's and Overloaded Function's (in a nutshell)

I cannot replicate this error at all. Mystery solved: It's the UTF-8 BOM. If I instruct my editor not to send it, the code builds without problem. Good to know. Weird, though, that it chokes only for string(8, "x"), not for any other print "xx" command, for example: Print "...
Nov 05, 2017 20:43
Forum: Tips and Tricks
Topic: Data-Type, conversion Array's and Overloaded Function's (in a nutshell)
Replies: 39
Views: 1626

### Re: Data-Type, conversion Array's and Overloaded Function's (in a nutshell)

Have you tried, to replace the char, with the corresponding ASCII-Number? yes, that works: print chr("x") ' error 57, type mismatch print chr(120) ' ok print string(8, "x") ' error 57, type mismatch print string(8, 120) ' ok PRINT STRING(8, "X") ' error 57, type mismat...
Nov 05, 2017 11:18
Forum: Tips and Tricks
Topic: Data-Type, conversion Array's and Overloaded Function's (in a nutshell)
Replies: 39
Views: 1626

### Re: Data-Type, conversion Array's and Overloaded Function's (in a nutshell)

Print String(Len(ttl), "~") ' chokes Print String(Len(ttl), 126) ' works fine Weird! Indeed. FreeBASIC Compiler - Version 1.05.0 (01-31-2016), built for win32 (32bit) Copyright (C) 2004-2016 The FreeBASIC development team. standalone Thanks for the link to the help file . It might deserve...
Nov 05, 2017 2:30
Forum: Tips and Tricks
Topic: Data-Type, conversion Array's and Overloaded Function's (in a nutshell)
Replies: 39
Views: 1626

### Re: Data-Type, conversion Array's and Overloaded Function's (in a nutshell)

Works like a charm, except line 130: Print String(Len(ttl), "~") error 57: Type mismatch, at parameter 2 Print String(Len(ttl), "~") ' chokes Print String(Len(ttl), 126) ' works fine Btw where is the official FB help file? I found two *.chm files in FreeBasic\FbEdit\Help\ but the...
Nov 01, 2017 18:02
Forum: Beginners
Topic: Allocate memory
Replies: 7
Views: 649

### Re: Allocate memory

Windows only ;-)

Code: Select all

`#include "windows.bi"var myptr=HeapAlloc(GetProcessHeap(), 0, 123)print "The size is "; HeapSize(GetProcessHeap(), 0, myptr); " bytes"Sleep`
Oct 31, 2017 15:47
Forum: General
Topic: MessageBoxW and cyrillic captions
Replies: 2
Views: 321

### Re: MessageBoxW and cyrillic captions

The code is built with a BOM, and the MessageBoxW text displays fine. It is the caption that misbehaves. In the meantime, it seems that the problem is system-wide: Even when opening a file with a cyrillic name in MS Word, I get the little squares. Notably, the caption looks correct if the caption st...
Oct 31, 2017 8:37
Forum: General
Topic: MessageBoxW and cyrillic captions
Replies: 2
Views: 321

### MessageBoxW and cyrillic captions

#include "windows.bi" MessageBoxW(0, "Это текст MessageBox", "Это подпись", MB_OK) Looks simple, but on Windows 7-64 (and only there) the caption is not displayed properly. Works fine on XP and Win10, no problem with Chinese or Arabic, no problem for the MessageBox tex...
Oct 29, 2017 15:34
Forum: Tips and Tricks
Topic: Table sort. Fastest sort algo I've ever come to know...
Replies: 22
Views: 3044

### Re: Table sort. Fastest sort algo I've ever come to know...

Thanks, dodicat. It resembles the radix and bucket "sort" algos. The question is perhaps how useful it can be in real life applications; you need to allocate an array of (maxrange-minrange)*sizeof integer bytes. But for limited ranges it is indeed very fast.

Go to advanced search