PopupMenu

I like ti fil two popup menu with the same value.
The first code is running very well but the second code listet only the first item.
In the first code there are two separate Popupmenu, in the seccond case the popupmenu are members.
What is wrong?
1. Code:

SQL="SELECT * FROM Sponning;" If OpenDataBase Then Data=DBase.SQLSelect(SQL) While Not Data.EOF If Data.Field("Type").StringValue <> "" Then TempStr = Data.Field("Type").StringValue+" - "+ Str(Data.Field("Nummer").Value) for N=0 to PopupSpomLi.ListCount-1 PopupSpomLi.ListIndex=N if PopupSpomLi.Text=TempStr Then goto Sprong Next PopupSpomLi.AddRow TempStr PopupSpomRe.AddRow TempStr End If Sprong: data.MoveNext Wend End if PopupSpomLi.ListIndex=0 PopupSpomRe.ListIndex=0

2. Code:

SQL="SELECT * FROM Sponning;" If OpenDataBase Then Data=DBase.SQLSelect(SQL) While Not Data.EOF If Data.Field("Type").StringValue <> "" Then TempStr = Data.Field("Type").StringValue+" - "+ Str(Data.Field("Nummer").Value) For N= 0 To PopNeut(2).ListCount-1 PopNeut(2).ListIndex=N If PopNeut(2).Text=TempStr Then GoTo Sprong Next PopNeut(8).AddRow TempStr PopNeut(2).AddRow TempStr End If Sprong: Data.MoveNext wend DBase.Close End If PopNeut(8).ListIndex=0 PopNeut(2).ListIndex=0

Oooh, there’s gonna be a lot of comments on the use of Goto.

I don’t know exactly what you are doing but the code seems overly complicated. Can this work?

SQL="SELECT * FROM Sponning;"
  If OpenDataBase Then
    Data=DBase.SQLSelect(SQL)
    While Not Data.EOF
      If Data.Field("Type").StringValue <> "" Then
        TempStr = Data.Field("Type").StringValue+" - "+ Str(Data.Field("Nummer").Value)
        PopupSpomLi.AddRow TempStr
        PopupSpomRe.AddRow TempStr
      End If
      data.MoveNext
    Wend
  End if
  PopupSpomLi.ListIndex=0
  PopupSpomRe.ListIndex=0

The problem is as follow:
In the DataBase Table “Sponning” there are a lot items with the same “Type” name but in the popupmenu i like to have every type once.
It’s run, if i use two single popupmenu’s, but if i use popupmenu’s with a membership it doesent works.

What database is it?
I think you can tell the database to not return duplicates in your query.

The DataBase is SQLite, how can i switch off the duplicates?

I think you can use DISTINCT in SQLite. http://www.tutorialspoint.com/sqlite/sqlite_distinct_keyword.htm
Try this: (pseudo code)

SQL="SELECT DISTINCT * FROM Sponning;"
  If OpenDataBase Then
    Data=DBase.SQLSelect(SQL)
    While Not Data.EOF
        TempStr = Data.Field("Type").StringValue+" - "+ Str(Data.Field("Nummer").Value)
        PopupSpomLi.AddRow TempStr
        PopupSpomRe.AddRow TempStr
      End If
      data.MoveNext
    Wend
  End if
  PopupSpomLi.ListIndex=0
  PopupSpomRe.ListIndex=0

Use DISTINCT in the SQL query:

SELECT DISTINCT * FROM Sponning

OK Thanks, it’s works

Great!
A tip is to make the database engine work as much for you as it can instead of processing the results too much :slight_smile: