Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C++ in QB?
#6
(05-26-2024, 04:11 PM)CletusSnow Wrote: I think I read somewhere that it is possible to use C++ code within a QB program. But unfortunately I can't find any information about it.
Is it possible, and if so, how?
For example, it goes like this:

The Basic file (Both files in the same ordner):
Code: (Select All)

Option _Explicit

'In QB64 mit "Declare Library" wie angegeben
Declare Library "D:\Lab\QuickBasic64\Extern-nicht-Basic\Basic-ruft-C\bfibonacci"
  Function fibo& (ByVal N As Integer)
End Declare

Dim As Integer N, rueckgabe
Dim As Single zeitstart, zeitende

Timer On

Cls
Locate 3, 3
Input "Berechnet die Fibonacci-Zahl von: ", N

zeitstart = Timer

Locate 5, 3
rueckgabe = fibo&(N%)
If rueckgabe = -1 Then
  Print "Eingabe zu gross!"
  Sleep: System
Else
  Print Using "Die Fibonacci-Zahl von ## = ###,########"; N; fibo&(N%)
End If

zeitende = Timer

Locate 7, 3
Print Using "Sekunden: ##.#### "; zeitende - zeitstart

End

The C-file ( bfibonacci.h):
Code: (Select All)

#include <stdio.h>
#include <stdlib.h>

long fibo(int n)
{
long x, y;
int i;

//Um bei 3 eine Anzeige von: 1 2 3 zu erreichen
x = y = i = 1;
if (n == 0 || n == 1)
{
return(n);
}
if (n > 40)
{
return(-1);
//sonst Überlauf
}
else while (i < n)
{
x = x + y; y = x - y; i++;
}
return(x);
}
Reply


Messages In This Thread
C++ in QB? - by CletusSnow - 05-26-2024, 04:11 PM
RE: C++ in QB? - by BSpinoza - 05-26-2024, 04:19 PM
RE: C++ in QB? - by CletusSnow - 05-26-2024, 04:39 PM
RE: C++ in QB? - by RhoSigma - 05-26-2024, 04:46 PM
RE: C++ in QB? - by CletusSnow - 05-26-2024, 05:29 PM
RE: C++ in QB? - by grymmjack - 05-27-2024, 03:44 PM
RE: C++ in QB? - by Kernelpanic - 05-26-2024, 05:49 PM



Users browsing this thread: 4 Guest(s)