View Full Version : new here
TomLebowski
06-11-2009, 13:47
hello forum.
I am new thinbasic user. what can you tell me about building of dll and exe files? I have downloaded last update of thinbasic. it's a lot here to explore, I see, it's too much!. I am working since half a year with c++ at school for a studying project. But I am looking for new ways to create graphics and window guis. it's all new for me with a basic language, but I see there are very active forum here. I like it. Found thinbasic by google and saw a lot of good example to learn, very good. sorry for my bad english.
now I need a simple gui example and somthing with graphics. seems to be not so hard to build new thinbasic example in some days. so long, tom
ErosOlmi
06-11-2009, 14:27
Ciao Tom and welcome to thinBasic community forum.
Thanks for indication about how you found thinBasic. What was your search term in Google?
Well, coming from c++ is a big jump :D
As first indication, never forget thinBasic is an interpreted language so you cannot create DLLs or real EXEs but you can create what we call Bundled EXEs that are a sort of self contained package of your scripts plus all what is needed to execute them without the need to have thinBasic installed.
That said, exactly what kind of application are you interested? Graphics inside standard GUI applications or OpenGL applications. Or both?
Search for examples about TBGL module and UI (user interface) module. After installation of thinBasic (if not already done, I strongly suggest latest beta 1.7.10.0 you can find here: http://community.thinbasic.com/index.php?topic=2899.0) go in \thinBasic\SampleScripts\TBGL\ and \thinBasic\SampleScripts\UI\ You will find a lot of examples. A lot more you can find here in forum.
Otherwise give us more precise indications and I'm sure you will get back some quick feedbacks.
Ciao
Eros
Petr Schreiber
06-11-2009, 14:49
Welcome Tom,
thinBASIC offers both classic 2D graphics and hardware accelerated 2D and 3D graphics.
The hardware accelerated ones are provided by TBGL module, and you can start creating by choosing one of the TBGL templates.
There are some additional advanced examples available in form of BonusPacks here:
TBGL BonusPack (http://www.thinbasic.com/index.php?option=com_jdownloads&Itemid=95&task=view.download&cid=6)
TBGL BonusPack Pro (http://www.thinbasic.com/index.php?option=com_jdownloads&Itemid=95&task=view.download&cid=9)
Another option to learn something about thinBASIC are ThinBASIC Journal (http://community.thinbasic.com/index.php?board=160.0)s (PDF magazines).
TomLebowski
12-11-2009, 11:26
thank you both guys !
Ciao Tom and welcome to thinBasic community forum.
Thanks for indication about how you found thinBasic. What was your search term in Google?
I was looking in general for "basic" and "basic + languages", "basic programming" and found for example after one hour by chance (!) this unique forum with thinbasic ("thin") interpreter ! so I was curious what's meaning of "thin".
my first closer question. How I can translate this c++ example to thinbasic ? oop possible ? classes ?
- gui example I have found in sample scripts (you say "ui"). more to come as soon as possible. children make a lot of work at the moment. there is a real hard life beside computer world. but I like and love this life with family as single and very young husband ;)
#include<iostream>
using namespace std;
class Automat
{
private:
int itemCount;
int insertedMoney;
int itemPrice;
public:
Automat(int, int);
void throwIn(int);
int getPrice();
int moneyBack();
bool pushButton();
bool isEmpty();
};
int main()
{
Automat automat(3,3);
automat.throwIn(10);
automat.moneyBack();
automat.throwIn(8);
automat.pushButton();
cin.get();
}
void Automat::throwIn(int money)
{
insertedMoney+=money;
}
int Automat::moneyBack()
{
int temp=insertedMoney;
insertedMoney=0;
return temp;
}
bool Automat::pushButton()
{
if(itemPrice>insertedMoney)
{
return false;
}
if(itemCount==0)
{
return false;
}
--itemCount;
insertedMoney-=itemPrice;
return true;
}
bool Automat::isEmpty()
{
return itemCount==0;
}
int Automat::getPrice()
{
return itemPrice;
}
Automat::Automat(int items, int price)
{
itemCount=items;
insertedMoney=0;
itemPrice=price;
}
before understanding thinbasic I have to learn more about interpreter and behaviour.
any help for thinbasic translation or link would be appreciated. cheerio. tom
Petr Schreiber
12-11-2009, 12:22
Hi Tom,
ThinBASIC does not support OOP classes, but you can easily emulate the case you listed as:
Uses "Console"
Alias Long As bool
' -- like a CLASS
Type Automat
' like private - small first letter
itemCount As Long
insertedMoney As Long
itemPrice As Long
End Type
Function TBMain()
Local myAutomat As Automat
Automat_Constructor(myAutomat, 3, 3)
Automat_throwIn(myAutomat, 10)
Automat_moneyBack(myAutomat)
Automat_throwIn(myAutomat, 8)
Automat_PushButton(myAutomat)
WaitKey
End Function
' -- like a METHODs
Sub Automat_Constructor(object As Automat, items As Long, price As Long)
object.itemCount = items
object.insertedMoney= 0
object.itemPrice = price
End Sub
Sub Automat_throwIn(object As Automat, money As Long)
object.insertedMoney += money
End Sub
Function Automat_moneyBack(object As Automat) As Long
Local temp As Long = object.insertedMoney
object.insertedMoney=0
Return temp
End Function
Function Automat_PushButton(object As Automat) As bool
If(object.itemPrice > object.insertedMoney) Then Return FALSE
If(object.itemCount = 0) Then Return FALSE
object.itemCount -= 1
object.insertedMoney -= object.itemPrice
Return TRUE
End Function
Function Automat_IsEmpty(object As Automat) As bool
Return (object.itemCount = 0)
End Function
Function Automat_getPrice(object As Automat) As Long
Return object.itemPrice
End Function
The use will be simple - first parameter of the methods will be the "object", and the rest will be as usual.
One of the ThinBASIC modules - Oxygen, provides CLASSes. But it is not directly thinBASIC BASIC.
TomLebowski
12-11-2009, 15:02
great, petr. thank you. seems to be not very difficult to translate from c++ to thinbasic.
sorry, one more question. simple method, pointer example. how do you translate pointer example for thinbasic? then I am satisfied for today.
#include<iostream>
using namespace std;
class Test
{
private:
int id;
public:
Test(int id)
: id(id)
{}
void tom()
{
cout<<"Test::tom() mit ID "<<id<<'\n';
}
void bar()
{
cout<<"Test::bar() mit ID "<<id<<'\n';
}
};
void Caller(Test* obj, void (Test::*method)())
{
(obj->*method)();
}
int main()
{
Test t1(1);
Test t2(2);
Caller(&t1, &Test::tom);
Caller(&t2, &Test::tom);
Caller(&t1, &Test::bar);
Caller(&t2, &Test::bar);
}
bye, thank you for very fast reply, tom
zlatkoAB
12-11-2009, 20:41
Excellent Petr- who need OOP anyway :D
Petr Schreiber
12-11-2009, 21:35
Hi Tom,
here you go :)
Just one thing - you can use pointers on variables (numeric, string, UDTs) but not on functions (yet).
This situation for functions (methods) is done differentely in ThinBASIC. As ThinBASIC is interpreter, you can assemble function names on the script run. For this reason your case translated to TB does not have to use pointer to achieve same result.
Uses "Console"
' CLASS >>
Type Test
Id As Long
End Type
Sub Test_Constructor(object As Test, id As Long)
object.Id = id
End Sub
Sub Test_Tom(object As Test)
PrintL "Test::Tom() mit ID "+Format$(object.id)
End Sub
Sub Test_Bar(object As Test)
PrintL "Test::Bar() mit ID "+Format$(object.id)
End Sub
' << CLASS
Sub Caller(object As Test, methodName As String)
' -- CALL will tell ThinBASIC we are assembling the procedure name on the fly
Call methodName(object)
End Sub
Function TBMain()
Local t1, t2 As Test
Test_Constructor(t1, 1)
Test_Constructor(t2, 2)
Caller(t1, "Test_Tom")
Caller(t2, "Test_Tom")
Caller(t1, "Test_Bar")
Caller(t2, "Test_Bar")
WaitKey
End Sub
So you can see it is quite straightforward. I think it does what it should.
Zlatko - OOP ... 2 years ago I would say it is completely redundant thing. But when the syntax is done right, it can be very useful - once Charles finishes CLASSes in oxygen, you will see even OOP can be pleasure and work very fast at the same moment.
Petr
Lionheart008
16-11-2009, 21:53
hi tom, hi petr, all :)
@tom: welcome to the forum too. good to see you are coming from c++ and you can bring new ideas and projects to thinbasic. good luck!
@petr: many thanks for these useful translations! I have studied some weeks ago c++ examples too and wished to have/to get translated these stuff also for thinbasic. many thanks.
best regards, Frank
Michael Hartlef
17-11-2009, 10:05
Hi Tom,
also from my side, a big welcome to our community. I hoep you will enjoy thinBasic.
Take care
Michael :)
TomLebowski
18-11-2009, 12:15
e-mail test :)
hi all, thank you all for help and friendly words for welcome here. my pc has a cold or big trouble. I send only the script as attachement. more to come.
tom
TomLebowski
22-11-2009, 14:24
hi all.
I am looking for input mask for values or strings. don't think of inputbox$, more using functions. perhaps any link or example here for ui/tbgl module.
thanks for hints. bye, tom
Petr Schreiber
22-11-2009, 14:44
If you need to validate strings,
you might use functions like:
IsLike
Letter$ and Letter_SetMask$
Verify
If you need to control what user enters in textbox in real time, catch %EN_UPDATE message:
Uses "UI"
' -- ID numbers of controls
Begin Const
%bClose = %WM_USER + 1
%tInput
End Const
' -- Create dialog here
Function TBMAIN()
Local hDlg As DWord
Dialog NEW 0, "You can use only a,b,c",-1,-1, 160, 60, _
%WS_POPUP Or %WS_VISIBLE Or %WS_CAPTION Or %WS_SYSMENU Or %WS_MINIMIZEBOX To hDlg
' -- Place controls here
Control ADD TEXTBOX, hDlg, %tInput, "", 5, 5, 150, 14, Call bInputProc
Control ADD BUTTON , hDlg, %bClose, "Click to close", 5, 40, 150, 14, Call bCloseProc
Dialog SHOW MODAL hDlg, Call dlgProc
End Function
' -- Callback for dialog
CallBack Function dlgProc()
' -- Test for messages
Select Case CBMSG
Case %WM_INITDIALOG
' -- Put code to be executed after dialog creation here
Case %WM_CLOSE
' -- Put code to be executed before dialog end here
End Select
End Function
' -- Callbacks for controls
CallBack Function bCloseProc()
If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %BN_CLICKED Then
' -- Closes the dialog
Dialog End CBHNDL
End If
End If
End Function
CallBack Function bInputProc()
Local s As String, pos, selStart, selEnd As Long
If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %EN_UPDATE Then
' -- Get the current text
Control GET TEXT CBHNDL, %tInput To s
' -- Is it longer than 0 characters
If Len(s) > 0 Then
' -- Store original cursor position
Control SEND CBHNDL, %tInput, %EM_GETSEL, VARPTR(selStart), VARPTR(selEnd)
' -- Does it contain something else than abc?
pos = Verify(s, "abc")
' -- If yes, trim it!
If pos Then s = LEFT$(s, pos-1)
' --Put text back
Control SET TEXT CBHNDL, %tInput, s
' -- Restore original cursor position
Control SEND CBHNDL, %tInput, %EM_SETSEL, selStart, selEnd
End If
End If
End If
End Function
TomLebowski
24-11-2009, 15:28
thanks petr. your example I will test later. I uses my first example to modify with two gui`s and new classes. thinbasic is become better to known for me. thanks for help.
perhaps you can check the tb script if I have done gui right way.
Uses "Console", "ui"
%ButtonClose = 1001
%ButtonUnknown = 1002
%ButtonCombobx = 1003
%ButtonZero = 1004
' CLASS >>
Type Test
Id As Long
doors As Long
End Type
Sub Test_Constructor(object As Test, id As Long)
object.Id = id
End Sub
Sub Test_Conductor(roomy As Test, doors As Long)
roomy.doors = doors
End Sub
'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Sub Test_Children(object As Test)
PrintL "Test::Children() with ID "+Format$(object.id)
End SUB
Sub Test_MikeyMouse(object As Test)
PrintL "Test::MikeyMouse() with ID "+Format$(object.id)
End SUB
Sub Test_Tom(object As Test)
PrintL "Test::Tom() with ID "+Format$(object.id)
End Sub
Sub Test_Bar(object As Test)
PrintL "Test::Bar() with ID "+Format$(object.id)
End Sub
Sub Test_Simpson(object As Test)
PrintL "Test::Simpson() and push RETURN with ID "+Format$(object.id)
waitkey
call dialogName()
End SUB
'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Sub Test_Gondor(roomy As Test) ', result As String)
'result += "north"
PRINTL "Test::Gondor() with ID "+Format$(roomy.doors)
End Sub
'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Sub Caller(object As Test, methodName As String)
' -- CALL will tell ThinBASIC we are assembling the procedure name on the fly
Call methodName(object)
End Sub
Sub exits(roomy As Test, openExit As String)
Call openExit(roomy)
End Sub
function dialogName() as string
Dim hDlg As DWORD
dim myArraylist(5) as string
Array Assign myArraylist() = "earth", "wind", "fire", "sea", "sky"
DIALOG NEW 0, "myDialog ",-2,-2, 300, 300, _
%WS_POPUP Or _
%WS_VISIBLE Or _
%WS_CLIPCHILDREN Or _
%WS_CAPTION Or _
%WS_SYSMENU Or _
%WS_MINIMIZEBOX, _
0 To hDlg
CONTROL ADD BUTTON, hDlg, %ButtonClose, "Click to close", 90, 40, 140, 100
CONTROL ADD BUTTON, hDlg, %ButtonZero, "zero Button", 90, 140, 80, 80, Call cbDialox
CONTROL ADD COMBOBOX, hDlg, %ButtonCombobx, myArraylist(), 160, 240, 80, 60, %CBS_SORT Or %CBS_DROPDOWN
DIALOG SHOW MODAL hDlg Call cbDialog
end function
Function TBMain()
Local t1, t2, t3, t4, t5, t6,t7 As Test
Test_Constructor(t1, 1)
Test_Constructor(t2, 2)
Test_Constructor(t3, 3)
Test_Constructor(t4, 4)
Test_Constructor(t5, 5)
'- ! -
Test_Conductor(t6,1)
Test_Conductor(t7,2)
Caller(t1, "Test_Tom")
Caller(t2, "Test_Tom")
Caller(t1, "Test_Bar")
Caller(t2, "Test_Bar")
Caller(t3, "Test_Children")
Caller(t4, "Test_MikeyMouse")
Caller(t5, "Test_Simpson")
Exits(t6, "Test_Gondor")
Exits(t7, "Test_Gondor")
printl
printl "all ok with script, return"
WaitKey
End Sub
'------------------------------------------------
' Callback function used to handle dialog events
'------------------------------------------------
CALLBACK Function cbDialog() As Long
Select Case CBMSG
Case %WM_Command
If CBWPARAM = %ButtonClose Then DIALOG End CBHNDL
Case %WM_DESTROY
MSGBOX 0, "Window is to be destroyed ", %MB_OK, "for one time"
End Select
End Function
CallBack Function cbDialox() As Long
Dim hdlg As Long
Dim myArraylist(5) As String
Array Assign myArraylist() = "monroe", "defoe", "watts", "james", "julia"
Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %ButtonZero Then
MsgBox 0, "twenty children in a classroom ", %MB_OK, "one teacher for all"
DIALOG NEW 0, "my2Dialog ",-2,-2, 240, 280, _
%WS_POPUP Or _
%WS_VISIBLE Or _
%WS_CLIPCHILDREN Or _
%WS_CAPTION Or _
%WS_SYSMENU Or _
%WS_MINIMIZEBOX, _
0 To hDlg
CONTROL ADD BUTTON, hDlg, %ButtonClose, "Click to close", 90, 40, 120, 100
CONTROL ADD BUTTON, hDlg, %ButtonClose, "Water", 20, 40, 60, 60
CONTROL ADD BUTTON, hDlg, %ButtonZero, "zero 2 Button", 90, 140, 80, 80, Call cbDialox
CONTROL ADD COMBOBOX, hDlg, %ButtonCombobx, myArraylist(), 160, 240, 80, 60, %CBS_SORT Or %CBS_DROPDOWN
DIALOG SHOW MODAL hDlg Call cbDialog
End If
End Select
End Function
bye, tom
Petr Schreiber
24-11-2009, 16:12
Hi Tom,
good work, I think the code does what it should. I have just two tips for you.
First - syntax based indenting. I think when you look at this:
CallBack Function cbDialog() As Long
Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %ButtonClose Then DIALOG End CBHNDL
Case %WM_DESTROY
MsgBox 0, "Window is to be destroyed ", %MB_OK, "for one time"
End Select
End Function
and this:
CallBack Function cbDialog() As Long
Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %ButtonClose Then DIALOG End CBHNDL
Case %WM_DESTROY
' -- cbHndl instead of zero makes sure the message box is created as child of the main window
MsgBox cbHndl, "Window is to be destroyed ", %MB_OK, "for one time"
End Select
End Function
The second one is much easier to read.
Second tip will save you some work. Instead of:
%ButtonClose = 1001
%ButtonUnknown = 1002
%ButtonCombobx = 1003
%ButtonZero = 1004
you can use
begin const
%ButtonClose = 1001
%ButtonUnknown
%ButtonCombobx
%ButtonZero
end const
This way thinBasic automatically assigns number +1 to each equate after previous one.
Lionheart008
24-11-2009, 22:59
hello tom, petr.
since I have been started with thinbasic I have looked the first days for simple input / string / number example. here is another example for this case.
'-- for tom, another string/number example by lionheart
uses "console", "ui"
begin const
%BTN_Test = 1010
%LBL_LABEL1
%LBL_LABEL2
%TXT_TEXTBOX1
%TXT_TEXTBOX2
%IDOK2
end const
'------------------
msgbox 0, "shows: another input string/number example", %MB_OK, "test-me"
CALLBACK FUNCTION DlgProc()
LOCAL sTest,sTest2 as string
local x,y as string
SELECT CASE CBMSG
CASE %WM_COMMAND
SELECT CASE CBCTL
CASE %IDOK
IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
CONTROL GET TEXT CBHNDL, %TXT_TEXTBOX1 TO sTest
MSGBOX 0, "sTest123.. = "+stest, ,"myResult"
END IF
CASE %IDOK2
IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
CONTROL GET TEXT CBHNDL, %TXT_TEXTBOX2 TO sTest2
MSGBOX 0, "sTestABC.. = "+stest2, ,"myResult2"
END IF
CASE %TXT_TEXTBOX1
IF CBCTLMSG = %EN_UPDATE THEN
CONTROL GET TEXT CBHNDL, %TXT_TEXTBOX1 TO sTest
x = VERIFY (sTest , "-+,.1234567890")
IF x > 0 THEN
sTest = REMOVE$(sTest, MID$(sTest, x, 1))
CONTROL SET TEXT CBHNDL, %TXT_TEXTBOX1, sTest
CONTROL SEND CBHNDL, %TXT_TEXTBOX1, %EM_SETSEL, x-1, x-1
END IF
END IF
CASE %TXT_TEXTBOX2
IF CBCTLMSG = %EN_UPDATE THEN
CONTROL GET TEXT CBHNDL, %TXT_TEXTBOX2 TO sTest2
y = VERIFY (sTest2 , "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
IF y > 6 THEN
sTest2 = REMOVE$(sTest2, MID$(sTest2, y, 1))
CONTROL SET TEXT CBHNDL, %TXT_TEXTBOX2, sTest2
CONTROL SEND CBHNDL, %TXT_TEXTBOX2, %EM_SETSEL, y-1, y-1
END IF
END IF
END SELECT
CASE %WM_SYSCOMMAND
IF (CBWPARAM AND &HFFF0) = %SC_CLOSE THEN
DIALOG END CBHNDL
END IF
END SELECT
END FUNCTION
FUNCTION TBMAIN()
LOCAL hDlg AS DWORD
DIALOG NEW 0, "Numeric/String Input Test", -1, -1, 200, 150, _
%WS_POPUP Or _
%WS_VISIBLE Or _
%WS_CLIPCHILDREN Or _
%WS_CAPTION Or _
%WS_SYSMENU Or _
%WS_MINIMIZEBOX, _
0 To hDlg
CONTROL ADD LABEL, hDlg, %LBL_LABEL1, "1) allowed is: -+,.1234567890", 50, 25, 120, 20
CONTROL ADD LABEL, hDlg, %LBL_LABEL2, "2) allowed is: ABCDEFGHIJKLMNOPQRSTUVWXYZ", 15, 35, 260, 20
CONTROL ADD BUTTON, hDlg, %IDOK, "Test1: 123..", 35, 60, 60, 16
CONTROL ADD BUTTON, hDlg, %IDOK2, "Test2: Abc..", 105, 60, 60, 16
CONTROL ADD TEXTBOX, hDlg, %TXT_TEXTBOX1, "", 45, 90, 100, 14
CONTROL ADD TEXTBOX, hDlg, %TXT_TEXTBOX2, "", 45, 120, 100, 14
DIALOG SHOW MODAL hDlg, Call DlgProc
END FUNCTION
the task belongs to a current question from tom to here:
http://community.thinbasic.com/index.php?topic=2960.msg22865;topicseen#new
hope it helps.
best regards, frank