Page 1 of 1

string to code block

Posted: Wed Sep 22, 2010 2:09 am
by Andy Edward
Hi everyone,

Is there a way to make a string such as

myString := '{||oDataSetGENERIC:FieldGet("' + variableWithEverChangingValue + '")}'

into a code block so I can put this into a DCFINDADDCOL DATA parameter like so

DCFINDADDCOL DATA myString HEADER 'PERIOD' TO COL_TABLE ??

Re: string to code block

Posted: Wed Sep 22, 2010 9:30 am
by rdonnay

Code: Select all

myString := '{||oDataSetGENERIC:FieldGet("' + variableWithEverChangingValue + '")}'

bBlock := &myString

Re: string to code block

Posted: Wed Sep 22, 2010 6:51 pm
by Andy Edward
rdonnay wrote:

Code: Select all

myString := '{||oDataSetGENERIC:FieldGet("' + variableWithEverChangingValue + '")}'

bBlock := &myString
Hi Roger,

Thanks for the reply.

Using your code does indeed made it into a code block but also returned the value of the code block. So the values inside the field (AMOUNT in this case) is always the value of the first row of the DataSet

Please take a look at the image attached for a better view of the problem. Hardcoded field is how the field finally should look like.

Code: Select all

xFieldName := 'AMOUNT' 
myString := '{||oDataSetGENERIC:FieldGet("' + xFieldName + '")}'
bBlock := &myString

DCFINDADDCOL DATA {||oDataSetGENERIC:FieldGet('PERIOD')} HEADER 'FIELD1' TO COL_TABLE
DCFINDADDCOL DATA {||oDataSetGENERIC:FieldGet('BATNO')} HEADER 'FIELD2' TO COL_TABLE
DCFINDADDCOL DATA {||oDataSetGENERIC:FieldGet('VOUCH')} HEADER 'FIELD3' TO COL_TABLE
DCFINDADDCOL DATA {||oDataSetGENERIC:FieldGet('ACNO')} HEADER 'FIELD4' TO COL_TABLE
DCFINDADDCOL DATA {||oDataSetGENERIC:FieldGet('DESC')} HEADER 'FIELD5' TO COL_TABLE
DCFINDADDCOL DATA {||oDataSetGENERIC:FieldGet(xFieldName)} HEADER 'Hardcoded' TO COL_TABLE
DCFINDADDCOL DATA bBlock HEADER 'From Forum' TO COL_TABLE

@1,1 DCFINDBROWSE FIELDS COL_TABLE DATA oDataSetGENERIC SIZE x1024+100,y1024+18 AUTOSEEK TITLE XTITLE FONT cSAYFONT TO xSELECT
May I ask kindly for your advice on this matter??

Re: string to code block

Posted: Wed Sep 22, 2010 10:09 pm
by rdonnay
Andy -

I don't know why yours doesn't work. It looks right to me.
Compile and run the below code.
It works as expected.
Use CUSTOMER.DBF from \exp19\data

Roger

Code: Select all

#INCLUDE "dcdialog.CH"

FUNCTION Main

LOCAL GetList[0], GetOptions, oBrowse, cFieldName, cField, bField

USE CUSTOMER

@ 0,0 DCBROWSE oBrowse ALIAS 'CUSTOMER' SIZE 10,20 FIT

DCBROWSECOL DATA {||CUSTOMER->bill_name} HEADER 'Name 1' WIDTH 15 PARENT oBrowse

cFieldName := 'bill_name'
cField := '{||CUSTOMER->' + cFieldName + '}'
bField := &cField

DCBROWSECOL DATA bField HEADER 'Name 2' WIDTH 15 PARENT oBrowse

DCREAD GUI FIT TITLE 'Macro test'

RETURN nil

PROC appsys ; return

Re: string to code block

Posted: Thu Oct 07, 2010 2:43 am
by Andy Edward
Just an update, that the problem went away after a system restart. :doh: