1st Time User Gambas Questions(Former VB6 user)

Post

Posted
Rating:
#1 (In Topic #296)
Trainee
Hello Everyone

I recently got into linux and now im exploring my way through gambas which was the closes thing i could find similar to VB6. I've search the net of ways to translate vb6 Type Statement to Gambas which only uses TypeOF and all i can find are types datatypes unrelated to what im trying to achive. So the question is, how does gambas do things like the way VB6 translates this?

Code

Public DataStuff as DataStruct

Private Type DataStruct
   a as string
   b as byte
   c as integer
   d as long
End Type

Question 2:
I've started tinkering with "Public Const" stuff and what's got me stumped is that Gambas doesn't like the way this is written.

Code

Public Const White as byte = 1
Public Const SayColor as byte = White

Is there a logical way of making Gambas understand that "White" is declared as a numeric value?
The error presented as follows: <COLOR color="#FF0000">Type Mismatch in modConstants.module:137</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#2
Regular
vuott is in the usergroup ‘Regular’
However, remember that Gambas is not a VB emulation.

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
Some information from the Gambas Wiki on STRUCT:

http://gambaswiki.org/wiki/lang/structdecl

When using embedded structures, or embedded arrays of structure, the interpreter has to create temporary objects so that you can manipulate them like real objects. And this is slower!
Consequently, DON'T USE STRUCTURES, UNLESS YOU HAVE TO! For example, to communicate with a shared C-library function that requires C structures.

and

If you declare the same structure in two different classes, they must have exactly the same fields, otherwise the interpreter will raise an error.

Personally, I prefer to create a small class now than use a STRUCT as it gives so much more extensibility.

Cheers - Quin.
I code therefore I am
Online now: No Back to the top

Post

Posted
Rating:
#4
Trainee

Quincunxian said

Some information from the Gambas Wiki on STRUCT:

http://gambaswiki.org/wiki/lang/structdecl

When using embedded structures, or embedded arrays of structure, the interpreter has to create temporary objects so that you can manipulate them like real objects. And this is slower!
Consequently, DON'T USE STRUCTURES, UNLESS YOU HAVE TO! For example, to communicate with a shared C-library function that requires C structures.

and

If you declare the same structure in two different classes, they must have exactly the same fields, otherwise the interpreter will raise an error.

Personally, I prefer to create a small class now than use a STRUCT as it gives so much more extensibility.

vuott said

For the project im doing its actually needed. If you can show me a psuedo code that would help a lot.

Hello,

1st answer:

Code (gambas)

  1. Public Struct DataStruct
  2.         a As String
  3.         b As Byte
  4.         c As Integer
  5.         d As Long
/lang/structdecl - Gambas Documentation


2nd answer:
Not variables and only certain native datatypes can be assigned.
/lang/constdecl - Gambas Documentation


However, remember that Gambas is not a VB emulation.

Thanks for that, I found this link last minute before I saw this post.

As for the 2nd answer, thats disappointing, would of saved me a lot of time remembering values for calculations. it looks like im going to have to type out long codes everytime i set arguements…
Online now: No Back to the top

Post

Posted
Rating:
#5
Trainee

Quincunxian said

Some information from the Gambas Wiki on STRUCT:

http://gambaswiki.org/wiki/lang/structdecl

When using embedded structures, or embedded arrays of structure, the interpreter has to create temporary objects so that you can manipulate them like real objects. And this is slower!
Consequently, DON'T USE STRUCTURES, UNLESS YOU HAVE TO! For example, to communicate with a shared C-library function that requires C structures.

and

If you declare the same structure in two different classes, they must have exactly the same fields, otherwise the interpreter will raise an error.

Personally, I prefer to create a small class now than use a STRUCT as it gives so much more extensibility.

vuott said

Hello,

1st answer:

Code (gambas)

  1. Public Struct DataStruct
  2.         a As String
  3.         b As Byte
  4.         c As Integer
  5.         d As Long
/lang/structdecl - Gambas Documentation


2nd answer:
Not variables and only certain native datatypes can be assigned.
/lang/constdecl - Gambas Documentation


However, remember that Gambas is not a VB emulation.

Thanks for that, I found this link last minute before I saw this post.

As for the 2nd answer, thats disappointing, would of saved me a lot of time remembering values for calculations. it looks like im going to have to type out long codes everytime i set arguements…
For the project im doing its actually needed. If you can show me a psuedo code that would help a lot.
Online now: No Back to the top

