Conversion from ca-clipper ( not found a variable)

Conversion from ca-clipper ( not found a variable)

Postby Silvio.Falconi » Tue Mar 01, 2022 11:04 am

I have this error

Error description: Error BASE/1003 Variabile inesistente: C1

on the source

numeri:= 9
combinaz:= 10
scelta:= "2"
c1:= "102030405060708090"
c2:= "011121314151617181"
c3:= "021222324252627282"
c4:= "031323334353637383"
c5:= "041424344454647484"
c6:= "051525354555657585"
c7:= "061626364656667686"
c8:= "071727374757677787"
c9:= "081828384858687888"
c10:= "091929394959697989"


contacomb:= 1
do while (contacomb <= combinaz)
c:= "C" + LTrim(Str(contacomb))
cnum:= LTrim(Trim(&c)) <----------------- give me error here not found c1
conta:= 1
do while (conta <= Len(cnum) / 2)
num:= "N" + LTrim(Str(conta))
&num:= SubStr(cnum, conta * 2 - 1, 2)
if (SubStr(&num, 1, 1) = "0")
&num:= SubStr(&num, 2, 1)
endif
conta:= conta + 1
enddo



How I can resolve ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: Conversion from ca-clipper ( not found a variable)

Postby karinha » Tue Mar 01, 2022 12:43 pm

Code: Select all  Expand view

// \SAMPLES\SILCONV.PRG - MODIFIED By Joao Santos. 01/03/2022.
// Compilado con: HARBOUR y xHARBOUR. BCC74.

#include "FiveWin.ch"

MEMVAR c1, c2, c3, c4, c5, c6, c7, c8, c9, c10

FUNCTION SILCONV()

   LOCAL numeri    := 9
   LOCAL combinaz  := 10
   LOCAL scelta    := "2"
   LOCAL contacomb := 1
   LOCAL c, cNum, Conta, Num

   c1  := "102030405060708090"
   c2  := "011121314151617181"
   c3  := "021222324252627282"
   c4  := "031323334353637383"
   c5  := "041424344454647484"
   c6  := "051525354555657585"
   c7  := "061626364656667686"
   c8  := "071727374757677787"
   c9  := "081828384858687888"
   c10 := "091929394959697989"

   WHILE( contacomb <= combinaz )

      SYSREFRESH()

      IF contacomb >= combinaz

         EXIT

      ENDIF

      c := "C" + LTrim( Str( contacomb ) )

      cnum := LTrim( Trim( &c ) ) // < give me error here not found c1

      ? cnum  // perfecto

      conta := 1

      WHILE( conta <= Len( cnum ) / 2 )

         SYSREFRESH()

         num  := "N" + LTrim( Str( conta ) )

         &num := SubStr( cnum, conta * 2 - 1, 2 )

         IF ( SubStr( &num, 1, 1 ) = "0" )

            &num := SubStr( &num, 2, 1 )

         ENDIF

         // No comprendo bien, mas funciona perfecto.
         // ? "Line 58/60: ", &num  // numeros aleatorios.

         conta := conta + 1

      ENDDO

      contacomb := contacomb + 1  // Incremental number. perfectoÿ

   ENDDO

RETURN NIL

// fin / end
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7824
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Conversion from ca-clipper ( not found a variable)

Postby Silvio.Falconi » Tue Mar 01, 2022 5:48 pm

I not understood, where is the error, on ca-clipper it was ok

the c1,c2... are not memvar but local and each combination have different C(n) there is one have until C45

I not understood why you must change my code allways
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: Conversion from ca-clipper ( not found a variable)

Postby karinha » Wed Mar 02, 2022 12:47 pm

Silvio, lo que debes entender es que en CLIPPER, HARBOUR o xHARBOUR, siempre tienes varias formas diferentes de hacer lo mismo. El COMPILADOR te permite ser ilimitado. Cada uno tiene su forma de programar, utiliza siempre el modo de programación que más te guste.

Silvio, what you need to understand is that in CLIPPER, HARBOUR or xHARBOUR, you always have several different ways of doing the same thing. The COMPILER allows you to be unlimited. Each one has its way of programming, always use the programming mode that you like the most.

