Página 1 de 2

Macrosubstituição no Clipper (&)

Enviado: 06 Set 2010 08:19
por Spitzer
Olá!

Tenho a seguinte declaração de variável:
LOCAL lNmArqTxt := "DESP.TXT"

Aí faço usao da variável declarada da seguinte forma:
SET PRINTER TO &lNmArqTxt

Não está dando certo.
Se eu não estiver enganado (há anos não programo), não posso usar macrosubstituição numa variável local. É isto mesmo?
E como faço? Me obrigo a declarar a variável como PRIVATE, por exemplo?

Obrigado!

Re: Macrosubstituição no Clipper (&)

Enviado: 06 Set 2010 08:24
por Maligno
Pode sim. Apenas coloque a variável entre parênteses.

Re: Macrosubstituição no Clipper (&)

Enviado: 06 Set 2010 09:19
por Spitzer
Olá, Maligno!

Obrigado pela pronta resposta.

No comando SET PRINTER TO &(lNmArqTxt) funcionou perfeitamente, mas no comando SWPRUNCMD("WORDPAD.EXE &(lNmArqTxt)",0,"","") não funcionou.
Dá a seguinte mensagem de erro: Não é possível encontrar o arquivo C:\Fro\&(lNmArqTxt). Verifique se o caminho e o nome do arquivo estão corretos.
A macrosubstituição não está sendo feita, neste caso.

Obrigado!

Re: Macrosubstituição no Clipper (&)

Enviado: 06 Set 2010 09:21
por Spitzer
Olá, Maligno!

Resolvido!
O comando ficou assim:
SWPRUNCMD("WORDPAD.EXE "+lNmArqTxt,0,"","")

Novamente, obrigado!

Re: Macrosubstituição no Clipper (&)

Enviado: 06 Set 2010 09:38
por Maligno
Falha minha. Na verdade eu tinha dito para colocar a variável entre parênteses sem o comando &.
Como parte de um comando funciona bem. Mas numa soma de strings, que você não havia exemplificado antes, não deve funcionar mesmo. Mas daí nem precisa, já que se trata apenas de uma "soma" de strings.

Macrosubstituição no Clipper (&)

Enviado: 30 Jan 2016 12:06
por microvolution
OLá Maligno e demais professores bom dia!
Já são quase 6 anos esse tópico, não sei se irão responder. Quero evitar de criar tópico desnecessário, pois este aqui está criado.

Bom, tenho as seguintes variáveis que serão gravadas (o conteúdo delas é claro) em campos de arquivos (tabelas) dbf/ntx:

Código: Selecionar todos

mVR_PARC1
mVCT_PARC1
mVR_PARC2
mVCT_PARC2
mVR_PARC3
mVCT_PARC3
mVR_PARC4
mVCT_PARC4
mVR_PARC5
mVCT_PARC5
mVR_PARC6
mVCT_PARC6
mVR_PARC7
mVCT_PARC7
Estas variáveis acima, com seus respectivos campos do arquivo (VR_PARCx e VCT_PARCx) fazem parte do compras de mercadorias.
Então, no momento em que o usuário está digitando, existe outra variável que recebe a quantidade de parcelas que foi dividida a "tal compra", que é a variável com seu respectivo campo da mesma tabela:

Código: Selecionar todos

mQT_PARC
QT_PARC
Como só o usuário é quem sabe quantas parcelas serão preenchidas: se uma ou no máximo 7.
Aí que "mora o perigo".
Se todas as parcelas fossem preenchidas no momento do "replace" (já foi feito o append blank neste caso), era muito fácil, não precisaria incomodar os digníssimos professores.

Então, estão fazendo um loop for/next de 1 até a quantidade de parcelas que realmente foram preenchidas e, usando a variável mQT_PARC para tal solução, da seguinte forma:
for nPARC := 1 to mQT_PARC

Código: Selecionar todos

replace ;
(...)
        VRTITUTLO  with mVR_PARC  + &nPARC.,;
        DT_VENCTO with mVCT_PARC + &nPARC.,;
(...)
Bom, como não existe a variável mVR_PARC e sim as variáveis mVR_PARCx o sistema gera um erro que variável não existe. O mesmo erro acontece nas duas linhas.

Então, mudei para:

Código: Selecionar todos

replace ;
(...)
        VRTITUTLO  with "mVR_PARC"  + &nPARC.,;
        DT_VENCTO with "mVCT_PARC" + &nPARC.,;