Post

Posted
Rating:
#6
Trainee
After exploring much of research into Gambas I came into a conclusion that Gambas isn't ready yet. It's still being updated and is probably close to being up to par with VB6. I'm impressed on how far its went up until now, but it does still lacks some features and support. I'll keep tabs on updates until its ready enough to port my VB6 project over. Its rather a heavy coded project and Gambas still doesn't support some key elements to get it work. It's close but not close enough just yet. Looks like I'll be putting this one down for a bit regrettably. :|

Regards, Lavos
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Regular
Technopeasant is in the usergroup ‘Regular’
 Often Gambas is merely differently implemented than VB, rather than neccesairly feature incomplete, but I can not speak for your project in particular.

If you want a suggestion for another similar IDE for Linux, you may want to look into Lazarus. Very similar RAD environment for building GUI applications, if you are willing to adapt to Pascal.
Online now: No Back to the top

Post

Posted
Rating:
#8
Trainee

Technopeasant said

Often Gambas is merely differently implemented than VB, rather than neccesairly feature incomplete, but I can not speak for your project in particular.

If you want a suggestion for another similar IDE for Linux, you may want to look into Lazarus. Very similar RAD environment for building GUI applications, if you are willing to adapt to Pascal.

Interesting, I looked up Lazarus and it does look appealing to me. I'll probably play around with it sometime soon.
As for Gambas, I find Gambas Method of Syntax very odd and inflexible, restricted, limited.

Here are some of my baffling examples…
<IMG src="https://i.imgur.com/SXlzdQX.png"> </IMG>

<IMG src="https://i.imgur.com/sL0j7Bs.png"> </IMG>

<IMG src="https://i.imgur.com/opjAsJa.png"> </IMG>

I spent a while reading up on the documentation… it's meh… and the strangest part is having to use an address or key?, to a module or class to call a function or routine.
Online now: No Back to the top

Post

Posted
Rating:
#9
Avatar
Guru
cogier is in the usergroup ‘Guru’
Hi Lavos,

The first error you show is caused by you trying to do a 'Dir', which requires a directory, and you are suppling a filename.

Looking at the code you are trying to find if a file exists and the best way to do that is with the 'Exist' command.

You can use &/ to join 2 paths together and you wont have to worry about the slash. The following lines produce the same result:-

Code (gambas)

  1. Print Exist(User.Home &/ ".bashrc")
  2. Print Exist(User.Home &/ "/.bashrc")
Online now: No Back to the top

Post

Posted
Rating:
#10
Trainee

cogier said

Hi Lavos,

The first error you show is caused by you trying to do a 'Dir', which requires a directory, and you are suppling a filename.

Looking at the code you are trying to find if a file exists and the best way to do that is with the 'Exist' command.

You can use &/ to join 2 paths together and you wont have to worry about the slash. The following lines produce the same result:-

Code (gambas)

  1. Print Exist(User.Home &/ ".bashrc")
  2. Print Exist(User.Home &/ "/.bashrc")

I've read the documentations about how using exist command works and played around with it before you made this post. It seems to work just fine when i swapped out Dir using File.Dir to see if the file exists.

Do you have any idea why I can't manipulate a Boolean function within its scope?
<IMG src="http://i.imgur.com/ujTjXdF.png"> </IMG>
Online now: No Back to the top

Post

Posted
Rating:
#11
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
Hi Lavos - can you post the code in modDatabase where .FileExist is declared please.

Cheers - Quin.
I code therefore I am
Online now: No Back to the top

Post

Posted
Rating:
#12
Trainee

Quincunxian said

Hi Lavos - can you post the code in modDatabase where .FileExist is declared please.

<IMG src="https://i.imgur.com/GwaKlr9.png"> </IMG>
Does this helps? 8-)
Online now: No Back to the top

Post

Posted
Rating:
#13
Avatar
Guru
cogier is in the usergroup ‘Guru’
That helped me. :P

Just use: -

Code (gambas)


not

Code (gambas)

  1. .FileExist = True
Online now: No Back to the top

Post

Posted
Rating:
#14
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
 Yeah - I don't know how I missed that. *sigh*

Cheers - Quin.
I code therefore I am
Online now: No Back to the top

Post

Posted
Rating:
#15
Trainee

cogier said

That helped me. :P

Just use: -

Code (gambas)


not

Code (gambas)

  1. .FileExist = True
