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

Why is "While" not completing properly

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

    Why is "While" not completing properly

    I have been practising writing some code.

    This is the code I have written...

    Code:
    'Date Created: 06-Aug-2011 11:04:27 PM
    'Last Updated: 07-Aug-2011 01:17:42 AM
    'Created By  : weiyentan
    'Updated By  : weiyentan
    'This script goes thru all the contacts and enters the contact id to the transaction table.
    dim contacttbl as p
    dim transtbl as p
    
    contacttbl =  table.open("contact")
    transtbl = table.open("transactions")
    
    
    contacttbl.fetch_first()
    
    WHILE .not. contacttbl.fetch_eof()
    	SELECT
    		CASE contacttbl.type = "Client"
    			transtbl.enter_begin()
    			transtbl.contactid = "contacttbl.contactid_field.value"
    			transtbl.description = "Subscription Fee"
    			transtbl.flddebit = 50
    			transtbl.enter_end(.T.)
    		CASE contacttbl.type = "Supplier"
    			
    			transtbl.enter_begin()
    			transtbl.contactid = "contacttbl.contactid_field.value"
    			transtbl.fldcredit = 100
    			transtbl.description = "Invoice"
    			transtbl.enter_end(.T.)						
    			
    		END Case
    
    END SELECT
    contacttbl.fetch_next()
    END WHILE
    
    transtbl.close()
    contacttbl.close()
    What I want it to do is go through the contact table records from top to bottom and then enter values into a transaction table for each contact. It checks to see a type of contact .. whether its a supplier or a client.

    If its a client then it writes subscription in the description field and 50 in the flddebit field
    If its a supplier then it writes invoice in the description field and 100 in the flddebit field.

    What I have noticed is that when it makes its evaluation. . .it will write the first record fine.

    If the type of the contact next record is different....then it stops.

    ie contact 1 = supplier the script will run onto the next record (completing the action in the transaction table)
    contact 2 = supplier the script will add that to the transaction table..
    contact 3 = client....the script will not add this record in at all and the script stops.

    I have attached the database for those that are interested to have a look. I would be most grateful.....and also..in the field that reads contactid in the code...how do I get that to have the contactid at the record the script is at...at the time?

    Your help is most appreciated.
    And thanks to Tom Cone Jr who has spent the time with me .... I have just started to grasp how the structure and flow of Xbasic works and eager to get my hands dirty.


    training database.zip

    #2
    Re: Why is "While" not completing properly

    Originally posted by Tanman View Post
    ...and also..in the field that reads contactid in the code...how do I get that to have the contactid at the record the script is at...at the time?

    transtbl.contactid = "contacttbl.contactid_field.value"

    should be

    transtbl.contactid = contacttbl.contactid_field.value

    the first writes the text "contacttbl.contactid_field.value" to the transtbl.contactid

    the second writes the contents of contacttbl.contactid_field.value to the transtbl.contactid

    I'll take a look at the sample.
    There can be only one.

    Comment


      #3
      Re: Why is "While" not completing properly

      Your attempt was not a bad effort.

      There is no End Case command in Alpha so that line was being interpreted as a simple End.

      If you remove that line your script will run normally. Note the use of contacttbl.contactid_field.value is also incorrect. The contactid field in the contact table is simply named contactid. After obtaining the contacttbl pointer you reference the field with contacttbl.contactid, not contacttbl.contactid_field.value
      I have attached a text file with a corrected script if you want to examine it after proceeding with your practice.


      training database - 08-06-2011 -1.txt
      There can be only one.

      Comment


        #4
        Re: Why is "While" not completing properly

        Thanks Stan!

        I went ahead and made those changes and it now works. I also added a line in there
        Code:
        transtbl.date = date()
        so it will enter the current date.

        I think I have one other validating rule to put in there...that is the code will check if the entry has not already been added with a record in the same year

        ie once the record has been added with 7/8/2011 date stamp, the rule will check if an existing record with the date stamp exists or not, and if it those goes to the end.

        I think an if then else method would be the right one to use but I will make a good go of it first before I write back again.

        Thanks once again.

        Comment


          #5
          Re: Why is "While" not completing properly

          I'm not clear what you mean by "goes to the end".

          You say...

          Code:
          ie once the record has been added with 7/8/2011 date stamp, the rule will check if an existing record with the date stamp exists or not, and if it those goes to the end.
          Once the record with 7/8/2001 date stamp is entered/added then yes, a record with the date stamp exists. I think what you want to do is check to see if a record with a particular date stamp exists, then decide whether or not to add a record. There's a function here that will help you with that if you are have trouble with that aspect.
          There can be only one.

          Comment


            #6
            Re: Why is "While" not completing properly

            Hi Stan,

            Wasn't so bad as I thought.

            Have wrote the amendments for the current year.

            Code:
            'Date Created: 06-Aug-2011 11:04:27 PM
            'Last Updated: 07-Aug-2011 10:30:19 AM
            'Created By  : weiyentan
            'Updated By  : weiyentan
            'This script goes thru all the contacts and enters the contact id to the transaction table.
            dim contacttbl as p
            dim transtbl as p
            
            contacttbl =  table.open("contact")
            [B]transtbl = table.open("transactions")
            
            transtbl.fetch_first()
            while .not. transtbl.fetch_eof()
            	
            	if year(transtbl.date) = year(now())then 
            		ui_msg_box("Rollover","The Rollover has been done, Please add transactions manually. ", UI_STOP_SYMBOL)
            end 
            	else
            	transtbl.fetch_next()
            	end if
            end while[/B]
            
            contacttbl.fetch_first()
            
            WHILE .not. contacttbl.fetch_eof()
            	
            	SELECT
            		CASE contacttbl.type = "Client"
            			transtbl.enter_begin()
            			transtbl.date =date()
            			transtbl.contactid = contacttbl.contactid
            			transtbl.description = "Subscription Fee"
            			transtbl.flddebit = 50
            			transtbl.enter_end(.T.)
            		CASE contacttbl.type = "Supplier"			
            			transtbl.enter_begin()
            			transtbl.date =date()
            			transtbl.contactid = contacttbl.contactid
            			transtbl.fldcredit = 100
            			transtbl.description = "Invoice"
            			transtbl.enter_end(.T.)						
            			
            	
            
            END SELECT
            contacttbl.fetch_next()
            END WHILE
            transtbl.batch_end()
            transtbl.close()
            contacttbl.close()
            It works! Had to revise a few things but it worked great in the end. Glad to put it somewhere else if it will help anybody.

            Comment


              #7
              Re: Why is "While" not completing properly

              Functional but possibly inefficient. If you create an index on the transactions date field, call it transyd, expression year(date) you can check the existence of the current year with one line. No need to fetch through records in the transactions table at all.

              Code:
              'Date Created: 06-Aug-2011 11:04:27 PM
              'Last Updated: 07-Aug-2011 10:30:19 AM
              'Created By  : weiyentan
              'Updated By  : weiyentan
              'This script goes thru all the contacts and enters the contact id to the transaction table.
              dim contacttbl as p
              dim transtbl as p
              
              contacttbl =  table.open("contact")
              transtbl = table.open("transactions")
              [COLOR="#FF0000"]if exist(year(now()),"transactions","Transyd")[/COLOR]
                   ui_msg_box("Rollover","The Rollover has been done, Please add transactions manually. ", UI_STOP_SYMBOL)
                   end 
              end if 
              contacttbl.fetch_first()
              transtbl.batch_begin()
              WHILE .not. contacttbl.fetch_eof()
              	
              	SELECT
              		CASE contacttbl.type = "Client"
              			transtbl.enter_begin()
              			transtbl.date =date()
              			transtbl.contactid = contacttbl.contactid
              			transtbl.description = "Subscription Fee"
              			transtbl.flddebit = 50
              			transtbl.enter_end(.T.)
              		CASE contacttbl.type = "Supplier"			
              			transtbl.enter_begin()
              			transtbl.date =date()
              			transtbl.contactid = contacttbl.contactid
              			transtbl.fldcredit = 100
              			transtbl.description = "Invoice"
              			transtbl.enter_end(.T.)						
              			
              	
              
              END SELECT
              contacttbl.fetch_next()
              END WHILE
              transtbl.batch_end()
              transtbl.close()
              contacttbl.close()
              There can be only one.

              Comment


                #8
                Re: Why is "While" not completing properly

                Thanks Stan,

                I am going to try this now and see how it works. I am getting the hang of this..its making more and more sense.

                Comment

                Working...
                X