(...)
E, aí grava no banco de dados o nome "mVR_PARC1" e não o seu contéudo.
Mudei então para a MACRO SUBSTITUIÇÃO:

Código: Selecionar todos

replace ;
(...)
        VRTITUTLO  with &"mVR_PARC".  + &nPARC.,;
        DT_VENCTO with &"mVCT_PARC". + &nPARC.,;
(...)
Apresenta erro também.
Enfim, alguém sabe como fazer a macro substituição nesse caso?
Ou conseguem me clarear para fazer diferente?
grato!

Macrosubstituição no Clipper (&)

Enviado: 30 Jan 2016 15:09
por Jairo Maia
Olá microvolution,

Você precisa montar o nome da variável antes da macro. Veja se ajuda a entender:

Código: Selecionar todos

SET DATE BRITISH
SET CENTURY ON

DBCreate( "Teste", {;
                   {"vrtitulo"  ,"N", 8, 2},;
                   {"dt_vencto" ,"D", 8, 0};
                   } )
Use Teste Shared New

mVR_PARC1:=15.00
mVCT_PARC1:=CToD( "01/02/2016" )

mVR_PARC2:=20.00
mVCT_PARC2:=CToD( "01/03/2016" )

mVR_PARC3:=25.00
mVCT_PARC3:=CToD( "01/04/2016" )

mQT_PARC := 3
For nPARC := 1 to mQT_PARC

  cValParc := "mVR_PARC" + LTrim( Str( nPARC ) )  // monta o nome da variavel
  cVencParc := "mVCT_PARC" + LTrim( Str( nPARC ) )  // monta o nome da variavel
  
  APPEND BLANK
  Replace VRTITULO With &cValParc.,;
          DT_VENCTO With &cVencParc.

Next

Return Nil

Macrosubstituição no Clipper (&)

Enviado: 30 Jan 2016 18:04
por ANDRIL
Crie o nome da variavel antes da macrosubstituíção, assim como o Jairo já informou. Esta linha também daria erro de tipagem incorreta ou de campo não existente no DBF.
microvolution escreveu:DT_VENCTO with mVCT_PARC + &nPARC
"

Esta usando o REPLACE em grupo o que pode tornar a identificação do erro mais difícil (inline), aconselho a usar REPLACE individuais.
Até+

Macrosubstituição no Clipper (&)

Enviado: 30 Jan 2016 18:45
por JoséQuintas

Código: Selecionar todos

 VRTITUTLO  with &( "mVR_PARC" + Str( nPARC, 1 ) ),; 
         DT_VENCTO with &( "mVCT_PARC" + Str( nPARC, 1 ) )

Macrosubstituição no Clipper (&)

Enviado: 30 Jan 2016 22:17
por microvolution
Genteeeeeeeeeeeeeee! só tem ninjas neste lugar...
Nunca serei semelhante a V.Sas.
Cada um postou soluções incríveis...
vou testar e no mais tardar na segunda, posto os resultados...
um forte abraço e bom fds! :))

Macrosubstituição no Clipper (&)

Enviado: 18 Fev 2016 23:08
por microvolution
bom, como disse eu mesmo dias atrás... estou aqui para testar as soluções dos nobres professores:
atualmente fiz assim com o código:

