Alpha Video Training
Results 1 to 14 of 14

Thread: Weight Conversion using a Dialog!

  1. #1
    Andy Dibble
    Guest

    Default Weight Conversion using a Dialog!

    I have a top screen menu called ‘Information’ with sub-headers – on of these sub headers are called: Weights and Measures, the menu code is set up as:

    Weights and Measures:|Cuft to Cbm / Cbm to Cuft
    Weights and Measures:|-
    Weights and Measures:|Set Up: Density Factors

    Depending on the user they would set up their Density Factor using the following:

    Sea Shipments: 5.5 to 7.0 pounds per cubic foot
    Air Shipments: 10.4 pounds per cubic foot

    The reason a Density Factor is used is because shipments of personal effects are difficult to weigh.

    The Weights and Measures:|Set Up: Density Factors will normally be set up after the installation of the Alpha 5v6 application and will not usually be changed unless an industry change requirement forces the user to do so.

    Once the Density Factor is entered the user would then select the Weights and Measures:|Cuft to Cbm / Cbm to Cuft to convert cubic feet to cubic meters and vice versa.

    I want the dialog to have 2 data entry fields:

    Field 1: Cubic Feet
    Field 2: Cubic Meters

    If a user enters in the Cubic Feet values I want the Cubic Meter field to convert the data, however – if the user enters Cubic Meters in the Cubic Feet field I want the Cubic Feet field to convert the Data also – I only want the two fields displayed in the dialog.

    In addition I will need a Radio Button selection for Sea Shipment and Air Shipment, thus the conversion factors would be drawn in from the Weights and Measures:|Set Up: Density Factors dialog window.

    What is the best approach in creating these two Dialogs? The data in the Density Factors needs to be permanent but if it does not need to link to a specific customer job, thus when the Density Factor is changed it will not effect any previously made customer shipments – this function is to be considered as a Conversion Calculator.

    Andy

  2. #2
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,308

    Default RE: Weight Conversion using a Dialog!

    ""I want the dialog to have 2 data entry fields:

    Field 1: Cubic Feet
    Field 2: Cubic Meters

    If a user enters in the Cubic Feet values I want the Cubic Meter field to convert the data, however – if the user enters Cubic Meters in the Cubic Feet field I want the Cubic Feet field to convert the Data also – I only want the two fields displayed in the dialog. ""

    I'd prompt for the volume, then the units, do the calc, and assign the input values and the calc values to Field 1 and Field 2 for display. I would not use Field 1 and Field 2 to both collect the input and do the calc since you can't know in advance which field is receiving input from the user. (More elegant solutions may be "out there". I have a personal tendency to use brute force solutions to all problems, with which I regularly struggle.)

    -- t

  3. #3
    Andy Dibble
    Guest

    Default RE: Weight Conversion using a Dialog!

    Tom,
    thanks for your direct comments, I think you could be correct in your approach but I want to do this a little different. I would like to have just 2 fields (left = cuft and right = cbm).

    If a user wants to know what his 101 cubit feet are in cbm they enter the data in the left field. On the other hand, if they want to know what 55 cbm are in feet they enter the details in the right field. In both cases the opposite field would show the result. The calculation factor is in the Density Factor field entered through the Set Up dialog.

    This would mean the 2 fields would have a dual purpose.

    1. Data Entry
    2. Calculated result.

    May be a two Conditional Objects with 2 data entry and 2 calculation fields placed on top of each other could do the task. I however do not know enough about Conditional Objects to know if this would help.

    Regards
    Andy

  4. #4
    Alpha Software Employee Lenny Forziati's Avatar
    Real Name
    Lenny Forziati
    Join Date
    Nov 2001
    Location
    Alpha Software
    Posts
    4,682

    Default RE: Weight Conversion using a Dialog!

    Here's a little Xdialog that will allow entry into either box. As you enter a number, the other number is recalculated. This doesn't use the exact formulas you are after, but should get you moving in the right direction.

    dim ft as n = 0
    dim m as n = 0
    ui_dlg_box("conversion",""%dlg%
    Cubic feet|Cubic meters;
    [ft!feet]|[m!meters];
    "close"
    %dlg%,""%code%
    if a_dlg_button = "feet"
    a_dlg_button = ""
    m = 0.02832 * ft
    elseif a_dlg_button = "meters"
    a_dlg_button = ""
    ft = 35.31 * m
    end if
    %code%)

  5. #5
    Andy Dibble
    Guest

    Default RE: Weight Conversion using a Dialog!

    Hi Lenny,

    You got it spot on, just increased the size of the data entry fields and were there. How to I centralize text in the fields, it this possible?

    'Date Created: 05-Nov-2004 02:27:32 AM
    'Last Updated: 05-Nov-2004 03:03:32 AM
    'Created By : Lenny Forziati
    'Updated By : Andy
    dim ft as n = 0
    dim m as n = 0
    ui_dlg_box("Volume Conversion",""%dlg%
    Cubic Feet|Cubic Meters;
    [16ft!feet]|[16m!meters];
    "close"
    %dlg%,""%code%
    if a_dlg_button = "feet"
    a_dlg_button = ""
    m = 0.0283168 * ft
    elseif a_dlg_button = "meters"
    a_dlg_button = ""
    ft = 35.3146666 * m
    end if
    %code%)

    Thanks
    Andy

  6. #6
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,308

    Default RE: Weight Conversion using a Dialog!

    Thanks, Lenny.

    I am still a beginner when working with xdialog code. It's hard to get out of the habit of thinking linearly. At first blush I'd think the CODE section of your script would run after the dialog closes. Of course that's wrong. It gets processed each time the change event fires for either text control. This is a new way of thinking for me, and the example helped.

    -- t

  7. #7
    Andy Dibble
    Guest

    Default RE: Weight Conversion using a Dialog!

    Hi Lenny,
    I improved the look of my dialog but I now want to add code to make it Modeless and to have a Rollup feature, this is my current code:

    dim ft as n = 0
    dim m as n = 0
    ui_dlg_box("Volume Conversion",""%dlg%
    {region}
    Cubic Feet: |{line=0,3}{sp=.75}[.16ft!feet];
    Cubic Meters: |{sp=.75}[.16m!meters];
    {line=2,0};
    {endregion};
    {region}
    "12OK" "12rollup"
    {endregion}
    %dlg%,""%code%
    if a_dlg_button = "feet"
    a_dlg_button = ""
    m = 0.0283168 * ft
    elseif a_dlg_button = "meters"
    a_dlg_button = ""
    ft = 35.3146666 * m
    end if
    %code%)

    Any suggestions for adding the Rollup/down feature?
    Regards
    Andy

  8. #8
    Alpha Software Employee Lenny Forziati's Avatar
    Real Name
    Lenny Forziati
    Join Date
    Nov 2001
    Location
    Alpha Software
    Posts
    4,682

    Default RE: Weight Conversion using a Dialog!

    Andy, the switch to a modeless dialog is quite simple. ui_dlg_box() becomes ui_modeless_dlg_box() and you need to add a "close" event handler that calls ui_modeless_dlg_close() to close the dialog.

    dim ft as n = 0
    dim m as n = 0
    dim dlg_title as c = "Volume Conversion"
    ui_dlg_box(dlg_title,""%dlg%
    {region}
    Cubic Feet: |{line=0,3}{sp=.75}[.16ft!feet];
    Cubic Meters: |{sp=.75}[.16m!meters];
    {line=2,0};
    {endregion};
    {region}
    "12OK" "12rollup"
    {endregion}
    %dlg%,""%code%
    if a_dlg_button = "feet"
    a_dlg_button = ""
    m = 0.0283168 * ft
    elseif a_dlg_button = "meters"
    a_dlg_button = ""
    ft = 35.3146666 * m
    elseif a_dlg_button = "OK"
    ui_modeless_dlg_close(dlg_title)
    end if
    %code%)


    Rollup code is a little more complex, but still fairly simple to do. Take a look in Learning Xdialog, there is a sample in the Misc section. Basically you define two dialogs with the same title and the rollup/rolldown button alternates between dialogs.

    However, I strongly prefer to create MDI Xdialogs. This allows the modeless window to be minimized instead of just rolled up which is probably what your app users are more accustomed to. You can also define menus and toolbars for an MDI window if desired. You'll find an example of this technique in Learning Xdialog as well.

    -Lenny

  9. #9
    Alpha Software Employee Lenny Forziati's Avatar
    Real Name
    Lenny Forziati
    Join Date
    Nov 2001
    Location
    Alpha Software
    Posts
    4,682

    Default RE: Weight Conversion using a Dialog!

    You're right Tom, Xdialogs don't have the usual linear flow of a typical script. Instead you are essentially designing a form and the code section contains the scripts for each event you would like to define. The code is run each time anything happens in the dialog, such as a user typing or clicking a button.

    It takes a slight shift in thinking, but it gives you a tremendous amount of power and flexibility.

    -Lenny

  10. #10
    Andy Dibble
    Guest

    Default RE: Weight Conversion using a Dialog!

    Lenny,
    I have read the information in Learning Exbasic and I have created my Rollup/Rolldown but can work out how to incorporate the following code:

    if a_dlg_button = "feet"
    a_dlg_button = ""
    m = 0.0283168 * ft
    elseif a_dlg_button = "meters"
    a_dlg_button = ""
    ft = 35.3146666 * m

    This is my current code as it stands:
    'Date Created: 27-Oct-2002 09:12:46 PM
    'Last Updated: 27-Oct-2002 09:12:46 PM
    'Created By :
    'Updated By : Andy
    dim ft as n = 0
    dim m as n = 0
    dim dialog_box_title as c
    dialog_box_title = "Volume Conversion"
    dlg_expanded = ""%dlg%
    {can_exit=close}
    {position=remember=test_dialog}
    {region}
    Cubic Feet: |{line=0,3}{sp=.75}[.16ft!feet];
    Cubic Meters: |{sp=.75}[.16m!meters];
    {line=2,0};
    {endregion};
    {region}
    "12OK" "12Rollup";
    {endregion}
    %dlg%

    dlg_contracted = ""%dlg%
    {can_exit=close}
    {position=remember=test_dialog}
    Click Rolldown to enter data.;
    {lf};
    "12OK" "Rolldown";
    %dlg%

    event_expanded = ""%code%
    if a_dlg_button = "OK" then
    ui_modeless_dlg_close(dialog_box_title)
    end if

    if a_dlg_button = "rollup" then
    ui_modeless_dlg_box(dialog_box_title,dlg_contracted,event_contracted)
    end if
    %code%

    event_contracted = ""%code%
    if a_dlg_button = "OK" then
    ui_modeless_dlg_close(dialog_box_title)
    end if

    if a_dlg_button = "rolldown" then
    ui_modeless_dlg_box(dialog_box_title,dlg_expanded,event_expanded)
    end if
    %code%

    ui_modeless_dlg_box(dialog_box_title,dlg_expanded,event_expanded)


    Can you you help?

    Regards
    Andy

  11. #11
    Alpha Software Employee Lenny Forziati's Avatar
    Real Name
    Lenny Forziati
    Join Date
    Nov 2001
    Location
    Alpha Software
    Posts
    4,682

    Default RE: Weight Conversion using a Dialog!

    Just add it to the event_expanded, as you want that code to be part of the event handler for the expanded window.

    -Lenny

  12. #12
    Andy Dibble
    Guest

    Default RE: Weight Conversion using a Dialog!

    Lenny,
    Already tried but leaning curve still only 1/2 inch from the floor!
    Andy

  13. #13
    Alpha Software Employee Lenny Forziati's Avatar
    Real Name
    Lenny Forziati
    Join Date
    Nov 2001
    Location
    Alpha Software
    Posts
    4,682

    Default RE: Weight Conversion using a Dialog!

    Try this:

    event_expanded = ""%code%
    if a_dlg_button = "OK" then
    ui_modeless_dlg_close(dialog_box_title)
    elseif a_dlg_button = "rollup" then
    ui_modeless_dlg_box(dialog_box_title,dlg_contracted,event_contracted)
    elseif a_dlg_button = "feet"
    m = 0.0283168 * ft
    elseif a_dlg_button = "meters"
    ft = 35.3146666 * m
    end if
    %code%


    One thing to notice is that I removed the a_dlg_button="" lines. These are only needed for a modal dialog. You can leave them in the modal dialog, they won't hurt anything, but they aren't needed. What they do is prvent the modal dialog from closing.

    -Lenny

  14. #14
    Andy Dibble
    Guest

    Default RE: Weight Conversion using a Dialog!

    Lenny,
    Thants done the trick - thanks for your assistance, I now know how to create this type of dialog, hip hip...

    Here is the complete code just incase anyone else has been following the threads:

    Regards
    Andy

    'Date Created: 27-Oct-2002 09:12:46 PM
    'Last Updated: 27-Oct-2002 09:12:46 PM
    'Created By : Lenny Forziati
    'Updated By : Andy
    dim ft as n = 0
    dim m as n = 0
    dim dialog_box_title as c
    dialog_box_title = "Volume Conversion"
    dlg_expanded = ""%dlg%
    {can_exit=close}
    {position=remember=test_dialog}
    {region}
    Cubic Feet: |{line=0,3}{sp=.75}[.16ft!feet];
    Cubic Meters: |{sp=.75}[.16m!meters];
    {line=2,0};
    {endregion};
    {region}
    "12OK" "12Rollup";
    {endregion}
    %dlg%

    dlg_contracted = ""%dlg%
    {can_exit=close}
    {position=remember=test_dialog}
    Click Rolldown to enter data.;
    {lf};
    "12OK" "Rolldown";
    %dlg%

    event_expanded = ""%code%
    if a_dlg_button = "OK" then
    ui_modeless_dlg_close(dialog_box_title)
    elseif a_dlg_button = "rollup" then
    ui_modeless_dlg_box(dialog_box_title,dlg_contracted,event_contracted)
    elseif a_dlg_button = "feet"
    m = 0.0283168 * ft
    elseif a_dlg_button = "meters"
    ft = 35.3146666 * m
    end if

    if a_dlg_button = "rollup" then
    ui_modeless_dlg_box(dialog_box_title,dlg_contracted,event_contracted)
    end if
    %code%

    event_contracted = ""%code%
    if a_dlg_button = "OK" then
    ui_modeless_dlg_close(dialog_box_title)
    end if

    if a_dlg_button = "rolldown" then
    ui_modeless_dlg_box(dialog_box_title,dlg_expanded,event_expanded)
    end if
    %code%

    ui_modeless_dlg_box(dialog_box_title,dlg_expanded,event_expanded)

Similar Threads

  1. dialog box conversion
    By dik_coleman in forum Alpha Five Version 6
    Replies: 3
    Last Post: 10-27-2004, 10:32 AM
  2. any tip on conversion to ver 5
    By ken tjia in forum Alpha Five Version 5
    Replies: 5
    Last Post: 09-06-2003, 08:26 PM
  3. Conversion
    By Douglas Menkel in forum Alpha Five Version 4
    Replies: 2
    Last Post: 05-24-2003, 09:00 AM
  4. A4.5 to A5 Conversion
    By John Gamble in forum Alpha Five Version 5
    Replies: 8
    Last Post: 08-26-2002, 02:21 PM
  5. Conversion
    By James Peterson in forum Alpha Five Version 4
    Replies: 0
    Last Post: 12-27-2001, 07:54 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •