View Full Version : skip several lines of unnecessary code in thinBASIC
Edcronos
17-01-2017, 11:49
hi
I'm a little lost as I skip several lines of unnecessary code in thinBASIC
in vba:
If T(a) Then _
If Not tem_valor(vq(a), v(a), Array_O, l + ll(a)) Then GoTo pula
If T(b) Then _
If Not tem_valor(vq(b), v(b), Array_O, l + ll(b)) Then GoTo pula
If T(c) Then _
If Not tem_valor(vq(c), v(c), Array_O, l + ll(c)) Then GoTo pula
For c2 = 1 To Cf1
If T(1) Then CoL_De(L_d, c2) = Array_O(l - 1, c2): L_d = L_d + 1
If T(2) Then CoL_De(L_d, c2) = Array_O(l, c2): L_d = L_d + 1
If T(3) Then CoL_De(L_d, c2) = Array_O(l + 1, c2): L_d = L_d + 1
Next
L_d = L_d + 1
pula:
Next
I know I can create a check variable
But is there a more practical way?
ReneMiner
17-01-2017, 17:01
For some good reasons there's no Goto in thinBasic, if you want to skip Iteration in For-Next loop there are several ways.
You may check for a condition using
For var = start To end When {condition}
Or you can skip code using:
If {condition} Then Iterate ...
Check thinBasic-help and code-examples how to use
Edcronos
17-01-2017, 18:05
Hi
In this case I already have several checks inside an extended loop
The only solution I see in my case is a lot of more checking inside a huge loop where what I'm looking for is execution speed
tt = True
If t(a) = True Then
If tem_valor(vq(a), v(a), Array_O, l + ll(a)) = False Then
tt = False
End If
End If
If t(b) = True And tt = True Then
If tem_valor(vq(b), v(b), Array_O, l + ll(b)) = False Then
tt = False
End If
End If
If t(c) = True And tt = True Then
If tem_valor(vq(c), v(c), Array_O, l + ll(c)) = False Then
tt = False
End If
End If
...
If tt = True Then
For c2 = 1 To Cf1
If t(1) Then CoL_De(L_d, c2) = Array_O(l - 1, c2): L_d = L_d + 1
If t(2) Then CoL_De(L_d, c2) = Array_O(l, c2): L_d = L_d + 1
If t(3) Then CoL_De(L_d, c2) = Array_O(l + 1, c2): L_d = L_d + 1
Next
L_d = L_d + 1
End If
Next
I am not a professional programmer, and I have limitations on remembering things,
Like names of functions, variables, so I always end up doing my own and I end up using short variables "which is also something highly reprimanded"
I do not see how this can be so scary in a few lines of code
Do knives kill people, or do people kill people?
Should the knives be abolished?
Will Goto have already destroyed some super computer, invaded systems, made a bug code?
But ok I will not discuss
I'll find another solution for me.
bye
Michael Hartlef
20-01-2017, 09:05
@EdCronos: With Exit you can exit a FOR loop and continue after the Next statement. Iterate returns to the FOR statement to continue the iteration.
Edcronos
20-01-2017, 12:06
11/5000
Hi
Thank you
In this case it is not just a question of getting out of the fuction
Would be like avoiding additional tests in an "AND"
Function And(test1, test2, test3, ...)
If test1 = false then function And = false: exit function
If test2 = false then function And = false: exit function
If test3 = false then function And = false: exit function
function And = true
End function
Or an "OR"
Function Or(test1, test2, test3, ...)
If test1 = true then function OR = true: exit function
If test2 = true then function OR = true: exit function
If test3 = true then function OR = true: exit function
function OR = false
End function
Are for testing and arrays filters
Must have a way to do this more easily, but I am limited by my own ability
Although I am inexperienced in programming, I see that programmers are more concerned with imposing their own concepts than trying to set a minimum standard in all these languages
How many languages are there?
How many types of syntax?
In the end all have to convert to machine language
But anyway I think I'll have to continue on the same vba,
This is why I ran into other issues,
And get relearning and breaking the head, just to play to assemble small functions that end up dropping aside
I have tried to look at Oxygen Basic but I have not been able to define an initial operation, mainly for the question of Byref multimimensional arrays and variant type
I wonder when they will abolish the "if then else" as well
This is because the goto and gosub complaint is that it leaves the code confusing
But if in a few line function this is impossible
With the "if then else" is able to leave it almost like a puzzle
If Col_Array2 > 0 Or Col_fim_Array2 > 0 Then
If Col_Array2 > 0 Then Cx = Col_Array2 Else Cx = Col_fim_Array2
If Col_Array2 = 0 Or Col_fim_Array2 = 0 Then
For c = 1 To m
If Matriz_1(c) = array2(Linha_array2, Cx) Then tem_valor = True: Exit Function
Next
Exit Function
Else
If Col_Array2 = 0 Then Col_Array2 = 1
If Col_Array2 <> Col_fim_Array2 Then
If Col_Array2 > Col_fim_Array2 Then
d = -1: dm = Col_Array2: mx = Col_Array2 - Col_fim_Array2
Else
d = 1: dm = Col_fim_Array2: mx = Col_fim_Array2 - Col_Array2
End If
c1 = Col_Array2: c2 = Col_fim_Array2
End If
End If
End If
If m < mx Then mx = m
Oi
nesse caso não é apenas questão de sair da função
seria como evitar testes adicionais em uma função "AND"
são para teste e filtros de arrays
deve ter uma maneira de fazer isso mais facilmente, mas eu sou limitado por minha própria capacidade
apesar de eu ser inexperiente em questão de programação,eu vejo que os programadores estão mais preocupados em impor seus próprios conceitos do que tentar definir um padrão mínimo em todas essas linguagens
quantas linguagens existem?
quantos tipos de sintaxe ?
no final todas tem que converter para linguagem de maquina
mas de qualquer forma acho que vou ter que continuar no vba mesmo,
isso por que esbarrei em outras questões,
e ficar reaprendendo e quebrando a cabeça, apenas para brincar de montar pequenas funções que no final acabam largadas de lado
tentei olhar o Oxygen Basic mas também não consegui definir um funcionamento inicial, principalmente para a questão dos arrays multdimencionas Byref e tipo variant
Fico imaginando quando vão abolir o "if then else" tambem
isso porque a reclamação do goto e gosub é que deixa o codigo confuso
mas se em uma função de poucas linha isso é impossivel
com o "if then else" é capaz de deixar lo quase como um quebra cabeça
Michael Hartlef
21-01-2017, 12:28
Rene showed you how to avoid the checking by using Iterate in your first example. Or did you ment something else?
Edcronos
22-01-2017, 02:39
Unfortunately I could not find a practical example of "Iterate"
But I can not help crying about my own lack of capacity
When I tried C ++ I even managed to locate myself, but I did not adapt to the "{}"
For me it was difficult to keep track of where in the code I was
When I tried another platform focused on the basic I did not expect so much discrepancy in the base, I just expected different extra capabilities
I basically use only FOR NEXT, IF THEN, ELSE, and ARRAYS, and even for those simple things I struggle with defining a functional code by the differences of declaring the variables and returning values outside the constraints of requirements in the lines of code
The vba until you answer me for the things I like to put together, I just wanted to carry some things I did for dll's to make it easier to use in the different experiments
One of them would be a macro that reallocates array data by parameters
But without stress for my limitations and without needing so much capacity the ideal is to continue where I am
Thank you for your attention.
infelizmente não consegui achar um exemplo pratico sobre "Iterate"
mas não adianta eu ficar chorando sobre minha propria falta de capacidade
quando eu tentei o C++ eu até consegui me situar , mas não me adaptei aos "{}"
para mim ficava dificil acompanhar em que parte do codigo eu estava
quando eu tentei outra plataforma enfocada no basic eu não esperava tanta discrepacia na base, esperava apenas capacidades extras diferentes
eu basicamente uso apenas FOR NEXT, IF THEN ELSE, e ARRAYS e mesmo para essas coisas tão simples enfrento dificuldades para definir um codigo funcional pelas diferenças de declarar as variaveis e retonar valores fora as difereças de exigencias nas linhas de codigo
o vba até que me atende para as coisas que eu gosto de montar, eu apenas queria portar algumas coisas que eu fiz para dll´s para ficar mais facil usar nos diferentes experimentos
uma delas seria uma macro que realoca dados de array por parametros
mas sem stress para minhas limitações e sem necessidade de tanta capacidade o ideal é continuar onde estou
mesmo assim obrigado pela atenção
Petr Schreiber
22-01-2017, 17:28
Edcronos,
let me help you. The advice given in this thread is a good one. For your case, this would be the way to jump to the nearest NEXT:
If T(a) Then _
If Not tem_valor(vq(a), v(a), Array_O, l + ll(a)) Then iterate for
If T(b) Then _
If Not tem_valor(vq(b), v(b), Array_O, l + ll(b)) Then iterate for
If T(c) Then _
If Not tem_valor(vq(c), v(c), Array_O, l + ll(c)) Then iterate for
If it is still too confusing, let me show you on this example:
uses "console"
long flagField(8) = 1, 1, 1, 0, 0, 1, 0, 1
long i
for i = 1 to 8
if flagField(i) = 0 then iterate for ' -- Skip flags which are not set, by moving on to the next iteration (which equals GOTO to label right before NEXT)
printl strformat$("Flag {1} is set", i)
next
waitkey
And this is even more ellegant, as adviced by Rene:
uses "console"
long flagField(8) = 1, 1, 1, 0, 0, 1, 0, 1
long i
for i = 1 to 8 when not flagField(i) = 0
printl strformat$("Flag {1} is set", i)
next
waitkey
Last but not least: There is a nice example on Iterate in the help file. How to reach it? Just open your script in ThinAIR, put cursor on the word Iterate and press F1. There is a context sensitive help system ready for you.
Petr
Edcronos
22-01-2017, 22:50
Sorry, maybe I'm too stupid, but for me it got a bit confusing as to how to apply it the way I want it
I did not understand, how to include sets of totally different conditions in this "Iterate"
If at least it had an assembly structure, with an output and input switch
For n = 1 to 1000
Set switch (primario)
Switch (1,5) ON
End switch
Set switch (segundario)
Switch (2,3,4) ON
End switch
Set switch (1)
If false then switch (1,3) off "exits the switch instruction set and switches off the execution of swtch(3)
...
End switch
...
Set switch (2)
If true then switch (2) off,
for nn to
If ten(nn)=false then switch (2,4) off,
next
If false then switch (2,4) off,
End switch
Set switch (3)
If false then switch (3,primario) off:
Print
End switch
...
...
Next
Well it's just an idea of how to have controlled execution blocks
ThinBASIC includes an embedded Basic called Oxygen, Oxygen supports goto and gosub, see the sample scripts in the Oxygen folder
I think the label must be a number.
Petr Schreiber
23-01-2017, 16:37
Edcronos,
for case like the one you demonstrated I would recommend to go more highlevel by adopting use of state machine engine for your problem.
It is a common practice in the automation industry.
It would be worth some time to research and develop a state machine engine - sure doable in ThinBASIC!
For more read: https://en.wikipedia.org/wiki/Finite-state_machine
Petr
Edcronos
23-01-2017, 22:08
Then you are wanting someone who only knows how to use "if then else, for next, variables and jumps" to do what you want, design a rocket
To tell you the truth, I'm not calling goto anymore.
Even without it, and even more complex, I could do things
My discouragement now, is about the lack of a minimum standard, and the lack of portability of the codes among the many basics created there
The strength of the other languages is not about the ability of the syntax but rather about the standard, basically only if you change ide and if you add optional functions
Like, C ++ that has a basic syntax and simple functions, but if you add capability and functions through #include
If a simple function that only has some variables, a "for" loop, a few if's does not work from one basic to another, what about more complex implementations?
What destroys language is not goto and gosub, it is not the ease of learning
It is rather the lack of firm foundations,
The engineers, instead of making small reforms, are knocking down what has ready and built everything again,
If the structure of the house is weak, have to play the furniture and everything else that was built in the house outside why not fit in another
aí voce está querendo que alguem que só sabe usar " if then else, for next, variaveis e saltos" para fazer o que quer , projete um foguete
para falar a verdade nem estou mais ligando para o goto
mesmo sem ele , e mesmo sobre uma maior complexidade, eu conseguiria fazer as coisas
meu desanimo agora, é sobre a falta de um padrão minimo, e a falta de portabilidade dos codigos entre os tantos basics criados por aí
a força das outras linguagens não é sobre capacidade da sintaxe e sim sobre o padrão, basicamente só se troca de ide e se adiciona funções opcionais
como, o C++ que tem um sintaxe basica e funções simples, mas se adiciona capacidade e funções através do #include
se uma simples função que só tem algumas variaveis, um laço "for" , alguns poucos if´s não funciona de um basic para outro, oque se pode falar de implementações mais complexas?
o que destrói a linguagem não é o goto e o gosub, não é a facilidade de aprendizagem
é sim a falta de alicerces firmes ,
os engenheiros, em vez de faz de pequenas reformas, ficam derrubando o que tem pronto e construido tudo novamente,
se a estrutura da casa se mostra fraca, tem que jogar os moveis e tudo mais que se construiu na casa fora por que não cabe em outra
Petr Schreiber
24-01-2017, 21:06
I get your point, Edcronos. And believe me or not, this fact was part of my motivation to start working on ThinBASIC interpreter.
I loved PowerBASIC at the time, and there was no other BASIC like that. Frustrating!
So... I feel your pain.
To be fair - C++ code portability is also discutable, I am afraid. Just reading through C++ Primer, Fifth Edition, you will find many notes regarding oddities even at the most basic level - the data types.
There is standard of C++, but again, there are no complete implementations. Just look at what Microsoft says about his C++ compiler:
https://blogs.msdn.microsoft.com/vcblog/2014/11/17/c111417-features-in-vs-2015-preview/
(older link, but more can be found if you have time for google run).
Initiating a movement for 21st century BASIC standard is sure very tempting! ...And incredibly challenging task at the same time :)
Petr
Edcronos
24-01-2017, 22:53
I understand that it is not 100%
But it's more than basic
I can quote points that I found
Functionname = value
Function = value
Return value
----------------------
Sub namesub()
Sub namesub
Without sub
--------------------
Long A
A As Long
Double
Long Long
variant
Do not have variant
---------------------------
Array (L, C)
Array [L] [C]
-------------------------
Base 0
Base 1
----------------------
$Let
Let
-----------------
Among many others
From there you can have real compilers and interpreters
======================================================
At least one could create a site where the staff could vote the basic characteristics of BASIC
And implementers would decide whether to follow the most voted pattern or not
Or at least if you had an opposite opinion leave an optional
I was even tempted to create a group on the face,
https://www.facebook.com/Programming-in-BASIC-768714663280647/
But let's face it
I do not know English,
This is necessary to reach the programmers of greater performance and importance in the generation of opinions
I'm not a programmer,
Would not know how to cover the most important points
And I do not even know how to use it in groups and I do not like the face
Among other things
Edcronos
25-01-2017, 06:11
About state machine until I found some codes and explanations
public class Lamp : StateMachine
{
// Triggers (or events, or actions, whatever) that our
// state machine understands.
[Trigger]
public readonly Action PressSwitch;
[Trigger]
public readonly Action GotError;
// Actual state machine logic
protected override IEnumerable WalkStates()
{
off:
Console.WriteLine("off.");
yield return null;
if (Trigger == PressSwitch) goto on;
InvalidTrigger();
on:
Console.WriteLine("*shiiine!*");
yield return null;
if (Trigger == GotError) goto error;
if (Trigger == PressSwitch) goto off;
InvalidTrigger();
error:
Console.WriteLine("-err-");
yield return null;
if (Trigger == PressSwitch) goto off;
InvalidTrigger();
}
}
But honestly I did not understand how to apply this in this situation of execution blocks
It would be simpler to create functions with passages of the parameters by reference
With the conditional goto would be something like
If Primary_key(1) = "on" Then
If Key(1) = "on" Then
If test1 Then
For n = 1 To k
If matriz(n) = "pronto" Then
Key(n) = off:
GoTo Key_1
End If
Next
GoTo Primary_key1 'off
End If
If inversion_keys Then
For n = 1 To UBound(Key)
If Key(n) = off Then Key(n) = "on" Else Key(n) = off
Next
GoTo Primary_key1 'off
End If
Key_1: 'off
End If
If Key(2) = "on" Then
If test1 Then
For n = 1 To k
If matriz(n) = False Then GoTo Key_2
Next
End If
If x Then Call f
If y Then Call g
Key_2:'off
End If
If Key(3) = "on" Then
If Key(4) = "on" Then
Primary_key1:'off
End If 'Primary_key1
If Primary_key(2) = "on" Then
At least I find something simple and logical, of course a native instruction already encapsulated would be much better