Thank you. That makes more sense. I'm still in a habit of coding in vb6. I'm still really trying hard to adapt to gambas way of understanding how it works.<EMOJI seq="1f60e">😎</EMOJI>

Anyway ive read the documentation for structs time and time again because it imo, vague… so im jyst gunna ask, is it possible to pass a value through structs? Im just trying to avoid using a class according programming standards, using class as a replacment for UDTs (structs) is bad practice.

-regards, Lavos and the community.
Online now: No Back to the top

Post

Posted
Rating:
#16
Trainee

Lavos said

cogier said

That helped me. :P

Just use: -

Code (gambas)


not

Code (gambas)

  1. .FileExist = True
Thank you. That makes more sense. I'm still in a habit of coding in vb6. I'm still really trying hard to adapt to gambas way of understanding how it works.<EMOJI seq="1f60e">😎</EMOJI>

Anyway ive read the documentation for structs time and time again because it imo, vague… so im jyst gunna ask, is it possible to pass a value through structs? Im just trying to avoid using a class because according programming standards, using class as a replacment for UDTs (structs) is bad practice.

-regards, Lavos and the community.
Online now: No Back to the top

Post

Posted
Rating:
#17
Avatar
Guru
cogier is in the usergroup ‘Guru’
 I have never used structs as Gambas says in capitals 'DON'T USE STRUCTURES, UNLESS YOU HAVE TO!'

What are you trying to acheive? Pehaps we can find an alternative.
Online now: No Back to the top

Post

Posted
Rating:
#18
Avatar
Regular
Cedron is in the usergroup ‘Regular’
 I've been busy for a little while so I have left this thread alone.

First a general comment for Lavos:  I, too, am a long time VB6 (actually VB3-6) user and I found Gambas at the beginning of the year.  My impression has been very very favorable.  I see Gambas as a big improvement over VB6, sort of like VB done right.  I joke it should have been called "Inc VB" (a word play on C++).

Having said that, there are a few things I would have liked to have been done differently.  Foremost, is the lack of a line continuation character.  I have requested it and it has been deemed too difficult to implement.  I hope this is rectified in the future.  I do find it a little annoying to have to dim all my variables, I would like to see either type declaration characters used (like VB), or a default type of Integer (instead of Single like orginal BASICs).

Those are the major ones.  

Hitting the issues raised in this thread:

I much prefer having "Return (value)" rather than "(function_Name) = (value)" as the way to return values from a call.  It would be nice to be able to return multiple values like Python can, but again, this has been deemed too difficult.  Multiple values can be returned by either ByRef arguments (which are not the default like VB) or returning an object or an array.  Unfortunately, this use of "Return" clashes with the "Return" used for a GoSub.  I would have preferred a different word for the latter, perhaps "GoBack".  The compiler can figure it out, but for readability I think different syntax should have been used.  I am a huge fan of GoSubs and consider them one of the things that makes BASICs superior to other languages.  Inherent readability being another.

The use of user defined structures is discouraged because I believe they make memory manager tougher, not sure about that though.  There is difficulty in matching the packing rules between Gambas definitions and what an underlying language does (like C or FORTRAN external library calls), so structs may not match.  I have never heard that it is poor programming practice to use a class when a struct would do.  I am curious to what the motivation for that might be or where you have heard it.

Out of curiosity, who is your "community"?

Regards,
Ced

.... and carry a big stick!
Online now: No Back to the top

Post

Posted
Rating:
#19
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
 There is a small issue with the Return statement when used with  Try/Catch/Finally Error management.
In this example:

Try {some task}
Return {Result}
Finally
{Do some closing task}
Catch
{Handle Error}

In the case of no error occurring, the Return statement works as required but the Finally statement never triggers leaving any 'final' tasks undone. The Function essentially Quits as soon as the Return statement is met.

When you have error trapping in a Function it is better to do this:

Dim ReturnValue as {Required data Type}
Try {some task}
Return Value = {Result}
Finally
{Do some closing task}
Return ReturnValue
Catch
{Handle Error}

Cheers - Quin.
I code therefore I am
Online now: No Back to the top

Post

Posted
Rating:
#20
Trainee

cogier said

I have never used structs as Gambas says in capitals 'DON'T USE STRUCTURES, UNLESS YOU HAVE TO!'

What are you trying to acheive? Pehaps we can find an alternative.

Yes, that would be nice! I'll be sure to share when I find something out.

Cedron said

