I want to design a popupmenu and I use SQL to find the title I need but I need to convert the table to an array in order to use Title From Variable xxx


Always use Fetch First, Fetch Next when looping thru a table. Using the Fetch Rec No isn't recommended as that won't work if the record you try to fetch has been deleted.

Here is a function that does the trick:

Include "MapBasic.def"

Function LoadValues(arrValues() As String, ByVal sTab As String, ByVal sCol As String) As Integer        
Dim aRow As Alias
Dim i As Integer

aRow = sTab & "." & sCol
ReDim arrValues(TableInfo(sTab, TAB_INFO_NROWS)

Fetch First From sTab
Do Until EOT(sTab)
   i = i + 1
   arrValues(i) = aRow

   Fetch Next From sTab

ReDim arrValues(i)
LoadValues = i

End Function

This could of course be extended to add a group by and an order by to the table and column to only use each unique value once and have the values ordered

PS: This works properly for a Char column. You would have to format your result if the column is of any other type.


Something like this:

Dim ArrayVarriable() as String
Select count(*) Count from [SqlTable] into tmpCount
Dim iCount as integer
iCount = tmpCount.Count
Redim ArrayVariable(iCount)
Dim i as integer

For i = 1 to iCount
    Select foo from [SqlTable] where RowID = [counterVariableName] into tmpTable
    ArrayVariable(i) = [SqlTable].foo
  • I have marked this answer as not useful as it has a number of problems: 1) You are issuing a potential large number of select statements 2) You do set the cursor at any record before trying to read data from the table 3) Your select statement in the loop might not return any values in a case where the table holds deleted records – Peter Horsbøll Møller Dec 2 '13 at 20:21

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.