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

  • MoGrace
    replied
    Re: syntax problem using eval()

    Here it is:

    Code:
    FUNCTION Tln AS A (Tmsg AS C, Tvar = null_value() AS A, Tpane = "USER" AS C )	
    'DESCRIPTION: formatting wrapper for trace.writeln()	
    	dim msg as a
    	'a null value is variable type 'Z'
    	if typeof(Tvar) = "Z" then
    		'no variable was passed, trace message only
    		msg = Tmsg
    	   	trace.WriteLn(msg,Tpane)	    
    	else
    		msg = Tmsg+": "+Tvar				
    		trace.writeln(msg,Tpane)
    	end if	
    	Tln=msg
    END FUNCTION
    If I want to use it to report a script error I use "ERROR" for TPANE and it creates a tab in the trace window.

    Leave a comment:


  • Al Buchholz
    replied
    Re: syntax problem using eval()

    Originally posted by MoGrace View Post
    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.
    TLN() is a user defined function?

    Is it shared somewhere?

    Leave a comment:


  • MoGrace
    replied
    Re: syntax problem using eval()

    Originally posted by gkeramidas View Post
    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()
    For Gary:
    testdata2.jpg
    Last edited by MoGrace; 02-17-2018, 12:26 PM.

    Leave a comment:


  • MoGrace
    replied
    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.

    Leave a comment:


  • MoGrace
    replied
    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.

    Leave a comment:


  • gkeramidas
    replied
    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()

    Leave a comment:


  • Al Buchholz
    replied
    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.

    Leave a comment:


  • Stan Mathews
    replied
    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().

    Leave a comment:


  • MoGrace
    replied
    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?

    Leave a comment:


  • gkeramidas
    replied
    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

    Leave a comment:


  • MoGrace
    replied
    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.

    Leave a comment:


  • Stan Mathews
    replied
    Re: syntax problem using eval()

    And now it works?

    Leave a comment:


  • MoGrace
    replied
    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

    Leave a comment:


  • Stan Mathews
    replied
    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.

    Leave a comment:


  • MoGrace
    replied
    Re: syntax problem using eval()

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

    testdata.jpg

    Leave a comment:

Working...
X