-1
因为我使用VB6.0创建一个对话框与列表框,但只有我可以得到带修剪(DlgText $(“xxxxx”))的字符串文本,为对方仍然无法找到如何得到它。VB6 - 我怎样才能得到列表框选择ID
大多数来自网络的答案都表示可以使用[LisBox_ID]。选择获取他们想要的项目,但我无法获得相同的结果。
对于我的代码: [对话]
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
[ActiveDlgControls]
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 & "- 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 <> "") Then
ActivateDlgControls = 1
iCheckResult = 1
sMissingMessage = "Information Missing:" & sMissingMessage
MsgBox sMissingMessage
End If
ElseIf (Action% = 2 And ControlName$ = "btn_Cancel") Then
iCheckResult = 2
End If
End Function
任何想法,我应该怎么获取选中列表框的项目? 我想获得我在LisBox中选择的数组编号。
虽然我得到了一个其他愚蠢的想法得到了指数类似如下代码:
For iArrayLoopCheck = 0 To UBound(aArrayList)
If (aArrayList(iArrayLoopCheck) = Trim(DlgText$("aArrayList")))Then
MsgBox "You Select item: " & iArrayLoopCheck
Exit For
End If
Next
不过我一直在寻找任何智能的代码/项目/简单的方法来快速获得结果就像得到字符串在阵列状值:TRIM(DlgText $( “XXXXX”))
最好的问候,
KT
如果我根据找不到的对象继续操作,可能无法成功。 这个x.ListIndex和x代表一个Object Like: https://msdn.microsoft.com/en-us/library/aa235162(v=vs.60).aspx 但是我找不到哪个对象我应该使用吗? 但是,谢谢你的回复。 –