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

xbasic code to read through a data file

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

    xbasic code to read through a data file

    i like to read a file in xbasic and change a few fields.
    basically my code in Clarion is this

    Open(filename)
    loop until eof(filename)
    next(filename) ! GETS THE NEXT RECORD
    if field1 = '' then field1='N'
    if field2 = '' then field2 ='N'
    put(filename) ! writes record changes to the table
    end
    close(filename)

    quite simple but just getting my feet wet with xbasic.

    thank you
    Raul Rego

    #2
    Re: xbasic code to read through a data file

    Are you wantting open a text type file or are you wanting to edit a table
    -----------------------------------------------
    Regards
    Mark Pearson
    [email protected]
    Youtube channel
    Website

    Comment


      #3
      Re: xbasic code to read through a data file

      Since files other than tables don't have fields, let's assume you mean a dbf table.

      Code:
      tbl = table.open("filename") 'Open(filename)
      tbl.fetch_first()'goto first record
      while .not tbl.fetch_eof() 'loop until eof(filename)
      'nothing here, haven't processed the first record yet, don't want to move to the second record 'next(filename) ! GETS THE NEXT RECORD
      if tbl.field1  = "" 'if field1 = '' then field1='N'
      tbl.change_begin() 'begin the change
      tbl.field1 = "N"
      tbl.change_end (.T.) 'commit the change
      end if
      if tbl.field2 = "" 'if field2 = '' then field2 ='N'
      tbl.change_begin()
      tbl.field2 = "N"
      tbl.change_end(.T.)
      'nothing here, performed with .change_begin() and .change_end() methods 'put(filename) ! writes record changes to the table
      tbl.fetch_next() 'now move to the next record
      end while 'end
      tbl.close() 'close(filename)
      There can be only one.

      Comment


        #4
        Re: xbasic code to read through a data file

        Raul, there are a number of xbasic examples in the programming puzzles I've been posting to the General Questions Forum. You may find them useful as you climb the xbasic learning curve.

        Comment


          #5
          Re: xbasic code to read through a data file

          Nice Stan, and see, you dont do all that work for nothing - I'm also paying attention

          Code:
          tbl = table.open("filename") 		'Open(filename)
          tbl.fetch_first()'goto first record
          while .not tbl.fetch_eof() 		'loop until eof(filename)
            if tbl.field1  = ""			
          	tbl.change_begin() 		'begin the change
          	tbl.field1 = "N"
          	tbl.change_end (.T.) 	        'commit the change
            end if
            if tbl.field2 = "" 
          	tbl.change_begin()
          	tbl.field2 = "N"
          	tbl.change_end(.T.)
            [COLOR="#FF0000"]end if[/COLOR]
            tbl.fetch_next() 'now move to the next record
          end while                                    'end
          tbl.close()

          Comment


            #6
            Re: xbasic code to read through a data file

            Thanks Ray.
            There can be only one.

            Comment


              #7
              Re: xbasic code to read through a data file

              My question here is "why wouldn't you do an "UPDATE" operation?" and set the condition on the field? I like writing xbasic as much as the next one, but the tools are there for those who don't want to write the code.

              Tom

              Comment


                #8
                Re: xbasic code to read through a data file

                Good point, Tom but I think he's trying to learn xbasic. It could have been pointed out that Alpha has easier ways to accomplish the end result.
                There can be only one.

                Comment


                  #9
                  Re: xbasic code to read through a data file

                  I'm coming to this a bit late but there is no need to start the change twice. A simple test on a simple table indicated that it took about 60% longer that way - assuming both fields need to be changed. The difference could be a much greater than that if there are a lot of records and/or indexes because A5 will update any affected indexes every time a change ends. (Unless you use batch_begin/end() but that's another story.)

                  Also, just an FYI, there is nothing wrong with using the .T. in the change_end() but it isn't necessary - it's the default anyway. The only real advantage I've ever found for using that argument is when I want to use a "save_flag" variable for development purposes so I can run the routine for debugging without actually saving any data. If there is a need to decide whether or not to save something in the finished routine, that can be done before starting the change/enter in the first place.

                  When I use a save_flag I put it at the top of the script so it's easy to find. In other words...

                  save_flag = .F. 'set to .T. before distributing.
                  ...
                  tp.change_end( save_flag )
                  ...
                  tpd.change_end( save_flag )
                  ...

                  Of course, I generally only use a save flag on longer scripts where there are multiple possible change/enter operations. It doesn't make much sense on short scripts with only one change/enter .

                  Here's my method:

                  Code:
                  tbl = table.open("filename")         'Open(filename)
                  tbl.fetch_first()     'goto first record
                  WHILE .not. tbl.fetch_eof()         'loop until eof(filename)
                      IF tbl.field1 = "" .or. tbl.field2 = ""
                          tbl.change_begin()         'begin the change
                          IF tbl.field1 = ""
                              tbl.field1 = "N"
                          END IF
                          IF tbl.field2 = ""
                              tbl.field2 = "N"
                          END IF
                          tbl.change_end()
                      END IF
                      tbl.fetch_next()     'now move to the next record
                  END WHILE 'end
                  tbl.close()

                  Comment


                    #10
                    Re: xbasic code to read through a data file

                    Originally posted by Tom Henkel View Post
                    My question here is "why wouldn't you do an "UPDATE" operation?" and set the condition on the field? I like writing xbasic as much as the next one, but the tools are there for those who don't want to write the code.

                    Tom
                    Tom, thanks. I sort of want to learn Xbasic. In Clarion it was easy to learn the language because as I created a screen or browse in GUI, Clarion generated the code; this doesnt seem to be the case in Alpha unless I am missing something obvious.

                    BUT, getting back to the learning process, how do you use "UPDATE"?

                    thanks

                    Comment


                      #11
                      Re: xbasic code to read through a data file

                      You do the same to create a screen or browse - in GUI
                      What you want to do is an operation on data in a table.

                      In the Control Panel, click tab OPERATIONS, select NEW, choose type of operation - Update Records
                      Select the table you want to use and fill in the rest.
                      The code that is produced, if you wish, is also available

                      You may want to do some reading and try stuff out first as much as possible, otherwise answers to your questions could become a long slow tutorial. Try to use the Interactive window, and the help examples provide code snippets.

                      and Welcome.

                      Comment


                        #12
                        Re: xbasic code to read through a data file

                        Originally posted by Tom Cone Jr View Post
                        Raul, there are a number of xbasic examples in the programming puzzles I've been posting to the General Questions Forum. You may find them useful as you climb the xbasic learning curve.
                        Tom. How about a link(s) to what you've posted in the GQF section. I could really use some end-to-end examples for web-based Alpha v11 applications.

                        By 'end-to-end' I mean What type of object to create; Which object options to click; Where to paste the Xbasic code?

                        Thank you!

                        Comment


                          #13
                          Re: xbasic code to read through a data file

                          Daniel,

                          The Programming Puzzles forum was created after the post you reference. The message board folks moved my puzzles from the GQF to the Programming Puzzles forum, not sure what links you now would like to see?
                          Last edited by Tom Cone Jr; 02-13-2012, 09:27 AM.

                          Comment

                          Working...
                          X