I've been busy for a little while so I have left this thread alone.

First a general comment for Lavos:  I, too, am a long time VB6 (actually VB3-6) user and I found Gambas at the beginning of the year.  My impression has been very very favorable.  I see Gambas as a big improvement over VB6, sort of like VB done right.  I joke it should have been called "Inc VB" (a word play on C++).

Having said that, there are a few things I would have liked to have been done differently.  Foremost, is the lack of a line continuation character.  I have requested it and it has been deemed too difficult to implement.  I hope this is rectified in the future.  I do find it a little annoying to have to dim all my variables, I would like to see either type declaration characters used (like VB), or a default type of Integer (instead of Single like orginal BASICs).

Those are the major ones.  

Hitting the issues raised in this thread:

I much prefer having "Return (value)" rather than "(function_Name) = (value)" as the way to return values from a call.  It would be nice to be able to return multiple values like Python can, but again, this has been deemed too difficult.  Multiple values can be returned by either ByRef arguments (which are not the default like VB) or returning an object or an array.  Unfortunately, this use of "Return" clashes with the "Return" used for a GoSub.  I would have preferred a different word for the latter, perhaps "GoBack".  The compiler can figure it out, but for readability I think different syntax should have been used.  I am a huge fan of GoSubs and consider them one of the things that makes BASICs superior to other languages.  Inherent readability being another.

The use of user defined structures is discouraged because I believe they make memory manager tougher, not sure about that though.  There is difficulty in matching the packing rules between Gambas definitions and what an underlying language does (like C or FORTRAN external library calls), so structs may not match.  I have never heard that it is poor programming practice to use a class when a struct would do.  I am curious to what the motivation for that might be or where you have heard it.

Out of curiosity, who is your "community"?

Regards,
Ced

I'm relieved to see a fellow VB user on this forum, I can relate to your experiences and somewhat understand your opinions of comparing Gambas and VB. To answer your curiosity, people on other programming communities explain tests being done with comparing UDTs vs Classes, UDTs speeds are faster than using Class declarations according to my research from other forums, Jonathan S. Harbour said the same things with his books a while back, I forget which one was that though.

The community? I speak for those who are trying for an alternative to VB, the ones who are transitioning from Microsoft Windows to Linux. It seems like Gambas might be the answer.
Visit me in on my community "here"

Quincunxian said

There is a small issue with the Return statement when used with  Try/Catch/Finally Error management.
In this example:

Try {some task}
Return {Result}
Finally
{Do some closing task}
Catch
{Handle Error}

In the case of no error occurring, the Return statement works as required but the Finally statement never triggers leaving any 'final' tasks undone. The Function essentially Quits as soon as the Return statement is met.

When you have error trapping in a Function it is better to do this:

Dim ReturnValue as {Required data Type}
Try {some task}
Return Value = {Result}
Finally
{Do some closing task}
Return ReturnValue
Catch
{Handle Error}

Thanks for sharing, I'll get right into playing around with this reference.
Online now: No Back to the top

Post

Posted
Rating:
#21
Trainee

Lavos said

cogier said

I have never used structs as Gambas says in capitals 'DON'T USE STRUCTURES, UNLESS YOU HAVE TO!'

What are you trying to acheive? Pehaps we can find an alternative.

Yes, that would be nice! I'll be sure to share when I find something out.

Cedron said

I've been busy for a little while so I have left this thread alone.

First a general comment for Lavos:  I, too, am a long time VB6 (actually VB3-6) user and I found Gambas at the beginning of the year.  My impression has been very very favorable.  I see Gambas as a big improvement over VB6, sort of like VB done right.  I joke it should have been called "Inc VB" (a word play on C++).

Having said that, there are a few things I would have liked to have been done differently.  Foremost, is the lack of a line continuation character.  I have requested it and it has been deemed too difficult to implement.  I hope this is rectified in the future.  I do find it a little annoying to have to dim all my variables, I would like to see either type declaration characters used (like VB), or a default type of Integer (instead of Single like orginal BASICs).

Those are the major ones.  

Hitting the issues raised in this thread:

I much prefer having "Return (value)" rather than "(function_Name) = (value)" as the way to return values from a call.  It would be nice to be able to return multiple values like Python can, but again, this has been deemed too difficult.  Multiple values can be returned by either ByRef arguments (which are not the default like VB) or returning an object or an array.  Unfortunately, this use of "Return" clashes with the "Return" used for a GoSub.  I would have preferred a different word for the latter, perhaps "GoBack".  The compiler can figure it out, but for readability I think different syntax should have been used.  I am a huge fan of GoSubs and consider them one of the things that makes BASICs superior to other languages.  Inherent readability being another.