Code: Select all  Expand view

// \SAMPLES\SILCONV2.PRG - MODIFIED By Joao Santos. 02/03/2022.
// Compilado con: HARBOUR y xHARBOUR Para: BCC74.

#include "FiveWin.ch"

FUNCTION SILCONV()

   LOCAL numeri    := 9
   LOCAL combinaz  := 10
   LOCAL scelta    := "2"
   LOCAL contacomb := 1
   LOCAL c, cNum, Conta, Num

   // COMMAND COMBINATION -> Distintas formas de hacer lo mismo.
   // Puede comentar con // y el compilador asumirá que las VARIABLES son MEMVAR.
   MEMVAR  c1, c2, c3, c4, c5, c6, c7, c8, c9, c10
   PRIVATE c1, c2, c3, c4, c5, c6, c7, c8, c9, c10

   c1  := "102030405060708090"
   c2  := "011121314151617181"
   c3  := "021222324252627282"
   c4  := "031323334353637383"
   c5  := "041424344454647484"
   c6  := "051525354555657585"
   c7  := "061626364656667686"
   c8  := "071727374757677787"
   c9  := "081828384858687888"
   c10 := "091929394959697989"

   WHILE( contacomb <= combinaz )

      SYSREFRESH()

      IF contacomb >= combinaz

         EXIT

      ENDIF

      c := "C" + LTrim( Str( contacomb ) )

      cnum := LTrim( Trim( &c ) ) // < give me error here not found c1

      ? cnum  // perfecto

      conta := 1

      WHILE( conta <= Len( cnum ) / 2 )

         SYSREFRESH()

         num  := "N" + LTrim( Str( conta ) )

         &num := SubStr( cnum, conta * 2 - 1, 2 )

         IF ( SubStr( &num, 1, 1 ) = "0" )

            &num := SubStr( &num, 2, 1 )

         ENDIF

         // No comprendo bien, mas funciona perfecto.
         // ? "Line 60/63: ", &num  // numeros aleatorios.

         conta := conta + 1

      ENDDO

      contacomb := contacomb + 1  // Incremental number. perfectoÿ

   ENDDO

RETURN NIL

// fin / end
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7824
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Conversion from ca-clipper ( not found a variable)

Postby Silvio.Falconi » Wed Mar 02, 2022 1:11 pm

Now The function run I insert Memvar but

the experts of fwh / harbor / clipper have always recommended me not to use the memvar and then in the old source of ca-clipper they are local

Image

problems:

1) first column I must divide the string into type XX.XX.XX.XX. how I can make ?
2) the other columns are -1 because are not calculate how I can make to show none ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: Conversion from ca-clipper ( not found a variable)

Postby karinha » Wed Mar 02, 2022 1:46 pm

the experts of fwh / harbor / clipper have always recommended me not to use the memvar and then in the old source of ca-clipper they are local


Esta información es incorrecta. Puede DECLARAR las variables a voluntad.

LOCAL // usar a voluntad
GLOBAL // usar con moderación
MEMVAR // usar a voluntad
PRIVATE // úselo a voluntad, pero no lo use dentro de LOOPINGS, puede explotar la RAM
PÚBLIC // Usar con moderación.

Desafío a cualquier EXPERTO a que demuestre que estoy equivocado. De lo contrario, mi profesor CLIPPER 5.3 va a recibir una paliza. jajajajajajaja.


This information is incorrect. You can DECLARE the variables at will.

LOCAL // use at will
GLOBAL // use sparingly
MEMVAR // use at will
PRIVATE // use it at will, just don't use it inside LOOPINGS, it can explode RAM
PUBLIC // Use sparingly.

I challenge any EXPERT to prove me wrong. Otherwise, my CLIPPER 5.3 teacher is going to take a beating. jajajajajajaja.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7824
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Conversion from ca-clipper ( not found a variable)

Postby karinha » Wed Mar 02, 2022 1:49 pm

1) first column I must divide the string into type XX.XX.XX.XX. how I can make ?
2) the other columns are -1 because are not calculate how I can make to show none ?



muéstranos un ejemplo práctico de cómo lo estás haciendo, no tengo idea de lo que quieres.

