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

Alpha Five tip: Assigning Images to Existing Records

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Alpha Five tip: Assigning Images to Existing Records

    Article written by Selwyn Rabins in response to a message from a customer.

    Assigning Images to Existing Records


    Say you have a database of employees, or customers, or students. You have a large number of existing records in your database, but currently you don't have a field in the record that shows an image of each person.

    Let's assume that you have a digital picture for all (or some) of the people. What's the best way of getting your existing images into your database (without doing a lot of manual work!).

    There are many ways in which this could be done. This article discusses one of the techniques.




    The first decision you have to make is what type of image field do you want to use. Alpha Five offers Jpeg, Bitmap and Image File Reference. The first two, Jpeg and Bitmap actually store the image in the table. The third type, Image File Reference, just stores the filename of the image in the table. The benefit of this is that your table file does not get bloated. Images files can be large, and you could quickly end up with a very large table file if you have many images.

    Note that the Jpeg field type is not limited to Jpeg images. It can store .jpg, .jpeg, .bmp and .png images. The field type refers to how Alpha Five stores the data internally, not to what types of images can be stored in the fields. Similarly for the Bitmap type. Image File Reference fields can also be used to reference any of the supported image types: Jpeg, Bmp and Png.

    For this article, we will use Image File Reference fields.

    In this article we will show you how to get your images 'into' your Alpha Five table.

    We will make the following assumptions:

    You have an existing table called 'Employees'.
    The table has (among others), a field called 'firstname' and a field called 'lastname'
    You have images for each employee and the image filenames are of the form 'image_firstname_lastname.jpg'. For example, the image filename for John Smith is called 'Image_John_Smith.jpg'.
    You have placed the images in a folder called 'Images' relative to the folder where your 'Employees' table is stored.
    The first step is to add a new field to your table. To do this:

    Right click on the table in the Tables/Sets tab of the Control Panel.
    Select the Edit Structure command
    Add a new field called 'Image' to the table and select the Image File Reference field type.
    Now, we have to populate this new 'Image' field with the filename of the image for each record.

    Obviously doing this by hand, one record at a time, would be hugely tedious. So, we are going to create an Xbasic script that will automate the process.

    Next, go to the Code tab in the Control Panel, click the 'New' button and create a new script (using the Xbasic editor). This will open up the Xbasic editor. Paste the code shown below in blue into the script editor. Save the script and give it any name you want.



    dim t as p
    t = table.open("employees")
    dim fn as c
    dim pathName as c
    dim image_filename_template as c
    dim imageFolderName as c
    imageFolderName = "Images"



    'This is the template that describes the format of your image filenames.


    image_filename_template = "Image_{alltrim(t.firstname)}_{alltrim(t.lastname)}.jpg"


    'The entries enclosed in { } are placeholders that refer to

    'fieldnames in your table.
    'Notice that the field placeholders in the template are prefixed with 't.'.
    'That's because the the table pointer that we opened is called 't'.
    'It is important that the template use the same name as the table pointer

    'at the start of the script!

    'So, for a record where firstname was 'John' and lastname was 'Smith'

    'the image filename would be Image_John_Smith.jpg.

    'You can define any format that you want.

    'get the folder where the table is stored.
    pathName = file.filename_parse(t.filename_get(),"dp")
    dim imageName as c
    t.fetch_first()
    dim totalcount as n
    totalcount = t.records_get()
    dim count as n = 0
    while .not. t.fetch_eof()
    count = count +1
    statusbar.Set_Text("Updating " + count + " of " + totalcount)
    imageName = imageFolderName + chr(92) +\

    evaluate_string(image_filename_template)



    'Only update the record if the imageName file actually exists.

    'Note that we need to add in the pathName of the table to

    'get a fully qualified filename before we check to see if it exists.
    if file.exists(pathName + imageName) then
    t.change_begin()



    'Notice that we only store the relative filename of the image.

    'This means that it will work if we move the location of the

    'table and the images sub-folder.
    t.Image = imageName


    t.change_end(.t.)
    end if
    t.fetch_next()
    end while
    t.close()
    ui_msg_box("Done","Updated " + count + " records.")


    The code is commented, but let's take a look at some of the key parts of it so that you can modify it for your own use.

    Firstly, it is likely that in your own case, your naming convention for the image filenames will be different than simply Image_Firstname_Lastname. Your image filenames might reference an employee id, for example.

    You will see that the script contains this line:

    image_filename_template = "Image_{alltrim(t.firstname)}_{alltrim(t.lastname)}.jpg"


    This is the format that describes how the image filenames are constructed. Our script uses a powerful Xbasic function, evaluate_string() which evaluates expressions that are enclosed in curly brackets in a string.

    You will notice that the template includes "t." in front of the fieldnames. That's because when the script opens the employees table, the table pointer name we use is 't'. So, the expression 'alltrim(t.firstname)' might evaluate to 'John' for the first record, and 'Fred' for the second record, and so on.

    Notice also that the template does an alltrim() around each of the fields. That's because otherwise the data would contain trailing spaces in it, which would mess up our filenames.

    If your table had a field called 'employeeid' (assumed to be a character field) and your image filename format was Image_employeeid.jpg (e.g. Image_032343.jpg), then you would change the image_filename_template to be:

    image_filename_template = "Image_{alltrim(t.employeeid)}.jpg"


    If employeeid was a numeric field, then your template would be (without the alltim() function):

    image_filename_template = "Image_{t.employeeid}.jpg"


    After the script has computed the image filename for the current record, it checks to see if this file actually does exists. If so, then it puts the record into change mode and updates the image field.

    Notice that we store a relative filename in the field (e.g. images\image_john_smith.jpg). This makes the table portable. If you move the table (and the subfolder of images) to another folder on your machine, the Linked Images will still display correctly.
    Richard Rabins
    Co Chairman
    Alpha Software

  • #2
    Re: Alpha Five tip: Assigning Images to Existing Records

    TNX Richard
    Have just updated all 20,000+ records with the above script adapted to insert a File pathname derived from global variables initiated through an apps settings table run by the autoexec script. This gives the path pointer as a string, to a scanned pdf copy (where valid) of "paper" received at the factory office and stored on a shared drive.
    “There is nothing like a dream to create the future.”
    But then again:
    Basic research is what I am doing when I don't know what I am doing and to steal ideas from one person is plagiarism; to steal from many is research!

    Comment


    • #3
      Re: Alpha Five tip: Assigning Images to Existing Records

      Glad this was helpful Chris. I guess it beats do this 20,000 times manually:)

      As an observation, at Alpha, we strive to find menu driven ways (such as genies or components or action scripting etc) to simplify tasks and make them as easy as possible.

      However, this example above, illustrates the benefits and advantages of also having a powerful langauge like xBasic, that empowers one to do exactly what you want when the need arises.
      Richard Rabins
      Co Chairman
      Alpha Software

      Comment


      • #4
        Re: Alpha Five tip: Assigning Images to Existing Records

        AND with the beauty of action scripting I achieved the same for a membership system with:

        a5.get_path()+chr(92)+"images"+chr(92)+alltrim(UID)+".jpg"

        Where the field UID (unique identifier is an 8 character field containing a "number" in the form "00001234") The images are named "00001234.jpg" and stored in a sub folder called "images".

        The only thing this does not do is check to see if there is an image for a particular record but I guess if needed that could be added in a filter.

        Regards

        Glen
        Glen Schild



        My Blog

        Comment

        Working...
        X