Subscribe Bookmark RSS Feed

weeks = 25; is from a dialog box. Please help with the column formula using "weeks" as an input

vinkane

Community Trekker

Joined:

Dec 23, 2013

Having trouble using "weeks" in a column formula. weeks = 25; is from a dialog box.  Help is appreciated

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

If you're familiar with Table Variables, no need to read further...

If your dialog box is part of a larger script, then MS' suggestion seems to be as streamlined as any. If collecting the value for "weeks" is all it is doing, you might consider ditching the script and creating a table variable called 'weeks'. Then use that in your formula:

12583_pastedImage_4.png

12576_pastedImage_0.png

12581_pastedImage_2.png

To change the value for 'weeks', double click on the current value and type over it.

BTW - With proper scoping, changing the value for the table variable can be done by script, as well:

(Assuming dt = Data Table("Untitled 21") for the above example)

 

New Window( "Line Up Box",

     <<Modal,

     V List Box(

           Lineup Box( N Col( 2 ), Text Box( "Set this value" ),

           var = Number Edit Box( 45 ), )

     ),

     H List Box( Button Box( "OK", dt:weeks = var << get ),

     Button Box( "Cancel", ) )

  );

6 REPLIES
ian_jmp

Staff

Joined:

Jun 23, 2011

Not sure exactly what you have already, or where you need to end up. But maybe something like this?

dt = New Table( "Weeks",

Add Rows( 1000 ),

New Column( "Date",

Numeric,

"Continuous",

Format( "m/d/y", 10 ),

Input Format( "m/d/y" ),

Formula( Random Integer( Today() - In Years( 1 ), Today() ) )

)

);

wList = {}; For(w=1, w<=52, w++, InsertInto(wList, Char(w)));

win = NewWindow("Pick Week",

lb = ListBox(wList, maxSelected(1)),

ButtonBox("OK", OKscript)

);

OKscript =

Expr(

win << closeWindow;

w = (lb << getSelected)[1];

w = Num(w);

form = Expr(If(Week Of Year(:Date) == wTBD, 1, 0));

SubstituteInto(form, Expr(wTBD), w);

dt << NewColumn("Match Selected Week", Numeric, Nominal, Formula(NameExpr(form)));

);

vinkane

Community Trekker

Joined:

Dec 23, 2013

Thanks for the try....the data table column( "Weeks to Roll" should = 25, a value needed by the user to evaluate a secondary operation.

vinkane

Community Trekker

Joined:

Dec 23, 2013

New Window("Line Up Box",

<<Modal,

V List Box(

Line Up Box(NCol(2),

Text Box("Set this value"), var = Number Edit Box(45),),),

H List Box(

Button Box("OK", ),

Button Box("Cancel" , )) );    

weeks = var << get;

show (weeks);

 

Need to use the variable "weeks" in a numerical column formula. Previous post may have been confusing

ms

Super User

Joined:

Jun 23, 2011

One way is to update the formula through a button script (i.e. the "OK" button).

For example:

//Example table

dt = New Table("weeks", Add Rows(10), New Column("Weeks to roll", Numeric));

// User sets value and adds formula

New Window("Line Up Box",

    <<Modal,

    V List Box(Lineup Box(N Col(2), Text Box("Set this value"), var = Number Edit Box(45), ), ),

    H List Box(

        Button Box("OK",

        Eval(Parse("Column(\!"Weeks to roll\!")<<set formula(" || Char(var << get) || ")"))

        ),

        Button Box("Cancel")

    )
);

Solution

If you're familiar with Table Variables, no need to read further...

If your dialog box is part of a larger script, then MS' suggestion seems to be as streamlined as any. If collecting the value for "weeks" is all it is doing, you might consider ditching the script and creating a table variable called 'weeks'. Then use that in your formula:

12583_pastedImage_4.png

12576_pastedImage_0.png

12581_pastedImage_2.png

To change the value for 'weeks', double click on the current value and type over it.

BTW - With proper scoping, changing the value for the table variable can be done by script, as well:

(Assuming dt = Data Table("Untitled 21") for the above example)

 

New Window( "Line Up Box",

     <<Modal,

     V List Box(

           Lineup Box( N Col( 2 ), Text Box( "Set this value" ),

           var = Number Edit Box( 45 ), )

     ),

     H List Box( Button Box( "OK", dt:weeks = var << get ),

     Button Box( "Cancel", ) )

  );

vinkane

Community Trekker

Joined:

Dec 23, 2013

Just checked out the table variable solution and GREAT. Plus learned something new.

Using the script below....what would be the column formula using weeks ?  Curious   Thanks for the solution

New Window("Line Up Box",

<<Modal,

V List Box(

Line Up Box(NCol(2),

Text Box("Set this value"), var = Number Edit Box(45),),),

H List Box(

Button Box("OK", ),

Button Box("Cancel" , )) 

weeks = var << get;

show (weeks);