Código: Selecionar todos

                                 for nPARC := 1 to mQT_PARC
                                    if nPARC = 1
                                       replace CDFORNECE with mCDFORNECE,;
                                          NUTITULO  with left ( alltrim ( str ( mNU_NF ) ) , 9 ) + alltrim ( str ( nPARC ) ),;
                                          DSHISTORI with mDSHISTORI,;
                                          VRTITUTLO with mVR_PARC1,;
                                          DT_VENCTO with mVCT_PARC1,;
                                          CD_TIPCOB with mCD_TIPCOB,;
                                          CDCON_BAN with "",;
                                          VRJUROS   with 0,;
                                          CD_DESPES with mCD_DESPES,;
                                          CD_SITTIT with 'A',;
                                          CD_CHEGDP with mCD_CHEGDP,;
                                          CD_CONTAB with ""
                                    elseif nPARC = 2
                                       replace CDFORNECE with mCDFORNECE,;
                                          NUTITULO  with left ( alltrim ( str ( mNU_NF ) ) , 9 ) + alltrim ( str ( nPARC ) ),;
                                          DSHISTORI with mDSHISTORI,;
                                          VRTITUTLO with mVR_PARC1,;
                                          DT_VENCTO with mVCT_PARC1,;
                                          VRTITUTLO with mVR_PARC2,;
                                          DT_VENCTO with mVCT_PARC2,;
                                          CD_TIPCOB with mCD_TIPCOB,;
                                          CDCON_BAN with "",;
                                          VRJUROS   with 0,;
                                          CD_DESPES with mCD_DESPES,;
                                          CD_SITTIT with 'A',;
                                          CD_CHEGDP with mCD_CHEGDP,;
                                          CD_CONTAB with ""
                                    elseif nPARC = 3
                                       replace CDFORNECE with mCDFORNECE,;
                                          NUTITULO  with left ( alltrim ( str ( mNU_NF ) ) , 9 ) + alltrim ( str ( nPARC ) ),;
                                          DSHISTORI with mDSHISTORI,;
                                          VRTITUTLO with mVR_PARC1,;
                                          DT_VENCTO with mVCT_PARC1,;
                                          VRTITUTLO with mVR_PARC2,;
                                          DT_VENCTO with mVCT_PARC2,;
                                          VRTITUTLO with mVR_PARC3,;
                                          DT_VENCTO with mVCT_PARC3,;
                                          CD_TIPCOB with mCD_TIPCOB,;
                                          CDCON_BAN with "",;
                                          VRJUROS   with 0,;
                                          CD_DESPES with mCD_DESPES,;
                                          CD_SITTIT with 'A',;
                                          CD_CHEGDP with mCD_CHEGDP,;
                                          CD_CONTAB with ""
                                    elseif nPARC = 4
                                       replace CDFORNECE with mCDFORNECE,;
                                          NUTITULO  with left ( alltrim ( str ( mNU_NF ) ) , 9 ) + alltrim ( str ( nPARC ) ),;
                                          DSHISTORI with mDSHISTORI,;
                                          VRTITUTLO with mVR_PARC1,;
                                          DT_VENCTO with mVCT_PARC1,;
                                          VRTITUTLO with mVR_PARC2,;
                                          DT_VENCTO with mVCT_PARC2,;
                                          VRTITUTLO with mVR_PARC3,;
                                          DT_VENCTO with mVCT_PARC3,;
                                          VRTITUTLO with mVR_PARC4,;
                                          DT_VENCTO with mVCT_PARC4,;
                                          CD_TIPCOB with mCD_TIPCOB,;
                                          CDCON_BAN with "",;
                                          VRJUROS   with 0,;
                                          CD_DESPES with mCD_DESPES,;
                                          CD_SITTIT with 'A',;
                                          CD_CHEGDP with mCD_CHEGDP,;
                                          CD_CONTAB with ""
                                    elseif nPARC = 5
                                       replace CDFORNECE with mCDFORNECE,;
                                          NUTITULO  with left ( alltrim ( str ( mNU_NF ) ) , 9 ) + alltrim ( str ( nPARC ) ),;
                                          DSHISTORI with mDSHISTORI,;
                                          VRTITUTLO with mVR_PARC1,;
                                          DT_VENCTO with mVCT_PARC1,;
                                          VRTITUTLO with mVR_PARC2,;
                                          DT_VENCTO with mVCT_PARC2,;
                                          VRTITUTLO with mVR_PARC3,;
                                          DT_VENCTO with mVCT_PARC3,;
                                          VRTITUTLO with mVR_PARC4,;
                                          DT_VENCTO with mVCT_PARC4,;
                                          VRTITUTLO with mVR_PARC5,;
                                          DT_VENCTO with mVCT_PARC5,;
                                          CD_TIPCOB with mCD_TIPCOB,;
                                          CDCON_BAN with "",;
                                          VRJUROS   with 0,;
                                          CD_DESPES with mCD_DESPES,;
                                          CD_SITTIT with 'A',;
                                          CD_CHEGDP with mCD_CHEGDP,;
                                          CD_CONTAB with ""
                                    elseif nPARC = 6
                                       replace CDFORNECE with mCDFORNECE,;
                                          NUTITULO  with left ( alltrim ( str ( mNU_NF ) ) , 9 ) + alltrim ( str ( nPARC ) ),;
                                          DSHISTORI with mDSHISTORI,;
                                          VRTITUTLO with mVR_PARC1,;
                                          DT_VENCTO with mVCT_PARC1,;
                                          VRTITUTLO with mVR_PARC2,;
                                          DT_VENCTO with mVCT_PARC2,;
                                          VRTITUTLO with mVR_PARC3,;
                                          DT_VENCTO with mVCT_PARC3,;
                                          VRTITUTLO with mVR_PARC4,;
                                          DT_VENCTO with mVCT_PARC4,;
                                          VRTITUTLO with mVR_PARC5,;
                                          DT_VENCTO with mVCT_PARC5,;
                                          VRTITUTLO with mVR_PARC6,;
                                          DT_VENCTO with mVCT_PARC6,;
                                          CD_TIPCOB with mCD_TIPCOB,;
                                          CDCON_BAN with "",;
                                          VRJUROS   with 0,;
                                          CD_DESPES with mCD_DESPES,;
                                          CD_SITTIT with 'A',;
                                          CD_CHEGDP with mCD_CHEGDP,;
                                          CD_CONTAB with ""
                                    elseif nPARC = 7
                                       replace CDFORNECE with mCDFORNECE,;
                                          NUTITULO  with left ( alltrim ( str ( mNU_NF ) ) , 9 ) + alltrim ( str ( nPARC ) ),;
                                          DSHISTORI with mDSHISTORI,;
                                          VRTITUTLO with mVR_PARC1,;
                                          DT_VENCTO with mVCT_PARC1,;
                                          VRTITUTLO with mVR_PARC2,;
                                          DT_VENCTO with mVCT_PARC2,;
                                          VRTITUTLO with mVR_PARC3,;
                                          DT_VENCTO with mVCT_PARC3,;
                                          VRTITUTLO with mVR_PARC4,;
                                          DT_VENCTO with mVCT_PARC4,;
                                          VRTITUTLO with mVR_PARC5,;
                                          DT_VENCTO with mVCT_PARC5,;
                                          VRTITUTLO with mVR_PARC6,;
                                          DT_VENCTO with mVCT_PARC6,;
                                          VRTITUTLO with mVR_PARC7,;
                                          DT_VENCTO with mVCT_PARC7,;
                                          CD_TIPCOB with mCD_TIPCOB,;
                                          CDCON_BAN with "",;
                                          VRJUROS   with 0,;
                                          CD_DESPES with mCD_DESPES,;
                                          CD_SITTIT with 'A',;
                                          CD_CHEGDP with mCD_CHEGDP,;
                                          CD_CONTAB with ""
                                    endif
                                    // MOVE_MEMORIA_ARQUIVO ()
                                    // unlock
                                    // commit
                                 next
esta é apenas a parte do REPLACE, tem também a do APPEND BLANK que é semelhante.
bom, tá ficando muito grande, e penso que podemos diminuir isso daqui, mas, não consegui encaixar ou entender nenhum dos exemplos citados anteriormente (como Jairo disse) e etc...
as variáveis/campos VR_PARC (de 1 a 7) com suas respectivas VCT_PARC são preenchidas no momento em que o usuário decide em quantas parcelas irá lançar... ele tem 7 opções, como disse.
Então, uso o FOR/NEXT para isso... mas penso que poderíamos gravar de 1 a 7 em menos linhas.
só não consegui ainda encaixar os exemplos citados para isso ocorrer.
vlw!

Macrosubstituição no Clipper (&)

Enviado: 18 Fev 2016 23:27
por microvolution
demorei alguns minutos... pois o fórum ficou sem resposta...
então, o pior de tudo é que só grava uma parcela no APPEND BLANCK... rsrsrs

Macrosubstituição no Clipper (&)

Enviado: 18 Fev 2016 23:33
por JoséQuintas
Resumindo: desprezou todas as respostas.

Macrosubstituição no Clipper (&)

Enviado: 18 Fev 2016 23:40
por JoséQuintas
Aliás, nem sei se está etendendo o que está fazendo, coisa muito doida.
Afinal, é um registro pra cada parcela? porque no 7 grava todas as parcelas de 1 a 7?

Macrosubstituição no Clipper (&)

Enviado: 19 Fev 2016 11:37
por JoséQuintas
Deixa eu ver se entendi....

Todo esse fonte, é que ao invés de gravar uma data em branco, não grava nada, que é pra ela ficar em branco no arquivo.
É isso?