I'm sorry, I know this must be clearly obvious but I'm really not seeing it at the moment. I have the following test code and this is the only thing I seem to be tripping up on:
entry$="Joanne"
For i = 1 To 5
entry$.b = entry$.b + 1
Debug entry$
Debug entry$.b
Next
entry$="Peter"
For i = 1 To 5
entry$.b = entry$.b + 1
Debug entry$
Debug entry$.b
Next
If you run that you'll see the name and variable count. Now, why is Peter continuing Joanne's count? Isn't this supposed to create a new variable called "entry$.b" - which is really "peter.b"?
entry$ and entry$.b are totaly different variables. the first is a string
(i prefer suffix .s for string instead of $ ), the other is a byte-variable with the name entry$
Summers wrote:I'm sorry, I'm just not following. If I do:
entry$="joe"
then
entry$.b
Then the variable is automatically named joe.b ?
entry$ and entry$.b are totaly different variables. the first is a string
, the other is a byte-variable with the name entry$ It have nothing to do with a Bytefield (Charfield) like in C-languages
Then how do I get a variable to automatically name itself joanne.b, using the above string variable..? The value of entry$ is going to change several times in one routine.
Have you been doing PHP/Python/Etc lately? PB (and most or BASIC's) is not not like these scripting languages. As powerful as they are they are no way as quick as PB. One of the things you cannot do is declare variables dynamically in this fashion. So if you want "joanne.b" you have to declare it as such.
Say I have var1.s with contents of "peter". I want to create a second variable called "peter.b" using the contents of var1.s. I am reading everyone's replies, but no-one seems to have answered this, or any possible workaround.
Summers wrote:Say I have var1.s with contents of "peter". I want to create a second variable called "peter.b" using the contents of var1.s. I am reading everyone's replies, but no-one seems to have answered this, or any possible workaround.
var1.s="Peter"
Peter.s=var1
debug var1
debug peter
Summers wrote:Say I have var1.s with contents of "peter". I want to create a second variable called "peter.b" using the contents of var1.s. I am reading everyone's replies, but no-one seems to have answered this, or any possible workaround.
dmoc was very clear:
You can't!
I suggest to find another solution using arrays and/or linked lists...
What you're asking for is simply not possible in PureBasic, the compiler doesn't support this kind of variable definition. That's why you're not getting any answers to your problem. As far as i know there's no easy trick to work around this, you have to create some sort of framework for this yourself at the moment if you really want this feature... Maybe you could make some sort of associative array to simulate this behaviour?
There are two main types of language: Compiled and Interpreted.
PHP, Python, Perl, Ruby. These are all interpreted. Iterpreted languages are slower, but very expressive. You can do thing like create dynamic variables, which is what you are doing.
PureBasic, like C++ or Delphi, is Compiled. The source code is compiled into a binary executable consisting of machine code instructions. These are instructions that can be directly executed by the processor, so they run much faster.
Another point is that in PB a variables type is declared by appending a type identifier to the end of the variables first mention.
var1.b is equivalent to char var1 in c or java.
This is a very efficient way of doing it, much less typing. However, it is a little confusing if your used to the dot being used for objects members.
Thanks for the replies, peoples and for having patience to deal with my daft questions I'm now studying arrays and will go that way - once I figure it all out