1
$\begingroup$

I am trying to create a code that concatenates a series of dynamic selections (year, month, day) to a string for creating a dynamic date string for use in an API which is to be included in a URLExecute[] function. In the code below, the majority of code seems to work fine. As the user selects the menu options which are dynamic, I have attempted numerous times to create a string of some sort without success. The last grid in the code snippet below is basically broken as I am out of ideas on how to handle the conversion. Once the string is completed, I will send it as part of an API to a SCADA historian.

Any advice whatsoever is greatly appreciated.

YearMenuS = PopupMenu[Dynamic[YearChoiceS], YearList, 1950];
YearMenuE = PopupMenu[Dynamic[YearChoiceE], YearList, 1950];

MonthMenuS = PopupMenu[Dynamic[MonthChoiceS], {"Jan"
                , "Feb"
                    , "Mar"
                        , "Apr",
                "May",
                    "Jun",
                        "Jul",
                "Aug",
                    "Sep",
                        "Nov",
                "Dec"}, "Jan"];

MonthMenuE = PopupMenu[Dynamic[MonthChoiceE], {"Jan"
                , "Feb"
                    , "Mar"
                        , "Apr",
                "May",
                    "Jun",
                        "Jul",
                "Aug",
                    "Sep",
                        "Nov",
                "Dec"}, "Jan"];

DayMenuS = 
  PopupMenu[Dynamic[DayChoiceS], 
   IntegerString[#, 10, 2] & /@ Range[31], 01 ];
DayMenuE = 
  PopupMenu[Dynamic[DayChoiceE], 
   IntegerString[#, 10, 2] & /@ Range[31], 01 ];

Grid[{
  {"Start Date"},
  {YearMenuS, MonthMenuS, DayMenuS},
  {"End Date"},
  {YearMenuE, MonthMenuE, DayMenuE},
  aa = YearMenuS[[1]];
  bb = MonthMenuS[[1]];
  cc = DayMenuS[[1]];
  {  Button["Get Data",
        (*Print[Dynamic  [YearMenuS[[1]]]  ]]  }*)
        txt1 = Print[aa];
        Print[TextString[aa]]; 
        Print[StringJoin[ aa, aa]  ];
        (*txt3=Print[aa,"-",bb,"-",cc];*)
        (*Print[az]*)
        ]}
  
  
  }]
```
$\endgroup$
4
  • $\begingroup$ Is Print@DayChoiceS what you need? $\endgroup$ – Kuba Jul 13 '20 at 3:29
  • 1
    $\begingroup$ @Kuba what i need is a string in the form of "YearChoice-MonthChoice-DayChoice". The S and E are just repeated code for Start and End. For instance, I am currently hard-coding "2010-08-10" into my API and I was hoping to make it dynamic. $\endgroup$ – Colin Lyle Jordan Jul 13 '20 at 4:11
  • $\begingroup$ I meant that you can use DayChoiceS instead of DayMenuS[[1]] $\endgroup$ – Kuba Jul 13 '20 at 5:59
  • $\begingroup$ @Kuba. Thanks I will give that a go and see how it works. $\endgroup$ – Colin Lyle Jordan Jul 13 '20 at 23:44
1
$\begingroup$

@PrintDayChoiceS did not quite give me what I wanted -- it produced the solution or day pick but not as a string. The work around i used in the end was to skip the printing and just execute the API within the Button[] function. Not sure if this is the most efficient. But seems to work for the moment. Thanks again @Kuba :)

GetRawDataGrid = Grid[{
    {WellListLabel},
    {WellMenu},
    {BlankLine},
    {SelectDateS},
    {YearMenuS, MonthMenuS, DayMenuS},
    {BlankLine},
    {SelectDateE},
    {YearMenuE, MonthMenuE, DayMenuE},
    aa = MonthMenuS[[1]];
    bb = MonthMenuS[[1]];
    cc = MonthMenuS[[1]];
    {BlankLine},
    {  Button[ExecuteBut,
        
        finalstringS = 
       StringJoin[ToString[YearChoiceS], "-", 
        StringTake[ToString[MonthChoiceS], -2], "-", 
        ToString[DayChoiceS]];
        finalstringE = 
       StringJoin[ToString[YearChoiceE], "-", 
        StringTake[ToString[MonthChoiceE], -2], "-", 
        ToString[DayChoiceE]];
        tqdatatest = 
       URLExecute[
            "http://LAPTOP-XXXX:XXXX/api/v2/getTagData", {"tags" \
-> "XXXX:XXXX.GBGasField.Sine.Tag0002" ,(*Tag0002 is tq*)
                    "startTime" -> finalstringS,
                    "endTime" -> finalstringE
                        }][[3]][[2]][[1]][[2]];
        ]}
    
    
    }, Alignment -> Left, Background -> BCTV];
TabView[{WellListLabel -> GetRawDataGrid}, Background -> BCTV];

```
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.