No announcement yet.

Quick question on dynamic object name creation

  • Filter
  • Time
  • Show
Clear All
new posts

  • Quick question on dynamic object name creation

    I'm sure I've done this before, but I just can't remember how...

    I'm trying to modify an image upon returning from a dialog. Instead of using a bunch of if/then statements on the dialog return, I thought I could perhaps concatenate that result into the object name.

    Here's an example:

    If I show a dialog with this....

    result = DialogEx.Show("Buy Plot", true, nil, nil);

    can I now modify an image such as....

    plot..result..gfx = "AutoPlay\\Images\\Cow.png";

    (I have several images, all named plot1gfx, plot2gfx, plot3gfx, etc).

    how to I use the "result" from the dialog return to modify those images without doing something like...

    if (result == 1) then
    plot1gfx = ....
    else if (result ==2) then
    plot2gfx = ....

    Thanks as always!

  • #2
    Can you try to explain your objective a little more clearly (perhaps with an APZ that reveals what you're trying to achieve). At the moment, I'm having trouble following exactly what it is that you're wanting to do.

    In regards the first part of your question ...
    Originally posted by Stobe View Post
    ...If I show a dialog with this....

    result = DialogEx.Show("Buy Plot", true, nil, nil);

    can I now modify an image such as....

    plot..result..gfx = "AutoPlay\\Images\\Cow.png";
    .. you should keep in mind that when a Dialog is executed, control is passed from the parent window (ie. your main page) to the child window (ie. the DialogEx). So, if you call up a Dialog and place a command to manipulate an image immediately afterwards, the image command won't be executed until the Dialog window is closed. So the answer to your question is Yes - just position your code immediately after the DialogEx.Show command:
    Image.Load("Image1", "AutoPlay\\Images\\Cow.png");
    With this code-snippet, notice how the image doesn't actually load until the DialogEx window is closed. As for the rest of it, if u can explain your objective/problem more clearly, we can try to help further.


    • #3
      EDIT: As I typed this, I think I figured it out.... lol

      After re-reading my original post, I understand the confusion, lol.

      Lets start by saying I have 10 image objects. All named plot1gfx, plot2gfx.... all the way to plot10gfx

      When I click on the image (on_click), it will open a dialog, and based upon choices made on that dialog, it will return a number (int) which gets assigned to the "result" variable from the dialog call


      result = DialogEx.Show("Buy Plot", true, nil, nil);  --this shows the dialog, and waits for the result
      now I need to use the number coming back as the result to reference one of the image objects.

      (hmmm.. I think I just figured it out)

      how about I build a string first, then use it to reference the image object like this....

      imageName = "plot"..result.."gfx";
      Image.Load(imageName, "AutoPlay\\Images\\Cow.png");
      so if the return variable from the dialog is 5, the Image Object called plot5gfx will be changed, and if the return variable is 9, Image Object called plot9gfx will be changed.

      Hope that made more sense.


      • #4
        Well, it'd be helpful to know what choices are being executed from the DialogEx window (hence the request for the APZ, so we can see specifically where your code is failing).

        The DialogEx.Show command will only return the result that is passed to the DialogEx.Close action. This is explained in the manual. If you're just trying to load an image based upon a predetermined set of conditions, then create a table of image-names in Globals which the trigger-event can reference and loop thru. If the trigger-event meets the predetermined conditions, it can then make the appropriate selection from this table.

        You really need to explain your problem more clearly. It may be clear to you, but for the rest of us, it exists in a 'vacuum'. And we can only work from the info you give us. Upload an APZ (that's actually commented in the place you're having trouble with) and we can go from there.