Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

syntax problem using eval()

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    syntax problem using eval()

    I don't know what I am doing wrong here but I am getting an error of "extra characters at end of expression"

    This is the line that errs:

    vn = eval("thf."+tmp.fldname)

    tmp = table.open_session("t_repfin")
    thf = table.open_session("hh_fin")

    hh_fin is a one record table that has 50 fields with amounts I am trying to map to t_repfin->fldname that has 50 records. So I query hh_fin to set it to the one record I need, then fetch thru t_repfin and set each t_repfin record to the matching field in hh_fin.

    here's the section of the script I am working with (Note TLN() is a udf that writes to the trace window)
    Code:
    if xflag then    
        tmp.batch_begin()
        tmp.fetch_first()
        WHILE .not. tmp.fetch_eof()        
            'map each of the hh_fin fields in the one record to create a matching record in t_repfin
            'errs with 'extra chars at end of expression'
           [COLOR=#ff0000] vn = eval("thf."+tmp.fldname)[/COLOR]
            'returned fieldname instead of amount                 
            'vn = thf.eval(quote(tmp.fldname))
            Tln("hh_fin->"+tmp.fldname,vn)
            commit_flag = .t.    
            select
                case blankflag = .t.            
                    on error goto ERRMSG3                
                    tmp.change_begin()
                        'select all records to display as blank in report                
                        tmp.sel_flag = .t.
                    tmp.change_end(commit_flag)
                    goto SKIPIT
                case tmp.FLDNAME = ""
                    goto SKIPIT
                [COLOR=#0000ff]case eval("thf."+tmp.fldname) > 0[/COLOR] 
                'case thf.eval(quote(tmp.fldname)) > 0            
                    on error goto ERRMSG3
                    tmp.change_begin()                                                                    
                        [COLOR="#0000FF"]'tmp.amount = eval("thf."+tmp.fldname)
                        tmp.amount = thf.eval(quote(tmp.fldname))[/COLOR]
                        tmp.sel_flag = .t.
                    tmp.change_end(commit_flag)    
            end select
                
            SKIPIT:        
            on error goto 0
            'should stop loop on error
            if commit_flag then            
                tmp.fetch_next()    
            else
                EXIT WHILE
            end if    
        END WHILE
        tmp.batch_end()
        
        CLOSETBLS:
        lst1 = crlf_to_comma(tmp.Enum_Session_Open())
        Tln("tmp open list",lst1)
        if inlist2(tmp.name_get(),lst1) then
            tmp.close()
        end if
        lst2 = crlf_to_comma(thf.Enum_Session_Open())
        Tln("thf open list",lst2)
        if inlist2(thf.name_get(),lst2) then
            thf.close()
        end if
        
    end if
    
    if commit_flag then
        ui_beep(UI_STANDARD_BEEP)
    end if
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

    #2
    Re: syntax problem using eval()

    Not sure what is going on.

    I do what you are doing, but in 2 steps to make it easier to diagnose.

    so

    vn = eval("thf."+tmp.fldname)

    becomes

    text2eval = "thf."+tmp.fldname
    vn = eval(text2eval)

    Then I can see what the value the eval() is acting on through debug(1) or a msgbox.

    or

    command2eval = "vn =thf."+tmp.fldname
    evaluate_template(command2eval)

    Without an example of the your table it's only a guess as to what is happening..
    Al Buchholz
    Bookwood Systems, LTD
    Weekly QReportBuilder Webinars Thursday 1 pm CST

    Occam's Razor - KISS
    Normalize till it hurts - De-normalize till it works.
    Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
    When we triage a problem it is much easier to read sample systems than to read a mind.
    "Make it as simple as possible, but not simpler."
    Albert Einstein

    http://www.iadn.com/images/media/iadn_member.png

    Comment


      #3
      Re: syntax problem using eval()

      I am not seeing how tmp.fldname returns a field name. At least I think that is what is being attempted.
      There can be only one.

      Comment


        #4
        Re: syntax problem using eval()

        Didn't expect such a quick reply - here's what the test data looks like:

        testdata.jpg
        Robin

        Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

        Comment


          #5
          Re: syntax problem using eval()

          Ok, I understand more about what you are doing and the theory is sound.

          Code:
          tbl = table.open("dept")
          tmp = table.open("a")
          ? eval("tbl."+tmp.fldname)
          = 1
          tmp.fetch_next()
          ? eval("tbl."+tmp.fldname)
          = "Grocery
          Your test data has a blank value in fldname for S011. That will throw the error you are seeing.
          There can be only one.

          Comment


            #6
            Re: syntax problem using eval()

            The test for the blank fldname was in a lower part of the script so I moved it to the beginning. In the meantime I used Al's suggestion so I could view the values in the trace window. Here is what it looks like now:
            Code:
            if xflag then
            	dim vfldstr as c = ""
            	dim vamt as n = 0	
            	tmp.batch_begin()
            	tmp.fetch_first()
            	WHILE .not. tmp.fetch_eof()		
            		'map each of the hh_fin fields in the one record to the matching amount field in t_repfin				
            		[COLOR="#0000FF"]vfldstr = "thf."+tmp.fldname
            		if eval_valid(vfldstr) then
            			vamt = eval(vfldstr)		
            			Tln(vfldstr,vamt)
            			commit_flag = .t.	
            		else
            			goto SKIPIT
            		end if[/COLOR]
            		
            		select
            			case blankflag = .t.			
            				on error goto ERRMSG3				
            				tmp.change_begin()
            					'select all records to display as blank in report				
            					tmp.sel_flag = .t.
            				tmp.change_end(commit_flag)
            				goto SKIPIT
            			'case tmp.FLDNAME = ""
            				'goto SKIPIT			
            			case vamt > 0
            				on error goto ERRMSG3
            				tmp.change_begin()																						
            					tmp.amount = vamt
            					tmp.sel_flag = .t.
            				tmp.change_end(commit_flag)	
            		end select
            			
            		SKIPIT:		
            		on error goto 0
            		'should stop loop on error
            		if commit_flag then			
            			tmp.fetch_next()	
            		else
            			EXIT WHILE
            		end if	
            	END WHILE
            	tmp.batch_end()
            	
            	CLOSETBLS:
            	lst1 = crlf_to_comma(tmp.Enum_Session_Open())
            	Tln("tmp open list",lst1)
            	if inlist2(tmp.name_get(),lst1) then
            		tmp.close()
            	end if
            	lst2 = crlf_to_comma(thf.Enum_Session_Open())
            	Tln("thf open list",lst2)
            	if inlist2(thf.name_get(),lst2) then
            		thf.close()
            	end if
            	
            end if
            You guys are the best! Thanks
            Robin

            Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

            Comment


              #7
              Re: syntax problem using eval()

              And now it works?
              There can be only one.

              Comment


                #8
                Re: syntax problem using eval()

                Here's what the report section looks like when there are amounts filled in - no zero amounts are displayed.

                repsection.jpg

                phooey - I see I still have a DOB error to fix... but this part works.
                Last edited by MoGrace; 02-15-2018, 05:51 PM.
                Robin

                Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

                Comment


                  #9
                  Re: syntax problem using eval()

                  if i'm understanding what you're trying to do, here's what I use when I have to do what you're doing.

                  something like this:

                  dim arr[0] as p
                  arr.initialize_from_table(tablename, your filter , order)

                  this would populate the array with the all of fields and their values for the one record you want.

                  after change_begin, assuming your filter returned the 1 record you were looking for:

                  tmp.fieldname = arr[1].fieldname (the fieldname from hh_fin)

                  it's just much easier for me to address, since I know the fieldnames from the other table.

                  if this isn't what you're trying to accomplish or want more info how I do it, let me know. I use arrays or collections a lot for this type of operation

                  Comment


                    #10
                    Re: syntax problem using eval()

                    Hi Gary,
                    I am not matching field to field, instead I am mapping the hh_fin field to the amount field in t_repfin by matching the t_repfin->fldname to the hh_fin->fieldname (which holds the value I need to get into the t_repfin->amount field). Did you see the screenshot of my data example above in post #4?
                    Robin

                    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

                    Comment


                      #11
                      Re: syntax problem using eval()

                      Robin,

                      You may have a logic issue but I am still struggling with the flow. Not a big fan of goto <label>.

                      If the first record has a valid fieldname you commit_flag = .t. and transfer the value to the appropriate field. I don't see where you reset commit_flag to .f. for the next loop. That should probably be done immediately after WHILE .not. tmp.fetch_eof().
                      There can be only one.

                      Comment


                        #12
                        Re: syntax problem using eval()

                        Robin

                        Consider adding some logging to this process to indicate what records are read and how they are processed.

                        If not forever, but at least during some extensive testing. Writing to a text file is fast and easy to monitor while a process is running.
                        Al Buchholz
                        Bookwood Systems, LTD
                        Weekly QReportBuilder Webinars Thursday 1 pm CST

                        Occam's Razor - KISS
                        Normalize till it hurts - De-normalize till it works.
                        Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
                        When we triage a problem it is much easier to read sample systems than to read a mind.
                        "Make it as simple as possible, but not simpler."
                        Albert Einstein

                        http://www.iadn.com/images/media/iadn_member.png

                        Comment


                          #13
                          Re: syntax problem using eval()

                          I created a tmp table with one field, fldname. in it, I entered reason, which is a fieldname in my attend table.

                          when I ran this code, txt contained "Vacation" which is the value of the reason field in the first record in my attend table. is that what you're trying to achieve here?

                          Code:
                          dim tmp as p
                          dim thf as p
                          dim txt as c
                          thf =table.open("Attend")
                          tmp= table.open("tmp")
                          
                          tmp.fetch_first()
                          while .not. tmp.fetch_eof()
                          	txt = eval("thf." + tmp.fldname)
                          end while
                          thf.close()
                          tmp.close()

                          Comment


                            #14
                            Re: syntax problem using eval()

                            Originally posted by Stan Mathews View Post
                            Robin,

                            You may have a logic issue but I am still struggling with the flow. Not a big fan of goto <label>.

                            If the first record has a valid fieldname you commit_flag = .t. and transfer the value to the appropriate field. I don't see where you reset commit_flag to .f. for the next loop. That should probably be done immediately after WHILE .not. tmp.fetch_eof().
                            The commit_flag is set to false by the error handler, but I can see that it makes more sense to set the flag to .f. before testing with eval_valid(). So far the only error that triggered was because of the one blank fldname.
                            Robin

                            Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

                            Comment


                              #15
                              Re: syntax problem using eval()

                              Originally posted by Al Buchholz View Post
                              Robin

                              Consider adding some logging to this process to indicate what records are read and how they are processed.

                              If not forever, but at least during some extensive testing. Writing to a text file is fast and easy to monitor while a process is running.
                              The udf I have TLN() writes to the trace window with the name of the thf fieldname and the value of that field. I will comment that out once testing is done.

                              I do have another routine that creates an array of the data which I show to the user to confirm, I suppose I could do that here, but this is only for a report and the report preview should accomplish the same. If the data is not right the user can fix it and run the report again before printing. I added a linked field on the report that will take the user back to the input form.
                              Last edited by MoGrace; 02-17-2018, 12:44 PM.
                              Robin

                              Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

                              Comment

                              Working...
                              X