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

Selecting values from tables using xbasic

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

    Selecting values from tables using xbasic

    I've set up a table to show who is logged in and when they log out. I created a script named "Autoexec" to run when someone logs in, it enters a record into a table I have called "Logins", this table has four columns in it (PK_LOGIN_ID, USERNAME, LOGGED_IN, LOGGED_OUT) when the script runs it enters USERNAME = user_name() and LOGGED_IN = Now(). What I would like it to do after it enters the record is set a variable called "varLOGIN_ID" to be set to the entered record for the PK_LOGIN_ID.

    I then would like to set a script for "CanDatabaseClose" to set the LOGGED_OUT using the variable it created upon login. The problem I am having is:
    (1) Setting the variable to the logged in user.
    (2) Setting the CanDatabaseClose Script to update the LoggedOut field using the varibale as the record identifier.

    Heres the script in my AutoExec that I have running after the record gets entered (by the way I used action scripting for "Xbasic Enter new record" to enter the record), it is not setting the variable and is not running the query that I want, I am not sure what is wrong here.
    Code:
    dim tbl as P
    dim qry as P
    dim run as P
    tbl = table.open("LOGINS")
    
    query.filter = "USERNAME = USER_NAME()"
    query.order = "invert(pk_login_id)"
    qry = tbl.query_create()
    run = qry.records_get()
    dim LOGIN_ID as N
    
    tbl.fetch_first()
    while .not. tbl.fetch_eof()
    	LOGIN_ID = tbl.pk_login_id
    	tbl.fetch_next()
    end while
    
    run.close()
    tbl.query_detach()
    tbl.close()
    
    DIM varLOGIN_ID AS N
    varLOGIN_ID = LOGIN_ID
    As for the CanDatabaseClose script, I have not set it up since I am not sure how to?

    #2
    Re: Selecting values from tables using xbasic

    query.filter = "USERNAME = USER_NAME()"

    should probably be

    query.filter = "USERNAME = "+quote(USER_NAME())
    There can be only one.

    Comment


      #3
      Re: Selecting values from tables using xbasic

      Thanks for the reply Stan. Now when I log into my database, it tells me "run.close(): Argument is incorrect data type". Do I need this in my code? I am not very familiar with desktop as I have been building mostly web apps.

      Comment


        #4
        Re: Selecting values from tables using xbasic

        run = qry.records_get()

        You are assigning a numeric value to the run variable which you have dimmed as P. I am unclear about what the .close() is supposed to do.

        You are probably attempting to close the query you have run. That query can be accessed with the pointer variable used to create it (qry). I also notice you are not using the query.filter and query.order variables you have assigned.

        Try your script as

        Code:
        dim tbl as P
        dim qry as P
        dim run as N
        tbl = table.open("LOGINS")
        
        query.filter = "USERNAME = "+quote(USER_NAME())
        query.order = "invert(pk_login_id)"
        qry = tbl.query_create("N",query.filter,query.order)
        run = qry.records_get() 'not sure why you want this number
        dim LOGIN_ID as N
        
        tbl.fetch_first()
        while .not. tbl.fetch_eof()
        	LOGIN_ID = tbl.pk_login_id
        	tbl.fetch_next()
        end while
        
        qry.close()
        tbl.query_detach()
        tbl.close()
        
        DIM varLOGIN_ID AS N
        varLOGIN_ID = LOGIN_ID
        There can be only one.

        Comment


          #5
          Re: Selecting values from tables using xbasic

          To my way of thinking there should only be one record in the logins table for each user. If that is the case you can do something like this (no need to loop through the table with a while loop).

          Code:
          dim tbl as P
          dim qry as P
          dim run as N
          tbl = table.open("LOGINS")
          
          query.filter = "USERNAME = "+quote(USER_NAME())
          query.order = "invert(pk_login_id)"
          qry = tbl.query_create("N",query.filter,query.order)
          run = qry.records_get()
          if run > 0 'the query found a record for the user
          	dim LOGIN_ID as N
          	LOGIN_ID = tbl.pk_login_id
          else
          	'assign some value to indicate the user was not found
          	LOGIN_ID = "No ONE"
          end if
          qry.close()
          tbl.query_detach()
          tbl.close()
          
          DIM varLOGIN_ID AS N
          varLOGIN_ID = LOGIN_ID
          There can be only one.

          Comment


            #6
            Re: Selecting values from tables using xbasic

            Stan, I am not sure why I would need that also. I think I may have added it in because I was trying a host of information I found on alphapedia and may have just forgot to remove it.

            I ran the code you provided (while removing the run = qry.records_get()) in the interactive window and when I query varLogin_ID using "?varLogin_ID" I get zero "0". In looking at my logins table, I should be returning 28, which is the ID of my login. The zero "0" ID is the very first record in my table.

            Comment


              #7
              Re: Selecting values from tables using xbasic

              I just saw your new reply, I would like to keep a log of all logins, so a user will be showing up more than once. The only reason I placed the while loop is because that is what I saw in alphapedia and I was just trying too hard to screw up, I really have no idea what I am doing, if there is a simpler cleaner way of doing this I probably dont know about it.

              The logic I was trying to do was filter the table by the logged in user name, then selecting the very last ID for that user in the table to set the variable to, so that when that user logs out, I can use that variable to identify the record which needs to get updated and fill in the logged_out column.

              Comment


                #8
                Re: Selecting values from tables using xbasic

                Time to learn how to use the debugger.

                Run in the interactive again but add a first line

                debug(1)

                A debugger window will open where you can set expressions at the bottom and watch their values. In my attachment is an example, the values show as it will look before stepping through (F12) the code.
                Image 3.png
                There can be only one.

                Comment


                  #9
                  Re: Selecting values from tables using xbasic

                  Wow, i ran the dubugger and I am getting the value that I am looking for, but then it loops through and changes it back to zero. How do I stop the loop?

                  Comment


                    #10
                    Re: Selecting values from tables using xbasic

                    Never mind, i think I got it. here is what I am using.

                    Code:
                    debug(1)
                    dim tbl as P
                    dim qry as P
                    tbl = table.open("LOGINS")
                    
                    query.filter = "USERNAME = "+quote(USER_NAME())
                    query.order = "invert(pk_login_id)"
                    qry = tbl.query_create("N",query.filter,query.order)
                    
                    dim LOGIN_ID as N
                    
                    tbl.fetch_first()
                    	LOGIN_ID = tbl.pk_login_id
                    
                    qry.close()
                    tbl.query_detach()
                    tbl.close()
                    
                    DIM varLOGIN_ID AS N
                    varLOGIN_ID = LOGIN_ID

                    Comment


                      #11
                      Re: Selecting values from tables using xbasic

                      Glad you have it fixed.

                      From your description of the debugger run I suggest you look at the default browse of the logins table. For that code to loop it would seem there is more than one record with your user_name(). Otherwise the tbl.fetch_next() would exit the loop leaving the login_id as the first value found.
                      There can be only one.

                      Comment


                        #12
                        Re: Selecting values from tables using xbasic

                        Yes, there are multiple entries with the same user_name(), this is intentional. Management would like to see when users are logging in and out of the database and to get an idea of how often it is being utilized.

                        Comment


                          #13
                          Re: Selecting values from tables using xbasic

                          OK, but again. Your test found your user name in the logins table. It looped and the last record found didn't have a value in tbl.pk_login_id which is why you weren't getting the value expected in the variable.

                          Is that normal/proper or is this just test data?

                          In other words, why is the first record for a user in the logins table more likely to have a value in the pk_login_id field than the last?
                          There can be only one.

                          Comment


                            #14
                            Re: Selecting values from tables using xbasic

                            I see what your getting at. I think it is because my user name in the table is the first record, and it has the ID field as zero 0, which is then incremented by 1 every time a new record is added. I guess that in the looping, it began with the last record first since my order had this column inverted, until it looped back to the first record with the ID of zero. Which would make sense as to why my variable would always be zero once the script finished.

                            Comment

                            Working...
                            X