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

Random record selection

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

    Random record selection

    I am trying to extract a random record from the quotes table.
    See attached sample

    I am doing it from the mainmenu form.
    I set up a set of steps in the calculated variables to do it.

    VquoteNo = rand()*100
    vid = int(calc->VquoteNo)/10
    VidChar = "00"+alltrim(Str(calc->vid))
    vquote = LOOKUP("quotes.dbf","id ="+QUOTE(calc->VidChar),"qte")


    Questions:
    Is there a more direct or more efficient way to apply the random extraction from the quotes table to the variable vquote?

    The problem is the issue of the "00", it will be a limitation.

    #2
    Re: Random record selection

    I created a random number generator function a couple weeks ago. You could simply make the functions parameters equal to the following and then get a random record number in return and then use that number to bring up the record on a form...

    So Import the function below that I created which allows you to generate a true random number using the random.org API. Be Sure to name the Function "RandNums"
    1.)Goto the control panel and select the "code" tab
    2.)Press the "New" button at the top of the control panel window
    3.)Select the "Function" from the drop down list
    4.)Enter the value "RandNums" in the Function Name field on the window that pops us
    5.)Press "Ok" on the new function window (just Leave the function Return Type as "Character")
    6.)Now a new window will popup in the code editor with the outline for a new function. Erase everything in that window and paste all of the code below
    7.) Hit the save button to save the new function you entered

    Code:
    'Date Created: 25-Jan-2011 04:28:47 PM
    'Last Updated: 08-Feb-2011 03:34:37 PM
    'Created By  : Lee Goldberg - Shore Consultants Ltd
    'Updated By  : Lee Goldberg - Shore Consultants Ltd
    
    FUNCTION RandNums AS C (vNumOfNums 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="+vNumOfNums-"&min="+vMyMin-"&max="+vMyMax-"&col=1&base=10&format=plain&rnd=new"
    	vbody = "" 
    	vp = http_post(vurl,vbody,"",80,2800,.f.)
    '	msgbox("vp",vp.body)
    	
    	vresponse = *HTML_TO_PLAIN(vp.body)
    	
    	if left(vresponse,10) = "RANDOM.ORG" then
    	    msgbox("Error!","Parameters do not meet criteria")
    	    vReturn = "Error! Please try again"
    	else
    		vReturn = alltrim(vresponse)
    	end if
    	
    	RandNums = vReturn
    END FUNCTION

    Now, add a new xBasic Script (Using xBasic Editor) on the "code" tab in the control panel (Select the "New" button->then select "Script(Using xBasic Editor)" )and add copy and paste the code in the box below to your new xBasic Script. You can Save this code with whatever name you want. Use This name to referenced the code on the OnClick action of a button placed on a form you want to preform this action. You can also use it however you would like.

    Code:
    'Date Created: 08-Feb-2011 03:34:59 PM
    'Last Updated: 08-Feb-2011 03:34:59 PM
    'Created By  : Lee Goldberg - Shore Consultants Ltd
    'Updated By  : Lee Goldberg - Shore Consultants Ltd
    DIM pFrmMyFrm as p 'Pointer to the form you want to open to show the random record 
    DIM vRandRecNo as N  'The Value the function will return
    DIM vRandNums as N 'How many random numbers you want the function to return.  In this case you just want one number
    DIM vMinimum as N 'The minimum number the random generator can select from
    DIM vMaximum as N 'The maximum number the random generator can select from
    DIM vMyTblName as c 'The Name of the table you want a random record for
    DIM vMyFrmName as c 'The Name of the form you want to open to show the random record
    
    vMyTblName = "tbllotto" 'change the name to the table you want to select the random record from
    vMyFrmName = "lotto" 'change this to the name of the form you want to show the random record you will generate below
    vRandNums = 1 'is "1" because you only want one record number to be returned. (function can return more than one)
    vMinimum = 1 'you can make this higher depending on if you only want the random number to be selected from a certain range of records
    vMaximum = tablecount(alltrim(vMyTblName),".t.")
    
    'Stores the random number returned by the RandNums function in the variable vRandRecNo for later use
    'RandNums can return a string of random numbers (but this case just one number)
    'So RandNums function will return a single integer value that is 
    'greater than or equal to vMinimum and less than or equal to vMaximum (as defined above)
    
    vRandRecNo = val(RandNums(vRandNums,vMinimum,vMaximum)) 'Returns a random Number from the RandNums Function and uses the Val() function to make the char string it returns numeric type
    
    'Show the random selected record number to the user
    msgbox("Random Record #","Random Record Number: "+crlf(2)+"    "+alltrim(str(vRandRecNo))+" of the " + alltrim(str(vMaximum))+" totals records in the table "+alltrim(vMyTblName))
    
    'Here you can open a form that shows the records from the table you selected
    
    'First load (open) the form and reference it to the variable fMyFrm for later manipulation
    'Then clear the form of any current queries that may prohibit the from from showing the random record
    'then tell the form to Goto the random record number
    'then repaint (or refresh) the form so that it shows the user the random record number we just told it to goto.
    
    pFrmMyFrm = form.load(alltrim(vMyFrmName))
    pFrmMyFrm.Query_Clear()
    pFrmMyFrm.Recno_goto(vRandRecNo)
    pFrmMyFrm.Repaint()
    
    'End of Code
    'let me know if you have any questions
    '[email protected]
    Hope this helps
    Last edited by goldberg2727; 02-08-2011, 05:13 PM.
    Lee Goldberg
    Software Development and Sales
    Shore Consultants Ltd.
    [email protected]
    www.shorecon.com

    Comment


      #3
      Re: Random record selection

      Thanks for the response. I will try it.
      I did respond to this was because, I did not get an email that the thread was answered.

      Comment

      Working...
      X