show us a practical example of how you are doing it, i have no idea what you want.

Code: Select all  Expand view

      // ? VAL( CNUM )

      cValcNum := VAL( CNUM )

      ? TRANSF( cValcNum, "99-99-99-99-99-99-99-99-99" )
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7824
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Conversion from ca-clipper ( not found a variable)

Postby Enrico Maria Giordano » Wed Mar 02, 2022 8:38 pm

Any variable that is not local must be only used when really necessary (ie. in very rare occasions). The reason is simple: non-local variables break the encapsulation principle so their values are more difficult to trace.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Conversion from ca-clipper ( not found a variable)

Postby karinha » Wed Mar 02, 2022 9:32 pm

Enrico Maria Giordano wrote:Any variable that is not local must be only used when really necessary (ie. in very rare occasions). The reason is simple: non-local variables break the encapsulation principle so their values are more difficult to trace.

EMG


Master Enrico, I respect your opinion, but I think it has no basis. In which Clipper book or manual did you see this?

Here at this link, you have the Clipper 5.3 manual: Rare exceptions, xHarbour follows the same logic, that's why I like xHarbour better.

https://harbour.github.io/doc/clc53.html#memvar-cmd

I always followed the instructions in manuals and books that adopted the CA-CLIPPER syntax. I've never had problems, I always DECLARE: FIELD, LOCAL, MEMVAR, PRIVATE (I don't use it much) I prefer MEMVAR in Combination with PRIVATE, of course, I don't make excessive use of PRIVATES and PUBLIC, I use it only in exceptional cases. The only one that I'm not used to using, because I don't understand how it works, is GLOBAL.

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7824
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Conversion from ca-clipper ( not found a variable)

Postby karinha » Wed Mar 02, 2022 9:37 pm

Master Enrico:

That's how I learned to program in CLIPPER 5.3, and I never had any problems with users, nor a stack overflow or a program breaking, saying that the "VARIABLE DOESN'T EXIST!". A poorly written program is a bad program that sooner or later will generate problems for the user.

Code: Select all  Expand view

■  This example demonstrates the relationship between a private
   and field variable with the same name.  The private variable is
   declared with the MEMVAR statement:

   FUNCTION Example
      MEMVAR amount, address
      PRIVATE amount := 100
      USE Customer NEW
      //
      ? amount                // Refers to amount private variable
      ? Customer->Amount      // Refers to Amount field variable
      //
      RETURN NIL
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7824
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Conversion from ca-clipper ( not found a variable)

Postby Enrico Maria Giordano » Wed Mar 02, 2022 10:07 pm

Encapsulation is not a concept tied to a particular programming language. It is a good programming principle that is useful to build and maintain a clean project structure. You can learn about it reading any programming theory book.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Conversion from ca-clipper ( not found a variable)

Postby Silvio.Falconi » Thu Mar 03, 2022 9:50 am

karinha wrote:
1) first column I must divide the string into type XX.XX.XX.XX. how I can make ?
2) the other columns are -1 because are not calculate how I can make to show none ?



muéstranos un ejemplo práctico de cómo lo estás haciendo, no tengo idea de lo que quieres.

show us a practical example of how you are doing it, i have no idea what you want.

Code: Select all  Expand view

      // ? VAL( CNUM )

      cValcNum := VAL( CNUM )

      ? TRANSF( cValcNum, "99-99-99-99-99-99-99-99-99" )
 


Regards, saludos.



ahhahaaahahahahahahaahaahhaahahahahaha, you're are Joke :)

I cannot use your transform TRANSF( cValcNum, "99-99-99-99-99-99-99-99-99" )


Image


But I made a easy function because I not Know the len of the string


Code: Select all  Expand view


#include "fivewin.ch"
Function Main ()
? ConvertString("019002894546")

return nil
Function ConvertString(cnum)
local conta:= 1
local cnewstring:=""
              do while (conta <= Len(cnum) / 2)
                  num:= "N" + LTrim(Str(conta))
                  &num:= SubStr(cnum, conta * 2 - 1, 2)
                  cnewstring+=&num+"."
                  conta:= conta + 1
               enddo
