The app started to crash on this line recently, but I don’t know why. Is there anything wrong with the syntax?
PopQSCategory.SelectRowWithValue(rs.Column("PopMenuCategory").Value) //Popup menu
This is the message I get with the crash:
The crash happens after I create a new row in a Listbox and select that row. However when I first quit the app, run it again and THEN select that row, no crash occurs.
Is that a RowSet?
Column() gives you a DatabaseColumn.
And value exists as property and gives you a Variant.
SelectRowWithValue for a PopupMenu takes a string, which gets converted automatically from the variant, so StringValue wouldn’t change that.
But could it be the value from RowSet is really not found in the popup?
Maybe you better put it in a variable, so you can inspect it in debugger.
e.g.
dim v as variant = rs.Column("PopMenuCategory").Value
PopQSCategory.SelectRowWithValue(v) //Popup menu
1 Like
Tried it, gives the same error.
You’re right, turns out that the rs is empty. Restarting the app and loading the DB again and then selecting that row shows the correct value, so I have to find out what’s happening on the way with the rs value. Thanks.
You better always put a “SelectRowWithValue” into a Try/Catch, like this, because you don’t know what value will be returned from a select:
Try
DesktopPopupmenu.SelectRowWithValue("StrangeValueNotInList")
catch e as InvalidArgumentException
// your error handling here
System.Beep
DesktopPopupmenu.SelectedRowIndex = -1
End Try
1 Like
For debug purposes, change temporally your implementation by the mix of the above suggestions for inspection:
Var theValue As variant
Var theValueWasRead As String = "No"
Try
theValue = rs.Column("PopMenuCategory").Value
theValueWasRead = "Yes"
PopQSCategory.SelectRowWithValue(v) //Popup menu
Catch theError
Break // Check if theValueWasRead and look at theError and theValue
End
Thanks. TheValue and V are coming back as Nil. theValueWasRead comes back as Yes. theError is Value Not Found. It seems somewhere the value is not read or deleted after a ListboxRow is created which is being read correctly again from the DB column when I restart the app.
I have something to think about now, thanks for all the help.
Here is your problem. You are on a row where the column PopMenuCategory is NULL or moved away from valid records reaching rs.EOF as in a empty RecordSet.
I realised now that I have this null rs value because of the new code I recently added. When I Comment them out, there is no crash. So now I will have to find a way to change the popupmenu rows values another way, maybe let this happened on another moment. Mostly that helps.
if PopQSCategory.SelectedRowIndex = 0 then // If the Action Category is selected from the PopQSCategory popup menu...
'//Show Story Type values 0-9
**PopupMenuTypes.RemoveAllRows**
PopupMenuTypes.AddAllRows ("Capture and Escape" , "Chase" , "Coming of Age" , "Kidnap and Rescue" , "Local Adventure" , "Love Story" , "Puzzle" , "Revenge" , "Supernatural Transformation" , "Triumphant Victim")
PopupMenuTypes.SelectedRowIndex = 0
elseif PopQSCategory.SelectedRowIndex = 1 then
**PopupMenuTypes.RemoveAllRows**
PopupMenuTypes.AddAllRows ("Coming of Age" , "Internal Transformation")
PopupMenuTypes.SelectedRowIndex = 0
elseif PopQSCategory.SelectedRowIndex = 2 then
**PopupMenuTypes.RemoveAllRows**
PopupMenuTypes.AddAllRows ("Capture and Escape" , "Character Adventure", "Chase", "Excess and Downfall", "Intense Love Story", "Love Story", "Puzzle", "Revenge", "Supernatural Transformation")
PopupMenuTypes.SelectedRowIndex = 0
end if
A little update on this crash problem. It turns out that the real reason of the No Value error, was because the DB columns that were being read had a Null value. I fixed this problem by giving them a default value while creating a new record after which they an be changed to anything else with the popup menu values. Now it doesn’t crash anymore!