Normal Topic can I stop element data from being used literally? (Read 603 times)
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
can I stop element data from being used literally?
Dec 5th, 2013 at 11:41pm
Print Post Print Post  
     Is there a technique I can use to make information from an element seem just like Sbasic code that can be used in sbasic?

I use command buttons to send emails and faxes. Inside the sbasic code I create variables for the Subject, To, from, body and attachment that are then used with the @SendMail command.

I needed a way to allow a user to modify some of those particulars without having to wait for me to make a change and recompile.

So I created a new Database in the app that has just 5 fields. Key, From, subject, Body and attachment. My intent was to simply use @XLookupSourceList to create my variables that then can be changed by a user going to the specific record that matches the button and change anything they wanted all on their own.

var vVals as String

     vVals = @XLookupSourceList(@Fn, "code1", "EmailStructure!Key", "EmailStructure_Sender;EmailStructure_Subject;EmailStructure_Attachment;EmailStr
ucture_Body")
     if not @Error
     {

           VFromEmail = @AccessStringArray(vVals, 1)
           Vsubject = @AccessStringArray(vVals, 2)
           Vattachment = @AccessStringArray(vVals, 3)
             Vbody = @AccessStringArray(vVals, 4)



     }


     else
     {
           @MsgBox("Error: Unable to get email info.", "", "")
     }


Now when I did this my VFromEmail and Vsubject worked as thought but my Vbody came across in email as literally as it was typed, not as Sbasic usually interprets it.

So for example this code in Sbasic used with @sendmail makes the email body with the element of the last name of a physician and then the sentences

                 

Vbody = "Dr. "
                             + OATstudy_Last
                             + ","
                             + @NewLine()
                             + @NewLine()
                             + "yada yada yada."
                                 + @NewLine()
                                 + @NewLine()
                             + yada yada yada"
                             + @NewLine()
                             + @NewLine()
                             + "yada yada yada"
                             + @NewLine()
                             + @NewLine()
                             + "yada yada yada"

Now when I place this exact text in either a text element or a text editor element and use the @XLookupSourceList Vbody = @AccessStringArray(vVals, 4)

it comes out in the email literaly as is not as interpreted by Sbasic. Is there a different way I can do this?

Thanks
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: can I stop element data from being used literally?
Reply #1 - Dec 6th, 2013 at 2:12pm
Print Post Print Post  
Basically you are attempting self-modifying code, a strongly discouraged practice in computer science.

If possible, you should try to accomplish the same thing by using variables and a set of subroutines that allow the user to select between several formats and fill in the variables for that format. This can accomplish a lot of flexibility and doesn't cause the difficult issues involved in self modifying code.

But, if you insist, you may be able to take advantage of @FormRunCustomProgram. There are limitations on what this can do, primarily, it runs the code only as attached to an open form other than that that launched the function. In other words, the form specified as an argument must be one other than the current form.

@FormRunCustomProgram can take a string and interpret that string as a small SBasic program that it will compile and then execute. After it is run, your current form will need to gather the results from the specified form.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: can I stop element data from being used literally?
Reply #2 - Dec 6th, 2013 at 6:31pm
Print Post Print Post  
I've run code that is stored in a text field (in a 'code tester' app) by having SBasic write the contents of the field out to a file (CodeTest.pgm in my case), and then using #include "CodeTest.pgm" to bring it into the place where I wan to run it.

The LE that contains the programming text is named "Code". I write it to a file with this:
Code
Select All
// Write the contents of the Code field out to disk.
FileOverWrite("CodeTest.pgm", Code) 



And bring it in to SBasic like this:
Code
Select All
// Executes the code saved to disk by the Execute button on the Code Tester form.
#include "CodeTest.pgm" 


  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged