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

Update ux controls in a for loop

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

    Update ux controls in a for loop

    Hi,
    In unix, I think there is a command eval() that executes command that needed to be parsed before execution.

    In AA, I have several controls (static text) that I have defined consecutively with a named div i.e. q01, q02...
    I need to set the innerhtml for these controls in a loop filling in the name (div id) of the control programatically


    Code:
    for i = 1 to jp.result.random.data.size()
    	e._setElement.[COLOR="#FF0000"]DIV1[/COLOR].value = "Some text" --- sets the innerHTML of DIV with the id of 'DIV1'
    next i
    how do I substitute DIV1 got from the example notes to work with my number of controls?
    I have tried

    e._setElement.q0+i+.value = "Some text" with no joy.

    Thanks.
    Regards,

    Kotin Karwak
    Developer Edition
    Version 12.3 Build 2684
    System Addins: Build 4438
    Build machine Windows Vista
    Skype: mateso08

    #2
    Re: Update ux controls in a for loop

    i would try

    e._setElement.q0+alltrim(str(i))+.value = "Some text" with joy.
    Win 10 64 Development, Win 7 64 WAS 11-1, 2, Win 10 64 AA-1,2, MySql, dbForge Studio The Best MySQL GUI Tool IMHO. http://www.devart.com/dbforge/mysql/studio/

    Comment


      #3
      Re: Update ux controls in a for loop

      Frank,
      Had some joy now but from a different implementation.
      The suggested did not work but a better construct than I was using in case of blank spaces


      Code:
      cc = "e._set.STATICTEXT_"+ i + ".value = "+ jp.result.random.data.[i]    'using object name
      evaluate_template(cc)

      Creating a string with substitutions done and use evaluate_template(), similar to what the world of unix does.

      Have now included the trim as follows

      Code:
      cc = "e._setElement.q0"+ alltrim(str(i)) +".value = "+ jp.result.random.data.[i] 'using div id. Note need to test in live preview, working preview doesn't show as expected?!
      evaluate_template(cc)
      Regards,

      Kotin Karwak
      Developer Edition
      Version 12.3 Build 2684
      System Addins: Build 4438
      Build machine Windows Vista
      Skype: mateso08

      Comment


        #4
        Re: Update ux controls in a for loop

        Originally posted by kotinkarwak View Post
        Frank,
        Had some joy now but from a different implementation.
        The suggested did not work but a better construct than I was using in case of blank spaces


        Code:
        cc = "e._set.STATICTEXT_"+ i + ".value = "+ jp.result.random.data.[i]    'using object name
        evaluate_template(cc)

        Creating a string with substitutions done and use evaluate_template(), similar to what the world of unix does.

        Have now included the trim as follows

        Code:
        cc = "e._setElement.q0"+ alltrim(str(i)) +".value = "+ jp.result.random.data.[i] 'using div id. Note need to test in live preview, working preview doesn't show as expected?!
        evaluate_template(cc)
        "jp.result.random.data.[i]" looks strange to me. I've not seen anything indexed using .[i]. Put a debug(1) just before your cc and see what you're getting. There could be an error.
        Alpha Anywhere latest pre-release

        Comment


          #5
          Re: Update ux controls in a for loop

          Both syntax with a dot and without shown to work. Didn't pick on that since I just copied the debug output into the code.
          Thanks

          Alpha_note_00.jpg


          Let me also dump the whole code used in this learning exercise, Have commented it as much as possible and might help someone figure out xbasic syntax etc etc. If any explanation is needed, please do ask.

          Code:
          function loadQuestions as c (e as p)
          
          '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
          ' 	Call function (RandNums) to fetch random set of data to correspond to the question id's that need to be displayed. 
          '	Function arguments
          '//Bookmark1: data conversion, strings to numeric
          '		(1) Number of items to return. This corresponds to the drop down selection from UX. Note the conversion performed to ensure its fed in as a numeric
          '		(2) Min value for the id
          '		(3) Max value for the id.
          '	Assumptions: Database table holds sequential id's that are complete else checks might be needed to confirm if record exists in the database
          '
          '	returned value: {"jsonrpc":"2.0","result":{"random":{"data":[10332,10308,10255,10321,10335,10289,10282,10281,10339,10313],"completionTime":"2015-06-10 19:17:38Z"},"bitsUsed":66,"bitsLeft":249406,"requestsLeft":991,"advisoryDelay":0},"id":630}
          
          '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
          dim cima as c
          cima = RandNums(a5_convert_type(e.dataSubmitted.QNUM  ,"numeric"),10248,10347)		
          
          ' extract data returned by function
          dim jp as p 
          jp = json_parse(cima)
          
          'jp.result.random.data			'{[1]=10290,[2]=10248,[3]=10260,[4]=10339,[5]=10318,[6]=10296,[7]=10253,[8]=10258,[9]=10294,[10]=10307}
          '?jp.result.random.data.size() 	'returns the number of it items in array.
          
          dim keys as c
          dim cc as c
          
          
          debug(1)
          
          for i = 1 to jp.result.random.data.size()
          	keys = keys + jp.result.random.data.[i] + ", " 
          next i
          
          keys = rtrim(keys,",")
          
          '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
          ' start of SQL run
          ' With the keys available in variable (keys), connect to database and read associated record.
          ' The WHERE xxxx IN () clause works with direct assignment of data, sql arguments failed to execute.
          '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
          	dim conn as sql::Connection
          	dim rs as sql::Resultset
          	dim flag as l
          	dim sqlStmt as c
          	dim js as c
          	dim args as sql::Arguments
          	
          	flag = conn.Open("::Name::conn_northwind")
          	
          	if flag = .f. then
          		js = "alert('Could not connect to database. Please contact support team.');"
          	else
          		js = "alert('Connected to database ok');"
          	end if
          	
          	sqlStmt = "SELECT OrderID,CustomerID,ShipName FROM orders WHERE OrderID IN ("+ keys +" );"
          	
          	'conn.PortableSQLEnabled = .t.
          	
          	flag = conn.Execute(sqlStmt)
          	
          	if flag = .f. then
          		js = "alert('Could not execute query. Error: " + js_escape(conn.CallResult.text) + "');"
          		conn.Close()
          	else
          		js = "alert('Connection and SQL execution ok');"
          	end if
          	
          	rs = conn.ResultSet
          	
          	dim json as c
          	json = rs.ToJSONObjectSyntax()
          	
          	json = "[" + crlf_to_comma(json) + "]"
          					
          	dim ns[0] as p
          	a5_JSON_PopulateArray(ns,json)
          '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
          'end of SQL run
          '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
          
          dim random_org_item as c
          dim database_read_item as c
          
          for i = 1 to jp.result.random.data.size()
          '//Bookmark2: Change object data/content using the object id. few lines below shows similar but utilizing div id.
          	cObjectID = "e._set.STATICTEXT_"+ alltrim(str(i)) + ".value = "+ jp.result.random.data.[i]
          	random_org_item = jp.result.random.data.[i]
          	
          	for x = 1 to ns.size()
          		database_read_item = ns[x].OrderID 			'needed these variables since direct comparison didn't work:- if ns[x].OrderID = jp.result.random.data.[i] then
          		if random_org_item = database_read_item then
          			cdivID = "e._setElement.DIV"+alltrim(str(i)) + ".value = \""+ ns[x].OrderID + ", "+ ns[x].CustomerID +", "+ ns[x].ShipName + "\""
          			exit for	
          		end if
          	next x
          		
          	evaluate_template(cdivID)
          	evaluate_template(cObjectID)
          	
          	'NOTES from http://www.alphasoftware.com/alphaforum/showthread.php?85525-Using-variable-value-in-Statement&highlight=execute+code+block
          next i
          
          'Temporary show data returned JSON from random.org in the statictext object id: temporaryData
          e._set.temporaryData.value = cima
          
          'loadQuestions = js	'error handling commented out
          
          end function 
          
          
          
          '------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
          '																														'
          'Fetch a dynamic set of random numbers from a given startingpoint and endpoint. The set totals also determined by the calling function, i.e. return 5,7,15,20 numbers. 	'
          '																														'
          '------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
          function RandNums as c (vMyNum AS N,vMyMin AS N,vMyMax AS N)
          	DIM vp as p
          	DIm vurl as c
          	DIM vbody as c
          	DIM vresponse as c
          	DIM vReturn as c
          	'vurl = "http://www.random.org/integers/?num="+vMyNum-"&min="+vMyMin-"&max="+vMyMax-"&col=1&base=10&format=plain&rnd=new"
          	'vurl = "https://www.random.org/integer-sets/?sets=1&num=5&min=10248&max=10347&seqnos=on&commas=on&sort=on&order=index&format=html&rnd=new"
          	
          	vurl = "http://api.random.org/json-rpc/1/invoke"
          
          	vbody = <<%str%
          	{
          	    "jsonrpc": "2.0",
          	    "method": "generateIntegers",
          	    "params": {
          	        "apiKey": "71492e94-699d-4968-900d-b497zcb20c6f",
          	        "n": returnCount,
          	        "min": minValue,
          	        "max": maxValue,
          	        "replacement": false,
          	        "base": 10
          	    },
          	    "id": 630
          	}
          	%str%
          	vbody = stritran(vbody,"returnCount",str(vMyNum))		'use str() to convert numerics to strings. substitute items in the body to be used in http_post
          	vbody = stritran(vbody,"minValue",str(vMyMin))	
          	vbody = stritran(vbody,"maxValue",str(vMyMax))
          	
          	
          	vp = http_post(vurl,vbody,"",80,2800,.f.,.f.)				'port number 80, ssl sets to 443 on this dev machine but issues with security hence retain http and not https access.
          	
          	vresponse = *HTML_TO_PLAIN(vp.body)
          	
          	if left(vresponse,10) = "RANDOM.ORG" then
          	    vReturn = "Error! Please try again"
          	else
          		vReturn = alltrim(vresponse)
          	end if
          	
          	RandNums = vReturn
          	
          	'returned content as follows
          	'{"jsonrpc":"2.0","result":{"random":{"data":[10332,10308,10255,10321,10335,10289,10282,10281,10339,10313],"completionTime":"2015-06-10 19:17:38Z"},"bitsUsed":66,"bitsLeft":249406,"requestsLeft":991,"advisoryDelay":0},"id":630}
          
          end function
          Regards,

          Kotin Karwak
          Developer Edition
          Version 12.3 Build 2684
          System Addins: Build 4438
          Build machine Windows Vista
          Skype: mateso08

          Comment

          Working...
          X