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

change type of field with code?

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

    change type of field with code?

    Hi all,

    stumped me on this one.

    Have a numeric field coming across from csv file as numeric. Works fine. I then have to change a couple of field names, and ok there. I need to change the miles field from numeric to character. I can do this manually, but need to be able to do it with code.

    Any help will be appreciated? I can't find a funtion for this.

    dave
    Dave Mason
    [email protected]
    Skype is dave.mason46

    #2
    Re: change type of field with code?

    Not sure why you "need" to change the field type but I suggest you add a character field, update it with alltrim(str()) of the numeric field.
    There can be only one.

    Comment


      #3
      Re: change type of field with code?

      Hi Dave,

      Originally posted by DaveM View Post
      Hi all,

      stumped me on this one.

      Have a numeric field coming across from csv file as numeric. Works fine. I then have to change a couple of field names, and ok there. I need to change the miles field from numeric to character. I can do this manually, but need to be able to do it with code.

      Any help will be appreciated? I can't find a funtion for this.

      Use STR() to convert numeric to string/character, and LTRIM() to trim leading spaces.

      Easiest way is to have a numeric and character version of field and update from one to the other.

      You can also use an append operation, where you can define an append expression.

      If you want to restructure the file, you could create a new structure and copy the records, but I ahven't checked whether you can truly restructure a table in place via XBasic (although I suspect you could)
      Regards,

      Ira J. Perlow
      Computer Systems Design


      CSDA A5 Products
      New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
      CSDA Barcode Functions

      CSDA Code Utility
      CSDA Screen Capture


      Comment


        #4
        Re: change type of field with code?

        Hey guys,

        I didn't make it clear. I want to change a field type in a table from numb to char. I already know str().

        something like: a5.field_change_name() only I need a5.field_change_type()
        Dave Mason
        [email protected]
        Skype is dave.mason46

        Comment


          #5
          Re: change type of field with code?

          You made it perfectly clear but there is no way to do that directly.

          You can add a field (TABLE.ADD_FIELDS()), you can update a field with another field's contents, and you can then delete the original field (TABLE.DELETE_FIELDS()).
          There can be only one.

          Comment


            #6
            Re: change type of field with code?

            Dave:
            Why?
            What will you do with it after it becomes character?
            And can't you do the same with it being numeric with an expression?

            Messing with the table structure with xbasic is a BAD IDEA any way you look at it, doable or not doable.

            Comment


              #7
              Re: change type of field with code?

              Gabe,

              We were doing it with clipper in the 80's.

              I asked a couple years or so ago why we couldn't add fields and rename them and was told it was impossible with .dbf files to do this by people on this forum. Now we have some of the abilities.

              we can do it with the table structure, so why not with xbasic???

              If we cannot, I will live with it for now.

              Dave
              Dave Mason
              [email protected]
              Skype is dave.mason46

              Comment


                #8
                Re: change type of field with code?

                Hi Dave,

                Originally posted by DaveM View Post
                Gabe,

                We were doing it with clipper in the 80's.

                I asked a couple years or so ago why we couldn't add fields and rename them and was told it was impossible with .dbf files to do this by people on this forum. Now we have some of the abilities.

                we can do it with the table structure, so why not with xbasic???

                If we cannot, I will live with it for now.

                Dave
                I stated the answer earlier.

                If you want to restructure the file, you could create a new structure and copy the records
                This definitely works, as I've done it before. You get the structure of the original, change what you want, add indexes, copy whatever forms are required etc. It's a little more work, but it's not particularly hard.
                Regards,

                Ira J. Perlow
                Computer Systems Design


                CSDA A5 Products
                New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
                CSDA Barcode Functions

                CSDA Code Utility
                CSDA Screen Capture


                Comment


                  #9
                  Re: change type of field with code?

                  I am not saying you cannot do it, but just because you could does not mean you should.

                  Perserving the integrity of your data should be number one priority. You could loose your dictionary and rebuild it, loose you indices and rebuild them, loose scripts and rebuild them..etc but loosing data is fatal.

                  I am always reluctant to do anything with the table structure using xbasic for fear of any mishaps. If you have to, make sure you back up first.

                  I have added and deleted fields in test tables, but not in my actual tables. Since I am reluctant to do so in xbasic, I can't profess to have a lot of knowledge or experience in this, but you can add a character field to the table with xbasic and update it with the values from the numeric field.

                  I just think, it would be much more logical and streamlined to maintain the numeric field and convert the data to character in whichever subsequent processes you have to make.
                  Last edited by G Gabriel; 11-06-2007, 04:22 PM.

                  Comment


                    #10
                    Re: change type of field with code?

                    Originally posted by Stan Mathews View Post
                    You made it perfectly clear but there is no way to do that directly.

                    You can add a field (TABLE.ADD_FIELDS()), you can update a field with another field's contents, and you can then delete the original field (TABLE.DELETE_FIELDS()).
                    Originally posted by DaveM View Post
                    we can do it with the table structure, so why not with xbasic???

                    If we cannot, I will live with it for now.

                    Dave
                    If you watch what happens when the table structure is changed after you click save, Alpha does what Stan has described. (I don't know what that is not uncovered, but time and priorities come to mind.)

                    So Dave, write a function that looks like this:

                    chg_field_type(<fieldname>,<new_field_type>)

                    The function would then do what Stan has described.

                    tempf_newtype, update the value in tempf_newtype, remove <fieldname>, rename tempf_newtype to <fieldname>

                    Then post it in the code archive for others to use.
                    :)
                    Al Buchholz
                    Bookwood Systems, LTD
                    Weekly QReportBuilder Webinars Thursday 1 pm CST

                    Occam's Razor - KISS
                    Normalize till it hurts - De-normalize till it works.
                    Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
                    When we triage a problem it is much easier to read sample systems than to read a mind.
                    "Make it as simple as possible, but not simpler."
                    Albert Einstein

                    http://www.iadn.com/images/media/iadn_member.png

                    Comment


                      #11
                      Re: change type of field with code?

                      If you write such function, by all means, make sure the first line backs up the table.

                      Comment


                        #12
                        Re: change type of field with code?

                        Hi Dave,

                        I reread all the posts but did not notice table.restructure() mentioned. Seems to do what you want.

                        http://support.alphasoftware.com/alp...TRUCTURE().htm
                        Mike
                        __________________________________________
                        It is only when we forget all our learning that we begin to know.
                        It's not what you look at that matters, it's what you see.
                        Henry David Thoreau
                        __________________________________________



                        Comment


                          #13
                          Re: change type of field with code?

                          By golly, I think you've got it. Looks to be tedious to construct and later modify if necessary, and certainly overkill, but it should work.
                          There can be only one.

                          Comment


                            #14
                            Re: change type of field with code?

                            Mike:
                            Nice research. When I first read Dave's thread, something in the back of my mind tells me I read somewhere about a restructure but couldn't remember it. It's nice to know it's there, but personally, I wouldn't use it and am glad to forget it.

                            Structuring and re-stucturing tables should be something you do very rarely and shouldn't be a matter of routine that requires a script. It's playing with fire.

                            Comment


                              #15
                              Re: change type of field with code?

                              thanks to Mike C.

                              that is what I am looking for.

                              gabe, the restructuring of this table is of no consequence to the rest of the db. It is a temp table, but I am having to do the str() more than I should, and already having to change field names. It makes more sense to do it all in one step. If I lose this data, I just reruna function to recreate the table with data included.

                              It is nice to know that no udf will be needed for this one.

                              Dave
                              Dave Mason
                              [email protected]
                              Skype is dave.mason46

                              Comment

                              Working...
                              X