• Welcome to PlanetSquires Forums.
 

i tried to make this work but to no avail...

Started by veltesian, August 11, 2020, 11:39:30 PM

Previous topic - Next topic

veltesian

much apologies to keep coming back to an already open topic but.....

included with this post is a gui form i was attempting to just add & configure
a ListBox control but i keep getting 4 errors relating to the IDC_LISTBOX not being
understood/defined or not much of descriptive code parts to ID it. also i first took this
from one of the templates included with winfbe to study from but i can't see where
i could break with just the add listbox code.... but then thats where the errors start.
i would hope to figure out how to add a button also to that & give it a custom function
like toggling the items within the ListBox or transferring text/data from textbox 2 listbox
for updating the contents/etc....  something of that nature.

button code example within the included form i wish to change:
' // Add a cancel button
    'pWindow.AddControl("Button", , IDCANCEL, "&Close", 10, 10, 45, 23)

i would like to know how can the code above be changed to reflect a button that could edit
parts of the listbox such as toggling the items within the ListBox or transferring text/data
from textbox 2 listbox, etc....


thanks a million ahead of time for anyone who could help.

philbar

Eek.

Seriously, it's a lot easier if you work with the project manager instead of against it, and let the designer take care of your forms for you. What you're doing here is trying to create a "raw" Windows program from scratch, and the reason I use WinFBE is to avoid that.

Getting back to your problem, the IDC_xxx things are just numbers (LONG, to be specific). Every gadget you put on your form has to have a unique one. People who do these things typically start at 10000, say, for the first gadget and then 10001 for the next gadget, etc. FreeBasic was complaining because you used IDC_LISTBOX but you never defined it or gave it a value. If you're using the Visual Designer, it takes care of that for you, and you never even see the ID number unless you look for it.

Instead of that, use the project manager:

1. When you start WinFBE, click the "New Project" button. It will ask you for a path, and the "..." button will give you an Explorer-type window to help you choose one. That's where you choose a name for the project, for example, ListBoxTest. I always create a new folder for each project that I start: that way, when I've learned all I can from this project, I can delete the whole folder and not worry about losing something else that's still important.

2. Under "Templates", click "Visual Designer", and make sure the "Create Resource File and Manifest" box is checked. When you click OK, it does several things for you: (a) It creates a project file called, say, ListBoxTest.wfbe. Don't mess with that. (b) It creates a main program file called ListBoxTest.bas. For simple projects you won't even need to look at it, but if you need to reference outside files, this is where you put the #include statements. (c) It creates your initial Form file, called frmMain.inc. If you don't like the name frmMain, that's fine: the top entry in the Property box for the form is the name; change it to anything you like, but I recommend choosing the name before you start adding gadgets to the form.

Now you're ready to go. You can concentrate on designing your form and what to do when each gadget needs attention. You don't have to worry about the wsz... and the IDC... and the hideous message loop SELECT block.

Here's a quick sample, you can make it more elaborate:

' frmMain form code file
''
''
'My form consists of a text box, a button, and a list box.
'When you click the button the text is added to the list box
'    and the text box shows the item number.

Function frmMain_Button1_Click( ByRef sender As wfxButton, ByRef e As EventArgs ) As LRESULT
   dim as string TextLine
   dim as long n
   
   Textline = frmmain.Text1.text
   n = frmmain.List1.Items.Add(TextLine)
   frmmain.Text1.Text = "Added item #" + str(n)
   Function = 0
End Function


veltesian

hello philbar

thanks for explaining that to me.... i tried to open project & i pasted the code you showed me into a frmMain.inc
i had to add the 3 main CTRLs (button/textbox/listbox) and saved the project to a separate folder.... when pressing F5
it shows no errors... but the controls do nothing. i would gladly zip the whole project up and upload it .... i think it'll
zip up to a comfy 60 - 90 kb.

philbar

Don't forget to enable the Click event for the button.

In the design mode, select the button, choose the Events tab in the floating toolbox and check the Click box.

jermy

Don't forget to enable the Click event for the button.

veltesian

#5
ROFL..... oh my, yes i did forget in checking the click event ...... OMG i can't believe i did that.....
& yes it works just fine... thanks philbar & jermy. i gotta keep on that. i think i had done that a
few times already..... embarrassing for me :(

so a combobox is machanically the same thing when it comes to controls? interesting!

veltesian

i was also wondering about how can a button be programmed to toggle thru a number of listbox items
& select the items in a consecutive way,..... 1 after the other. perhaps if i could see what it would take
for a looping behavior, as it would get to the last item it loops back to the very 1st item.

Bumblebee

You can set a static variable in the button click event, to serve as a click counter.
Failed pollinator.

José Roca

1- Get the count of items in the listbox.

2.- Get the index of the currently selected item, if any.

3.- Increase the index by one.

4.- If index equal to count then index = 0

5.- Select the item with the new index.

Paul Squires

Quote from: veltesian on August 13, 2020, 02:27:28 PM
i was also wondering about how can a button be programmed to toggle thru a number of listbox items
& select the items in a consecutive way,..... 1 after the other. perhaps if i could see what it would take
for a looping behavior, as it would get to the last item it loops back to the very 1st item.

Here you go. Please see attachment.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

veltesian

a special thanks goes out to.......

bumblebee - for the suggestion of using a static variable. i had thought also
philbar suggested the use of a static variable too.... thanks to the both of you.

jose & paul - and a special thanks to both of you for the much needed as well
information/material support. :D

ps: btw paul the listbox.bas you have for upload works fantastic... it solved a few questions
i had about how to use the "count" & "selected index" parts of code. i unfortunately
sometimes might need to see a working model of programming code to help me
understand a way of how to duplicate it in code so that errors might be minimal.