Forum Discussion

Bjoernw's avatar
Bjoernw
New Contributor
8 years ago

How to make a IF-query with changing listbox-items?

Hello,

 

i have a problem with a IF-ELSE query.

For example my Listbox contains 4 items: Index0 = house; Index1 = tree; Index2 = car; Index3 = cat.

Now depending on the database my application uses the listbox items can vary. It can either show cat and car or just cat.

I use a IF-ELSE query:

(i´m not used to any script language, i only used the GUI and i hope you can understand my "logic")

 

If listbox.Item.index(2) = car

begin

  click car;

end;

 

Else

 

Begin

  click cat

end;

 

this works fine but now depending on the database my application uses the ItemIndex of the car-Item (or any other Item) changes from 2 to something else.

Is there a Solution where i can make a IF-ELSE query with the name of the Item ?

 

 Anyone have any ideas?

Thanks

 

7 Replies

  • shankar_r's avatar
    shankar_r
    Community Hero

    I would do a common function that can select the randomly generating list box value .

     

    As below:

     

     

     

     

     

    • m_essaid's avatar
      m_essaid
      Valued Contributor

      Shankar's solution is a good one, typicaly it would fit any case (but it won't manage the case where there would be several cats in the list for example)

  • Bjoernw's avatar
    Bjoernw
    New Contributor

    Hello,

     

    me again ;)

     

    how would the code Shankar_R posted would look like in DelphiScript?

     

    thanks again

    • m_essaid's avatar
      m_essaid
      Valued Contributor

      here it is, tested, :)

      you'll have obviously to map your combobox and use its alias name

       

      the "break" is to stop searching at the first occurence (if there is multiple occurences of the same item in the list)

       

       

       

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Forgive me, it's been YEARS since I've had to write DelphiScript...  so... here's my best guess:

      function fn_selectlistvalue(objListbox,str_valetoSelect)
      var vitemcount;
      var result;
      begin
          result := false;
          vitemcount := objListbox.wItemCount;
          for lsti:= 0 to vitemcount-1 do
              begin
                  if (aqString.Compare(aqConvert.VarToStr(objListBox.wItem(lsti)), str_valuetoselect, false) = 0 then
                     begin 
                         objListbox.ClickItem(lsti);
                         result := true;
                     end;
              end;
          fn_selectlistvalue := result;
      end;