View Full Version : New To Programming
OneHitWonder
29-06-2010, 23:45
Hello everyone,
I am sorry if I place this topic in the wrong section as I could not find a "Beginners" section.
I have always wanted to learn how to program but never actually got round to doing it. After a search on google I came across ThinBasic.
I was just hoping someone could point me in the right direction as I have never programmed before and would like to get started right away.
Kind regards,
OneHitWonder.
ErosOlmi
30-06-2010, 07:50
Ciao OneHitWonder and wellcome to thinBasic community forum.
I think thinBasic can be one of the best choice to start programming.
The problem is: where, how and at what level to start.
First install latest thinBasic version (http://community.thinbasic.com/index.php?topic=3480) in your computer.
Done that you will find an icon called thinAir. thinAir is the editor we use to write programs in thinBasic. It is a classical editor full of features dedicated to thinAir programming language.
On programming I usually follow an empirical method: have a simple but real problem to face and use it to discover a programming language. It must be not that complex problem in order to concentrate your efferts on the programming and less on the problem itself.
Done that I would concentrate on What is a variable in programming. It is the basis of whatever programming language you would face.
So what's next?
It depends on the path you would like to follow.
Give us more info.
Petr Schreiber
30-06-2010, 08:50
Welcome OneHitWonder,
one of the possible resources for study could be the ThinBASIC Tutorial. Where can you find it?
Just navigate to your ThinBASIC installation folder, SampleScripts/Tutorial and launch the script. It covers few basic topics, might be interesting for you.
Another resource are the ThinBASIC Journals, these are magazines covering various topics:
Journal #1 (http://community.thinbasic.com/index.php?topic=1865.0)
Journal #2 (http://community.thinbasic.com/index.php?topic=2310.0)
But as Eros said, one of the best approaches is to try to solve some problem.
Petr
Lionheart008
30-06-2010, 09:14
good morning OneHitWonder, welcome from my side too :)
As I know how it is as newbie or programming beginner with such a strange and new programming language like thinbasic here a little example for you to start. 1) one console application and 2) creating a short dialog.
A) After you have installed thinbasic, load a script from this board or have a closer look at the "Samplescripts" folder at Thinbasic directory. push "F5" to compile the example. push "F1" to get help from manual, there are many example too for helping you.
B) open the "samplescript" folder you will find more than 50 folders with special "module" power like "UI", "TBGL", "console" and much more. There you'll find a lot of predefined example you can use and making some personal experiences how to handle with thinbasic.
my little help for you:
info: little notice, there are two example into one. one uses "console" script and then the other one uses "ui" for building simple dialog example.
' Empty GUI script created on 06-30-2010 08:55:43 by (ThinAIR)
Uses "console", "UI"
PrintL "hello and welcome to Mr. OneHitWonder at this day: " + Date$
PrintL
MsgBox 0, "hello dear Mr. OneHitWonder", %MB_OK, "have a nice time with thinbasic :)"
PrintL
PrintL "press any key to quit this thinbasic example, thanks!"
WaitKey
PrintL
PrintL "or you can create a graphic user interface (GUI) with this few lines"
PrintL
'--end first console example ----------------------------------------------------------
'---Define a button ID
%ButtonClose = 1001
%thankyou = 1002
Dim hDlg As DWord
Dialog New 0, "myDialog",-1,-1, 330, 203, _
%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 kill", 90, 50, 80, 24
Control Add Button, hDlg, %thankyou, "thank you :)", 90, 90, 80, 24
Dialog Show Modal hDlg Call cbDialog
'------------------------------------------------
' 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
If CBWPARAM = %thankyou Then
MsgBox 0, "thank you, dear mr. OneHhitWonder for using Thinbasic"
End If
Dialog End CBHNDL
Case %WM_DESTROY
MsgBox 0, "Window is to be destroyed."
End Select
End Function
'--end second "ui" example -----------------------------------------------------------
you will notice very soon, it's very easy to build your first thinbasic example. but as eros and petr already said, what's your aim with using such a programming language ?
feel free to ask, don't hesitate, any good help you will get here very fast, I am sure ;)
best regards, frank
OneHitWonder
30-06-2010, 10:45
Good morning,
Thanks for your replies and for making me feel welcome here at this community. I have been doing quite a lot of reading on programming languages in general and have picked up some of the basics, variables, program flow. I just need to re-read up on subroutines and functions again.
The help manual has been very helpful, especially the module section and gives me the commands.
LionHeart008 I got slightly confused with your UI example I think I will stick with the console window until I get more experience.
It think I will concentrate on input and output and create a guessing game I read that is a good pratice.
If anyone has any more advice I would like to hear it.
Thanks again for your help.
OneHitWonder
ErosOlmi
30-06-2010, 12:47
I hope your feeling in thinBasic community will be always high.
We try our best to be helpful and have a nice place where to stay and talk about programming and technology passions.
LionHeart008 I got slightly confused with your UI example I think I will stick with the console window until I get more experience.
Usually console applications are separated by GUI ones. So programmers tends to make application for one world OR for the other.
In thinBasic you can easily mix them together because each of them is governed by a dedicated thinBasic module and both can be loaded at the same time into a script. Having standard windows handled with events and also a console window where to play with classic PRINT commands in comfortable in some situations.
Ciao
Eros
OneHitWonder
01-07-2010, 23:54
Hey,
As I mentioned in my previous post I was going to concentrate on making a simple guessing game. This is what I have come up with :o.
Uses "Console"
Randomize
Dim answer As Integer = Rnd (1, 100)
Dim guesses As Integer = 5
Dim guess As Integer
Console_WriteLine "Guess a number between 1 - 100"
Do
Console_Write "Guesses: " + guesses + " "
guess = Console_ReadLine
If guess < 0 Then
Console_WriteLine "Guess higher than 0"
ElseIf guess > 100 Then
Console_WriteLine "Guess lower than 100"
ElseIf guess > 0 And guess < 100 And guess < answer Then
Console_WriteLine "Try again, guess higher!"
guesses = guesses - 1
ElseIf guess > 0 And guess < 100 And guess > answer Then
Console_WriteLine "Try again, guess lower!"
guesses = guesses - 1
Else
Console_WriteLine "You win!"
Exit Do
EndIf
Loop Until guesses = 0
Console_WaitKey
OneHitWonder
Michael Clease
02-07-2010, 00:58
Almost but good for a first try.
Here is another solution
Uses "Console"
Randomize
Dim answer As Long = Rnd (1, 100)
Dim guesses As Long = 5
Dim guess As Long
Console_WriteLine "Guess a number between 1 - 100"
Do
Console_Write "Guesses: " + guesses + " "
guess = Console_ReadLine
If guess < 0 Then
Console_WriteLine "Guess higher than 0"
ElseIf guess > 100 Then
Console_WriteLine "Guess lower than 100"
ElseIf guess < answer Then
Decr guesses
If Guesses > 0 Then Console_WriteLine "Try again, guess higher!"+$CRLF
ElseIf guess > answer Then
Decr guesses
If Guesses > 0 Then Console_WriteLine "Try again, guess lower!"+$CRLF
Else
Console_WriteLine "You win!"
Exit Do
EndIf
Loop While guesses > 0
If Guesses <= 0 Then Console_WriteLine $CRLF+"Sorry you failed"
Console_WaitKey
OneHitWonder
02-07-2010, 01:34
Thanks for that example, I had no idea about the decr function thats pretty useful!
Thanks for your help on this.
If you could reccomend something else simple I should try making if you don't mind?
EDITED
I think it would be a good idea if DECR & INCR could have parimeters to handle how much to increase and descrease by. :D
OneHitWonder
John Spikowski
02-07-2010, 03:10
I think it would be a good idea if DECR & INCR could have parimeters to handle how much to increase and descrease by.
I'm pretty sure thinBASIC supports the following expression.
a += 3 ' same as a = a + 3
b -= 3 ' same as b = b - 3
OneHitWonder
02-07-2010, 04:14
Hey,
Your right that's a lot better to write.
Can anyone tell me whats wrong with this please. The answer always appears to be 100.
Uses "Console"
Randomize
Dim answer As Integer = Rnd (1, 100)
Dim guesses As Integer = 5
Dim guess As Integer
Console_WriteLine "Guess a number between 1 - 100"
Do
Console_Write "Guesses: " + guesses + " "
guess = Console_ReadLine
If guess = $NUL Then
Console_WriteLine "You must enter a number!" + $CRLF
ElseIf guess < 0 Then
Console_WriteLine "Guess higher than 0" + $CRLF
ElseIf guess > 100 Then
Console_WriteLine "Guess lower than 100" + $CRLF
ElseIf guess > 0 And guess < 100 And guess < answer Then
Console_WriteLine "Try again, guess higher!" + $CRLF
guesses -= 1
ElseIf guess > 0 And guess < 100 And guess > answer Then
Console_WriteLine "Try again, guess lower!" + $CRLF
guesses -= 1
Else
Console_WriteLine "You win!" + $CRLF
Exit Do
EndIf
Loop Until guesses = 0
If guesses <= 0 Then
Console_Write "You lose!"
EndIf
Console_WaitKey
OneHitWonder
ErosOlmi
02-07-2010, 08:06
INCR and DECR were originally developed without additional parameters in order to speed up operations (only variable pointer is needed to be parsed in order thinBasic engine can understand what to do).
But thinBasic has +=, -=, *=, /=, \=, &= assignment syntaxes too so conversion from other languages is easy.
thinBasic also supports & and . (yes, point like in PHP) for string concatenation
:? I tried your script in all the possibilities and seems working fine here (see attached image).
PS: when adding code to forum posts, if you use the "Syntax Highlight (geShi)" drop down combo, you will get colored syntax ;)
It is like the standard code tag but it adds the language name in side the tag so forum can chose the correct color and syntax.
OneHitWonder
02-07-2010, 11:46
Nice guess!
However I still have a problem with this code.
Uses "Console"
Randomize
Dim answer As Integer = Rnd (1, 100)
Dim guesses As Integer = 5
Dim guess As Integer
Console_WriteLine "Guess a number between 1 - 100"
Do
Console_Write "Guesses: " + guesses + " "
guess = Console_ReadLine
If guess = $NUL Then
Console_WriteLine "You must enter a number!" + $CRLF
ElseIf guess < 0 Then
Console_WriteLine "Guess higher than 0" + $CRLF
ElseIf guess > 100 Then
Console_WriteLine "Guess lower than 100" + $CRLF
ElseIf guess > 0 And guess < 100 And guess < answer Then
Console_WriteLine "Try again, guess higher!" + $CRLF
guesses -= 1
ElseIf guess > 0 And guess < 100 And guess > answer Then
Console_WriteLine "Try again, guess lower!" + $CRLF
guesses -= 1
Else
Console_WriteLine "You win!" + $CRLF
Exit Do
EndIf
Loop Until guesses = 0
If guesses <= 0 Then
Console_Write "You lose!"
EndIf
Console_WaitKey
I have also added a screenshot of my problem.
OneHitWonder
Michael Clease
02-07-2010, 12:10
The way you have written it that is correct behaviour.
But this is what you are after(as per my last post), you were doing checks that were not required, you had already check earlier in the program.
Found another bug if you enter 0 it showed the message "you must enter a number".
Uses "Console"
Randomize
Dim answer As Integer = Rnd (1, 100)
Dim guesses As Integer = 5
Dim guess As Integer
Dim Input As String
Console_WriteLine "Guess a number between 1 - 100"
Do
Console_Write "Guesses: " + guesses + " "
Input = Console_ReadLine
Guess = Input
If Input = "" Then
Console_WriteLine "You must enter a number!" + $CRLF
ElseIf guess < 0 Then
Console_WriteLine "Guess higher than 0" + $CRLF
ElseIf guess > 100 Then
Console_WriteLine "Guess lower than 100" + $CRLF
ElseIf guess < answer Then
Console_WriteLine "Try again, guess higher!" + $CRLF
guesses -= 1
ElseIf guess > answer Then
Console_WriteLine "Try again, guess lower!" + $CRLF
guesses -= 1
Else
Console_WriteLine "You win!" + $CRLF
Exit Do
EndIf
Loop Until guesses = 0
If guesses <= 0 Then Console_Write "You lose!"
Console_WaitKey
ErosOlmi
02-07-2010, 13:22
Using SELECT CASE ...
Uses "Console"
Randomize
Dim answer As Integer = Rnd (1, 100)
Dim guesses As Integer = 50
Dim guess As Integer
Dim Input As String
PrintL "Guess a number between 1 - 100"
Do
Print "Guesses: " + guesses + " "
Input = Console_ReadLine
If Input = "" Then
PrintL "You must enter a number!"
Else
Guess = Input
Select Case Guess
Case < 0
PrintL "Guess higher than 0"
Case > 100
PrintL "Guess lower than 100"
Case < answer
PrintL "Try again, guess higher!"
guesses -= 1
Case > answer
PrintL "Try again, guess lower!"
guesses -= 1
Case Else
PrintL "You win!"
Exit Do
End Select
End If
Loop Until guesses = 0
If guesses <= 0 Then Print "You lose!"
WaitKey