VBAndCs / sVB-Small-Visual-Basic

Small Visual Basic (sVB) is an educational programming language, created by Eng. Mohammad Hamdy as an evolved version of Microsoft Small Basic (SB). It is meant to be easier and more powerful at the same time, to introduce programming basics to kids and beginners of any age, provided that they can use the English keyboard on the Windows OS.
Other
222 stars 16 forks source link

The call to ListBox.AddItem(name) within the Form.OnShown event triggers an error. #67

Closed dynamicboy closed 1 month ago

dynamicboy commented 1 month ago

verson: sVB 3.0.7.3 details: The call to ListBox.AddItem(name) within the Form.OnShown event triggers an error. When I move it out of OnShown event, the error goes away. screenshot: bug bug2

VBAndCs commented 1 month ago

I think I mentioned in the notes that OnShown and the global area should not be used dependently. Try this:

A = {1, 2, 3}

' ------------------------------------------------
Sub Form1_OnShown()
   ForEach item In A
      ListBox1.AddItem(item)
   Next
EndSub

This code will display an empty list box, because the OnShown event is fired after the Form.Show method is called in the code behind file (form.sb.gen), and before the A = {1, 2, 3} line is called. So, you need to be careful when using this organization. If is recommended to put all the code in the global area, and don't use the OnShown event unless there is some code that requires that form and controls are already shown. You may say: The OnShwon Event will always run first and the form is already shown, but sometimes this mat take a while, so the global code may run first! This is why I recommend to put all code together in one place: either in the global area or in the OnShown event, but never divided on both. In fact I added the OnShow to solve an expected issue but it haven't happened yet :D So, try to forget about this event for now :)


From: dynamicboy @.> Sent: Friday, June 14, 2024 2:29 PM To: VBAndCs/sVB-Small-Visual-Basic @.> Cc: Subscribed @.***> Subject: [VBAndCs/sVB-Small-Visual-Basic] The call to ListBox.AddItem(name) within the Form.OnShown event triggers an error. (Issue #67)

verson: sVB 3.0.7.3 details: The call to ListBox.AddItem(name) within the Form.OnShown event triggers an error. When I move it out of OnShown event, the error goes away. screenshot: bug.png (view on web)https://github.com/VBAndCs/sVB-Small-Visual-Basic/assets/7421525/6dd714cd-5315-4551-9d20-a68b34d75f29 bug2.png (view on web)https://github.com/VBAndCs/sVB-Small-Visual-Basic/assets/7421525/70d70c03-2966-4377-a4b7-04eca731a8f7

— Reply to this email directly, view it on GitHubhttps://github.com/VBAndCs/sVB-Small-Visual-Basic/issues/67, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALQ5MVXXUSGZLL7IHR7MAATZHL46PAVCNFSM6AAAAABJKO7P2WVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM2TGNJQGY2DSMI. You are receiving this because you are subscribed to this thread.Message ID: @.***>

dynamicboy commented 1 month ago

Yes, I just test it. Sometimes the listbox is full, sometimes it is empty. For now, declare variables in global area, initialize them in OnShown Event. 2024-06-15_133020