Post your coding questions such as 'how to' here.
Post Reply
Posts: 11
Joined: Mon Aug 11, 2008 1:36 am


Post by Hacker » Thu Oct 18, 2012 3:22 pm

Hello :)

Hello :) I have some doubts about coolbasic ... Could you please help me?

I do not see much use of "arrays" and "classes" because I read the manual coolbasic but I speak Spanish :(. Could someone post a source code where
can explain this?

The other problem I have is that I try to create functions. But when I use the command "include" and try to compile I get an error that says "can't open include file ...." and I can not use functions :( help me please.

thank you very much for your help!

User avatar
Devoted Member
Posts: 575
Joined: Mon Aug 27, 2007 8:37 pm

Re: HELP ME u.u

Post by Jonez » Thu Oct 18, 2012 4:21 pm

There are no classes in CB.

You declare an array with the keyword Dim. An array is always global.

Code: Select all

Dim array(10)
would make an array with 11 cells (0 to 10). The array type is Integer as default.

Code: Select all

Dim array(10) As String
would make a String array.

To make a function you use the syntax: Function fName(param1, param2, ...) [Function code here] End Function

Code: Select all

Function HelloWorld()
    Print "Hello World"
To return from a function you use the command "Return [returnValue]". You cannot use just "return", but must always return a value. Edit: but you don't actually need a return-command if you don't want to return a value. A function can return all basic data type values, so there are no specific return types for ints, floats etc.

A parameter for a function can be only a primitive data type. For example, you can't put an array as a parameter (this will most likely change in the upcoming coolbasic, at least I truly hope so). The same goes for returning a value.

To include a file you simply use the command 'Include "filepath"'. If the compiler complains, most likely the path is incorrect. With unsaved code the path root (for relative paths) is the Coolbasic-folder. For saved files and exes the root is where the source or exe is. The include command only includes a separate .cb-source file, and it's of course really useful, but not mandatory. You can write all your code to a single file if you want.
-Vuoden 2008 aloittelijan ystävä -palkinnon voittaja-
Image <- protestipelikilpailun voittaja.
Space War

User avatar
Devoted Member
Posts: 854
Joined: Tue Sep 18, 2007 6:50 pm

Re: HELP ME u.u

Post by axu » Thu Oct 18, 2012 5:01 pm

While there are no classes in cb, somewhat comparable are Types. Types are custom data structures and are always stored in linked lists. You can use types like this:

Code: Select all

//Create collection named "MyFirstType" containing 2 fields (or properties)
Type MyFirstType
    Field someNumber
    Field someString As String
End Type

//Create new instance of MyFirstType (note: variable_name.type_name notation is used to declare variable as a type member)
a.MyFirstType = New(MyFirstType)
//Accessing type fields via backslash (\)
a\someNumber = 5
a\someString = "Hello "

b.MyFirstType = New(MyFirstType)
b\someNumber = 9
b\someString = "World"

//Iterate over all type members:
For i.MyFirstType = Each MyFirstType
    //Calculate sum of all someNumbers
    counter = counter + i\someNumber
    //Output someString
    Write i\someString
Next i
Print "" //Start a new line
Print "Sum: " + i\someNumber

Types cannot contain functions (methods) and doesn't support typical oo-programming like inheritance. Members of one type are always contained in same list which can be iterated over For Each loop, or using First(Type), Last(Type), After(TypeMember) and Before(TypeMember) commands. Delete(TypeMember) deletes type member.
Jos tämä viesti on kirjoitettu alle 5 min. sitten, päivitä sivu. Se on saattanut jo muuttua :roll:

User avatar
Posts: 1588
Joined: Thu Dec 06, 2007 8:46 pm
Location: Espoo

Re: HELP ME u.u

Post by valscion » Fri Apr 10, 2015 10:51 am

Nattakiha wrote:Want to contact this topic to do.
Hi Nattakiha, and welcome to CoolBasic Forums!

Could you elaborate on what you mean by "Want to contact this topic to do."? Your message is quite unclear.

We would like to have only posts with some quality here and so far your two messages have not really been that great. Please provide more content on the topics you post in order for us moderators not to have to do any further actions.

Thank you, and welcome to the community!
cbEnchanted, uudelleenkirjoitettu runtime. Uusin versio: 0.4.1 — Nyt myös sorsat GitHubissa!
NetMatch - se kunnon nettimättö-deathmatch! Avoimella lähdekoodilla varustettu

Post Reply