The use of user defined structures is discouraged because I believe they make memory manager tougher, not sure about that though.  There is difficulty in matching the packing rules between Gambas definitions and what an underlying language does (like C or FORTRAN external library calls), so structs may not match.  I have never heard that it is poor programming practice to use a class when a struct would do.  I am curious to what the motivation for that might be or where you have heard it.

Out of curiosity, who is your "community"?

Regards,
Ced

I'm relieved to see a fellow VB user on this forum, I can relate to your experiences and somewhat understand your opinions of comparing Gambas and VB. To answer your curiosity, people on other programming communities explain tests being done with comparing UDTs vs Classes, UDTs speeds are faster than using Class declarations according to my research from other forums, Jonathan S. Harbour said the same things with his books a while back, I forget which one was that though.

The community? I speak for those who are trying for an alternative to VB, the ones who are transitioning from Microsoft Windows to Linux. It seems like Gambas might be the answer.
Visit me in on my community "here"

Quincunxian said

There is a small issue with the Return statement when used with  Try/Catch/Finally Error management.
In this example:

Try {some task}
Return {Result}
Finally
{Do some closing task}
Catch
{Handle Error}

In the case of no error occurring, the Return statement works as required but the Finally statement never triggers leaving any 'final' tasks undone. The Function essentially Quits as soon as the Return statement is met.

When you have error trapping in a Function it is better to do this:

Dim ReturnValue as {Required data Type}
Try {some task}
Return Value = {Result}
Finally
{Do some closing task}
Return ReturnValue
Catch
{Handle Error}

Thanks for sharing, I'll get right into playing around with this reference.


I wonder if there is a community-driven documentation for Gambas, some parts of it are so vague but i read it over and over again hoping i get something out of it… :(
Online now: No Back to the top

Post

Posted
Rating:
#22
Avatar
Regular
Cedron is in the usergroup ‘Regular’

Lavos said

I'm relieved to see a fellow VB user on this forum, I can relate to your experiences and somewhat understand your opinions of comparing Gambas and VB. To answer your curiosity, people on other programming communities explain tests being done with comparing UDTs vs Classes, UDTs speeds are faster than using Class declarations according to my research from other forums, Jonathan S. Harbour said the same things with his books a while back, I forget which one was that though.

The community? I speak for those who are trying for an alternative to VB, the ones who are transitioning from Microsoft Windows to Linux. It seems like Gambas might be the answer.
Visit me in on my community "here"

Hmmmmmmmmm, classes being slower than UDTs has to be a platform/language specific thing.  In theory, and in practice in many places, a class is simply a structure with an associated set of routines and the address of the instance implicitly passed as the first parameter.  You can do it explicitly if you like, and I have many times, including recently when C was specified and C++ not allowed.

If you are looking for speed alone, Gambas is not the answer.  It is is a byte code interpreter (like Python, Java, VB1-3, and optional in VB4).  However, it is very easy to call shared libraries from Gambas which makes up for this.  I have posted many examples of shared libraries in this forum, you may want to look at those.

I took a look at your community.  I couldn't find any "About Eclipse Engine" to explain what it is about.  My first thought was it had to do with the Eclipse IDE, but that does not appear to be the case.  It looks like a game developers forum of some type.

If you are interested in using Gambas for game development, you might want to look at this thread:

Gambas One - Gambas ONE

I also have a shared library for accessing gamepads that I have not posted yet.

Ced

.... and carry a big stick!
Online now: No Back to the top

Post

Posted
Rating:
#23
Trainee
So I looked into this: /comp/gb.settings/settings - Gambas Documentation and this seems like it could only handle form Objects… It's probably obvious for you guys where I'm trying to achieve here(Creating a database for the application to access files when needed.) So starting off, I'm trying to figure out how to create a .ini or .conf file to preset options to save for the user. Perfect reference is getprivateProfileString from windows if that makes any sense to you. I've never worked with XML before but it seems like it might be an alternative, any code examples of that would help.

I'm on a windows machine when i posted this, so any request of posting codes, i'd be happy too when i get to my linux machine.

-Regards, Lavos
Online now: No Back to the top
1 guest and 0 members have just viewed this.