return cnewstring

 

only it print the "." also then last number
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: Conversion from ca-clipper ( not found a variable)

Postby karinha » Thu Mar 03, 2022 11:08 am

Enrico Maria Giordano wrote:Encapsulation is not a concept tied to a particular programming language. It is a good programming principle that is useful to build and maintain a clean project structure. You can learn about it reading any programming theory book.

EMG


Okay Master Enrico. But what does this have to do with DECLARE the VARIABLES? Can you show something in practice? Are you referring to the creation of classes? Do you NEVER declare variables? As I've never seen a source (.prg) of yours, I can't dispute it. Thanks. Hugs.

Bien maestro Enrico. Pero, ¿qué tiene que ver esto con DECLARAR las VARIABLES? ¿Puedes mostrar algo en la práctica? ¿Te refieres a la creación de clases? ¿NUNCA declaras variables? Como nunca he visto una fuente (.prg) tuya, no puedo discutirlo. Aprender es un placer. Gracias. Abrazos.

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7824
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Conversion from ca-clipper ( not found a variable)

Postby Enrico Maria Giordano » Thu Mar 03, 2022 11:25 am

I put many samples in this forum during the years, so you should have seen some of my source code. Anyway, maybe you don't know that declaring a variable also defines its scope and lifetime.

A LOCAL variable exists and is only visible inside the function where it is declared.

A STATIC variable declared inside a function is just like a LOCAL one but keeps its value till the end of the program (ie. its lifetime lasts from the declaration to the end of the program).

A STATIC variable declared outside a function is visible in the whole file (the PRG) and its lifetime is like the previous one.

A PRIVATE variable is visible and exists from the declaration to all the functions called by the function where it is declared.

A PUBLIC variable is visible and exists from the declaration to all the program.

So the only variable that fully respect the encapsulation principle is the LOCAL one.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Conversion from ca-clipper ( not found a variable)

Postby karinha » Thu Mar 03, 2022 11:51 am

Master Enrico Escrebió:

Una variable LOCAL existe y solo es visible dentro de la función donde se declara.

Una variable ESTÁTICA declarada dentro de una función es como una LOCAL pero mantiene su valor hasta el final del programa (es decir, su tiempo de vida dura desde la declaración hasta el final del programa).

Una variable STATIC declarada fuera de una función es visible en todo el archivo (el PRG) y su tiempo de vida es como el anterior.

Una variable PRIVADA es visible y existe desde la declaración hasta todas las funciones llamadas por la función donde se declara.

Una variable PÚBLICA es visible y existe desde la declaración hasta todo el programa.

Entonces, la única variable que respeta completamente el principio de encapsulación es la LOCAL.


Una variable LOCAL existe y solo es visible dentro de la función donde se declara.

Una variable ESTÁTICA declarada dentro de una función es como una LOCAL pero mantiene su valor hasta el final del programa (es decir, su tiempo de vida dura desde la declaración hasta el final del programa).

Una variable STATIC declarada fuera de una función es visible en todo el archivo (el PRG) y su tiempo de vida es como el anterior.

Una variable PRIVADA es visible y existe desde la declaración hasta todas las funciones llamadas por la función donde se declara.

Una variable PÚBLICA es visible y existe desde la declaración hasta todo el programa.

Entonces, la única variable que respeta completamente el principio de encapsulación es la LOCAL.

Perfect master Enrique, this is how I see the VARIABLE STATEMENTS. And so it is written in the CLIPPER 5.3 books and manuals. Perhaps, I have misunderstood something wrong that you wrote. It doesn't matter, you write your programs his way and I write mine. Thank you for the information. Strong hug..

Perfecto maestro Enrique, así veo yo las DECLARACIONES DE VARIABLES. Y así está escrito en los libros y manuales de CLIPPER 5.3. Tal vez, he entendido mal algo que escribiste mal. No importa, tú escribes tus programas a tu manera y yo escribo el mío. Gracias por la información. Fuerte abrazo.

I will continue to follow my books and manuals. hahahaha

Continuaré siguiendo mis libros y manuales. jajajaja

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7824
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 60 guests