Hello,
I am trying to save the content from a window into the Text file. After saving it, I am trying to give user the capability to read the content from the saved text file and populate it in the Text Edit Box so that they don't have to retype again.
I was able to save the text file by using Save Text function.
I was also able to browse the text file by using Pick File function.
I need help with the extraction of the data and the populating it in the Text Edit Box.
Following is my code:
initial_ECN = ""; // Define initial_ECN outside of the function
initial_PIDTag = "";
// Define a function to create the input window
WinInput = Function({},
ECN = initial_ECN;
PIDTag = initial_PIDTag;
New Window( "Input", <<Modal,
V List Box(
Border Box( Left( 10 ), Right( 94 ), Bottom( 10 ), Top( 10 ), Sides( 15 ),
V List Box(
Lineup Box( N Col( 3 ),
//System ECN
Text Box( "System ECN:" ),
S1 = Text Edit Box( ECN , Justify Text( "left" ), <<Set Width(100)),
Spacer Box( Size( 1, 1 ) ),
//System P&ID Tag
Text Box( "P&ID Tag:" ),
S2 = Text Edit Box( PIDTag, Justify Text( "left" ), <<Set Width(100) ),
S2_note = Text Box( " Attach system P&ID indicating boundaries included in these calculations.", Set Wrap( 400 ),Justify Text( "center" )),
S2_note << Set Font Style( "Italic" ),
Spacer Box( Size( 1, 1 ) ),
teb5 = Text Edit Box("$Documents\Report\", <<Set Width(100), << Set Hint("e.g. /Tech/")),
Button Box("Browse",<<Set Function(Function({},
{Default Local},
fileName = Pick File("Select Text File", "$DESKTOP", {"Text Files|*.txt", "All Files|*"}, 1, 0, ""); // Pick the text file
If(fileName != "", // If a file is selected
teb5 << Set Text(Read File(fileName)) // Read the file and set its content in the text edit box
)
)
)
)
)
)
)
),
Button Box( "OK",
RunTimestamp = Today();
System_info = {S1, S2} << Get Text;
initial_ECN = System_info[1]; // Update the global variable
initial_PIDTag = System_info[2]; // Update the global variable
OutputWindow(initial_ECN, initial_PIDTag); // After getting input, open the output window
)
)
);
// Function to create the output window
OutputWindow = Function({ECN, PIDTag},
OutputContent = New Window( "Final Output",
V List Box(
Border Box( Left( 10 ), Right( 50 ), bottom( 10 ), top( 10 ), sides( 15 ),
V List Box(
Lineup Box( N Col( 3 ), Spacing( 10 ),
//System ECN
Text Box( "System ECN:", Justify Text( "right" ) ),
S1 = Text Box( ECN, <<Set Width(100), Justify Text( "center" ) ),
Spacer Box( Size( 10, 10 ) ),
S1 << Background color( "yellow" ),
//System P&ID Tag
Text Box( "P&ID Tag:", Justify Text( "right" ) ),
S2 = Text Box( PIDTag, <<Set Width(100), Justify Text( "center" ) ),
S2_note = Text Box( " Attach system P&ID indicating boundaries included in these calculations.", Set Wrap( 500 ) ),
S2_note << Set Font Style ("Italic"),
S2 << Background color( "yellow" ),
)
)
),
H List Box(3,
Button Box( "Print PDF",
OutputContent << Set Page Setup(margins( 1, 1, 1, 1 ), scale( 0.80 ), portrait( 1 ), paper size( "Letter" ));
// OutputContent << Save PDF( "C:\Users\panjwanip\OneDrive - Barry-Wehmiller\Desktop\surface_area_output.pdf" )
OutputContent << Save Text( "C:\Users\panjwanip\OneDrive - Barry-Wehmiller\Desktop\surface_area_output.txt" )
//OutputContent << Save Excel File( "C:\Users\panjwanip\OneDrive - Barry-Wehmiller\Desktop\surface_area_output.xlsx" )
),
Spacer Box( size( 520, 20 ) ),
Button Box( "Back",
Current Window() << Close Window;
WinInput(); // Pass the current value of ECN back to the input window
),
)
)
)
);
// Initially open the input window with initial_ECN
WinInput();