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 IF statements

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

    XBasic IF statements

    Hi all,

    I have a rather challenging issue that has me stuck. See the form below.

    screenshot.bmp

    I'm trying to implement "shortcuts" on a form that upon selection, fill corresponding fields. The shortcuts are records in another table that are referenced and then via a look-up are set to field values on this form. I was successful in completing this and have copied the xbasic below for reference.

    Each 'part' consists of 3 fields to be updated: 1) quantity 2) part number 3) description


    The challenge is to write some sort of IF statement that will check if field 1 (2/3/4/etc) is already occupied, if so, it will fill the next instead of over-writting it. Basically to +1 the field references if necessary. Up to this point I've only been using the Genies and have taken the genie's Xbasic and modified it resulting in the code below. I have done this for all 15 parts in the table although only 2 are listed here. I am very new at Xbasic so hopefully there is an easy way to do what I'm describing.


    'Set Value of 1st part
    DIM form_name as c
    if is_object(topparent.this) then
    form_name = topparent.name()+".this"
    else
    form_name = ""
    end if

    'part1
    DELETE expression_result
    expression_result = eval("lookupc('F',alltrim(Var->RS)+alltrim(outgoing_part_number),'rpartdesc1','repair shortcuts','rs')",form_name)
    parentform:Rpartdesc1.value = expression_result
    DELETE expression_result
    expression_result = eval("lookupc('F',alltrim(Var->RS)+alltrim(outgoing_part_number),'rpartnum1','repair shortcuts','rs')",form_name)
    parentform:Rpartnum1.value = expression_result
    DELETE expression_result
    expression_result = eval("lookupn('F',alltrim(Var->RS)+alltrim(outgoing_part_number),'rpartqty1','repair shortcuts','rs')",form_name)
    parentform:Rpartqty1.value = expression_result

    'part2
    DELETE expression_result
    expression_result = eval("lookupc('F',alltrim(Var->RS)+alltrim(outgoing_part_number),'rpartdesc2','repair shortcuts','rs')",form_name)
    parentform:Rpartdesc2.value = expression_result
    DELETE expression_result
    expression_result = eval("lookupc('F',alltrim(Var->RS)+alltrim(outgoing_part_number),'rpartnum2','repair shortcuts','rs')",form_name)
    parentform:Rpartnum2.value = expression_result
    DELETE expression_result
    expression_result = eval("lookupn('F',alltrim(Var->RS)+alltrim(outgoing_part_number),'rpartqty2','repair shortcuts','rs')",form_name)
    parentform:Rpartqty2.value = expression_result

    #2
    Re: XBasic IF statements

    So if parentform:Rpartdesc1.value currently has a value, leave it alone, otherwise fill in the Rpartdesc1, rpartnum1, and rpartqty1? Same for the other "parts"?
    There can be only one.

    Comment


      #3
      Re: XBasic IF statements

      hi stan,

      actually I would like to be able to not leave it alone but rather change the order. If say rpartnum1 has a value, do not fill in 1 but fill into rpartnum2 etc.

      it's currently set up as:

      1 -> rpartnum1
      2 -> rpartnum2
      3 -> rpartnum3

      my goal is to be able to alter the order automatically:

      if rpartnum1 is full, then

      1-> rpartnum2
      2-> rpartnum3
      3-> rpartnum4

      This is just an example and not necessarily how it should be coded. So if any field is occupied, the subsequent field should be used.

      Comment


        #4
        Re: XBasic IF statements

        I don't understand, but that's not unusual.

        I think this does the same as your original code for as many entries as you set up in the part_list variable.

        Code:
        DIM form_name as c
        if is_object(topparent.this) then
        	form_name = topparent.name()+".this"
        else
        	form_name = ""
        end if
        part_list = "1,2,3,4,5,6" 'whatever is appropriate
        part_list = comma_to_crlf(part_list) 'change to crlf() list
        for each part_num in part_list 'process each entry in list
        	if alltrim(eval("parentform:Rpartdesc"+part_num.value+".value")) > ""
        		DELETE expression_result
        		expression_result = eval("lookupc('F',alltrim(Var->RS)+alltrim(outgoing_part_number),'rpartdesc"+part_num.value+"','repair shortcuts','rs')",form_name)
        		eval("parentform:Rpartdesc"+part_num.value+".value") = expression_result
        		DELETE expression_result
        		expression_result = eval("lookupc('F',alltrim(Var->RS)+alltrim(outgoing_part_number),'rpartnum"+part_num.value+"','repair shortcuts','rs')",form_name)
        		eval("parentform:Rpartnum"+part_num.value+".value") = expression_result
        		DELETE expression_result
        		expression_result = eval("lookupn('F',alltrim(Var->RS)+alltrim(outgoing_part_number),'rpartqty"+part_num.value+"','repair shortcuts','rs')",form_name)
        		eval("parentform:Rpartqty"+part_num.value+".value") = expression_result
        	end if
        next
        There can be only one.

        Comment


          #5
          Re: XBasic IF statements

          The "shortcuts" are essentially a look-up from another table 'repair shortcuts' which shares the same field names that I want to bring over to my parent form (rpartnum1, rpartdesc1, etc). Maybe the repetition of field names is what is confusing in the code. Let me give this a shot and see how I make out. Thanks Stan I'll keep you posted.
          Last edited by hov333; 03-26-2013, 05:08 PM.

          Comment


            #6
            Re: XBasic IF statements

            Stan, help me to understand. How should I go about setting up the parts list variables? I know how to create variables but in this case each part consists of 3 fields:

            1) quantity (rpartqty)
            2) part number (rpartnum)
            3) description (rpartdesc)

            Which of these should be used the create the variables for 1-15 parts. Please help explain the logic behind the code you shared.

            Thanks,
            John P.

            Comment


              #7
              Re: XBasic IF statements

              If you build a character list of "digits" and loop through that list in a for each ... next loop, the value property of the loop variable will contain each digit in turn.

              Eval() is one of few if not the only function that can be used on the left side of an equals sign.

              eval("parentform:Rpartdesc"+part_num.value+".value")

              says evaluate the string "parentform:Rpartdesc"+part_num.value+".value"

              Part_num is the for each ... next loop variable so in sequence the string becomes
              parentform:Rpartdesc"+"1"+".value (in the first pass)
              parentform:Rpartdesc"+"2"+".value (in the next pass)
              parentform:Rpartdesc"+"3"+".value (in the next pass)

              which evaluate to

              parentform:Rpartdesc1.value (in the first pass)
              parentform:Rpartdesc2.value (in the next pass)
              parentform:Rpartdesc3.value (in the next pass)

              The same evaluation process is happening on the right side of the equals sign and the same digit is dropped into the lookup expression.

              Make sense?
              There can be only one.

              Comment


                #8
                Re: XBasic IF statements

                starting to make sense. Stan what were you trying to say on the 6th line down: Part_num is the _?_ for each ...

                Also, how should I build up my variables? Is it actually just part_list, and not 15 different variables?
                i.e.

                part_list = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15"

                Comment


                  #9
                  Re: XBasic IF statements

                  Ok here so this is what I have as the xbasic script:

                  'Set Value of 1st part
                  DIM form_name as c
                  if is_object(topparent.this) then
                  form_name = topparent.name()+".this"
                  else
                  form_name = ""
                  end if

                  part_list = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15"
                  part_list = comma_to_crlf(part_list) 'change to crlf() list
                  for each part_num in part_list 'process each entry in list
                  if alltrim(eval("parentform:Rpartdesc"+part_num.value+".value")) > ""
                  DELETE expression_result
                  expression_result = eval("lookupc('F',alltrim(Var->RS)+alltrim(outgoing_part_number),'rpartdesc"+part_num.value+"','repair shortcuts','rs')",form_name)
                  eval("parentform:Rpartdesc"+part_num.value+".value") = expression_result
                  DELETE expression_result
                  expression_result = eval("lookupc('F',alltrim(Var->RS)+alltrim(outgoing_part_number),'rpartnum"+part_num.value+"','repair shortcuts','rs')",form_name)
                  eval("parentform:Rpartnum"+part_num.value+".value") = expression_result
                  DELETE expression_result
                  expression_result = eval("lookupn('F',alltrim(Var->RS)+alltrim(outgoing_part_number),'rpartqty"+part_num.value+"','repair shortcuts','rs')",form_name)
                  eval("parentform:Rpartqty"+part_num.value+".value") = expression_result
                  end if
                  next




                  Is this sufficient or is there supposed to be more? I tried a few things when running it and discovered, that it only activates the lookup if the desc field is not blank, and it over-writes what is there. So if the field is blank, it does not bring anything...seems like I'm missing something here. It should always fill, and if occupied then fill the subsequent field.

                  Comment


                    #10
                    Re: XBasic IF statements

                    The For each.....next command structure requires a list variable containing the values to be processed and a dummy variable to use as a place holder for the current item in the list.

                    In my original code sample I created the list variable in two steps.

                    part_list = "1,2,3,4,5,6" 'whatever is appropriate
                    part_list = comma_to_crlf(part_list) 'change to crlf() list

                    and the place holder dummy variable in the for each definition.

                    for each part_num in part_list 'process each entry in list

                    You can read that as

                    for each individual value in the part_list variable
                    'do something
                    next
                    There can be only one.

                    Comment


                      #11
                      Re: XBasic IF statements

                      Looks like I have the test wrong for what you wanted.

                      You want to say

                      if alltrim(eval("parentform:Rpartdesc"+part_num.value+".value")) = ""

                      not the greater than I had.

                      If the form rpartdesc1.value is blank, fill it, otherwise go on to to #2, etc.
                      There can be only one.

                      Comment


                        #12
                        Re: XBasic IF statements

                        great stan, its now not over-writing. However, its not moving the order down, its simply skipping the fields that are occupied. Am i supposed to have anything after the "next" command?

                        Comment


                          #13
                          Re: XBasic IF statements

                          Well, that's that part I don't comprehend.

                          "its not moving the order down"

                          The code given is not designed to move anything.

                          Let me try to understand the description in post #3 and get back to you.
                          There can be only one.

                          Comment


                            #14
                            Re: XBasic IF statements

                            Ok take a look at the first attachment, and compare it to this attachment.
                            screenshot2.jpg

                            This attachment shows what I'd like to happen if the 1st part field is already occupied. It will be putting the 2 parts from the shortcut into fields 2 & 3 instead of 1 & 2.

                            Comment


                              #15
                              Re: XBasic IF statements

                              Making more sense.

                              We need a way to obtain the count of how many shortcuts will be pertinent to the situation. In other words, why are there two listed on the screen? Is there some link to a field not visible? Is the Shortcuts* area a browse?
                              There can be only one.

                              Comment

                              Working...
                              X