1. Where do I find out all the functions available to me through various libraries, like vbcompat, and any others? I see references to them, but am not sure where I can find the contents themselves.
2. How do I make my own include file for my own functions that I use all the time? Any best practices?
3. If I want to modify data that is provided to a Sub, rather than working on a copy of that data, do I always need to explicitly indicate ByRef?
4. The code below raises two errors with the compiler. I know I'm probably doing this the "PHP" way, but in addition to figuring out why the length won't print out, I'm looking for a way to get the type returned by a function, in order to troubleshoot its use. I thought I'd try TypeOf for that but I'm not sure how it's used (below).
Code: Select all
'Show the length of input text
Dim as String MyName, FileName
Dim as Integer NameLength, MyVar
Print "Hello world!"
Input "What's your name? ", MyName
MyVar = LEN(MyName)
'ERROR 3: Line below raises error: Unexpected EOL. Why?
Print TypeOf(MyVar)
'ERROR 20: Line below raises error: Type mismatch, found '+' ...why?
Print "Hello, " + MyName + ". " + "Your name is " + NameLength + " letters long."
Code: Select all
' The following code loads an avatar.png and then displays it, waits for a keystroke, and then quits:
#INCLUDE "SDL\SDL.bi" 'SDL inkludieren.
#DEFINE xmax 640 'Fensterweite
#DEFINE ymax 480 'Fensterhöhe
DIM SHARED video AS SDL_Surface PTR 'Pointer auf den späteren Fensterpuffer.
DIM SHARED event AS SDL_Event 'Event zum Abfangen von Tastenanschlägen.
'Einmal ein Fenster der größe 640x480 mit 32bit Farbtiefe
'SDL_HWSURFACE = Im Grafikspeicher (Grafikkarte / Reservierter RAM in manchen Laptops)
'SDL_DOUBLEBUF = Mit 2 Pages, damit das Zeichnen nicht so hässlich aussieht
'SDL HWACCELL = Und Hardwarebeschleunigt
video = SDL_SetVideoMode(xmax,ymax,32, SDL_HWSURFACE OR SDL_DOUBLEBUF OR SDL_HWACCEL)
'Unter Freebasic entspräche das ungefähr screenres 640,480,32,2
'SDL_HWACCEL und SDL_HWSURFACE haben keine wirkliche Entsprechung.
''Ein Bild wie einen Avatar könnte man nun einfach mit
'IMG_Load laden.
''Code dafür wäre:
DIM avatar AS SDL_SURFACE PTR
avatar = IMG_Load("avatar.png")
''Gezeichnet kann das Ganze dann mit SDL_BlitSurface(start,startkoordinaten,Ziel, Zielkoordinaten) werden.
SDL_BlitSurface(avatar,NULL,video,NULL)
''Und angezeigt wird das Ganze letzendlich mit
SDL_Flip(video)
''und wenn man das Bild nicht mehr braucht, einfach mit
SDL_FreeSurface(avatar)
''den Speicher freigeben.
WHILE 1
SDL_PollEvent(@event) 'Falls ein Event geschehen ist (Taste gedrückt?) bitte in event speichern.
SELECT CASE event.TYPE 'Event ist ein zusammengesetzter Datentyp und hat von SDL aus schon einen Typen (Maus, Tastatur usw)
CASE SDL_KEYDOWN: 'Falls eine Taste gedrückt wurde, Programm beenden.
SDL_QUIT() 'SDL beenden und Fenster schließen.
END
END SELECT
WEND