title: VB6 - How could I get the ListBox selected id
body: <p>AS I using the VB6.0 for create a Dialog Box with the ListBox, but only I can get the String text with Trim(DlgText$("xxxxx")), for the other side still I could not found how to get it.</p>
  
  <p>Most of the answer from network said that could be using [LisBox_ID].Selected to get the item that what they want, but I can not get the same result.</p>
  
  <p>For my Code:
  [Dialog]</p>
  
  <pre><code>Function aOpenDialog As Boolean
      aOpenDialog = False
      iArrayLoop = 0
      Begin Dialog UserDialog ,,250,120,ScriptTitle,.ActivateDlgControls
          Text 5,5,130,10,"Sub Booking End Date", .tf_InsertionSetEndDate
          ListBox 5,15,100,100,aArrayList, .aArrayList
          Text 110,5,130,10,"After Date [DD-MMM-YYYY]", .tf_AfterDate
          TextBox 110,15,55,10, .txt_AfterDate
          Text 110,25,55,10,"Change Reason", .tf_ChangeReason
          TextBox 110,35,130,10, .txt_ChangeReason
          OKButton 110,45,70,10, .btn_Save
          CancelButton 110,55,70,10, .btn_Cancel
      End Dialog
      Dim dlg As UserDialog
      aArrayList(1) = "Day1"
      aArrayList(2) = "Day2"
      Dialog dlg
  End Function
  </code></pre>
  
  <p>[ActiveDlgControls]</p>
  
  <pre><code>Function ActivateDlgControls(ControlName$, Action%, SuppValue%)
      If (Action% = 2 And ControlName$ = "btn_Save") Then
          sMissingMessage = ""
          If (Not IsDate(CStr(Trim(DlgText$("txt_AfterDate"))))) Then
              sMissingMessage = sMissingMessage &amp; "- Please input the correct day format"
          Else
              MsgBox Format(Trim(DlgText$("txt_AfterDate")), "dd mmm yyyy")
  
              ' This Area will be using for get the selected array item id
              ' I can found the selected items with String
              MsgBox Trim(DlgText$("aArrayList"))
  
              ' Unknow way to found the selected items id
              ' MsgBox dlg.aArrayList.SelectedItem(x)
          End If
  
          If (sMissingMessage &lt;&gt; "") Then
              ActivateDlgControls = 1
              iCheckResult = 1
              sMissingMessage = "Information Missing:" &amp; sMissingMessage
              MsgBox sMissingMessage
          End If
      ElseIf (Action% = 2 And ControlName$ = "btn_Cancel") Then
          iCheckResult = 2
      End If
  End Function
  </code></pre>
  
  <p>Any idea how should I get the selected ListBox item?
  I want to get the array number that I selected inside the LisBox.</p>
  
  <p>Although I got an other stupid idea for get the index like as below code:</p>
  
  <pre><code>For iArrayLoopCheck = 0 To UBound(aArrayList)
      If (aArrayList(iArrayLoopCheck) = Trim(DlgText$("aArrayList")))Then
          MsgBox "You Select item: " &amp; iArrayLoopCheck
          Exit For
      End If
  Next
  </code></pre>
  
  <p>Still I was looking for any smart code/ items/ easy way to get the result quickly just like get the String value in array like: Trim(DlgText$("xxxxx"))</p>
  
  <p>Best Regards,</p>
  
  <p>KT</p>