PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: i tried to make this work but to no avail...  (Read 327 times)

veltesian

  • Little Newbie
  • *
  • Posts: 47
i tried to make this work but to no avail...
« on: August 11, 2020, 11:39:30 PM »

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.
« Last Edit: August 12, 2020, 01:07:44 AM by veltesian »
Logged

philbar

  • Little Newbie
  • *
  • Posts: 18
Re: i tried to make this work but to no avail...
« Reply #1 on: August 12, 2020, 04:48:18 AM »

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:

Code: [Select]
' 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
Logged

veltesian

  • Little Newbie
  • *
  • Posts: 47
Re: i tried to make this work but to no avail...
« Reply #2 on: August 12, 2020, 10:37:32 PM »

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.
Logged

philbar

  • Little Newbie
  • *
  • Posts: 18
Re: i tried to make this work but to no avail...
« Reply #3 on: August 13, 2020, 03:31:25 AM »

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.
Logged

jermy

  • Junior Member
  • **
  • Posts: 60
Re: i tried to make this work but to no avail...
« Reply #4 on: August 13, 2020, 06:18:57 AM »

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

veltesian

  • Little Newbie
  • *
  • Posts: 47
Re: i tried to make this work but to no avail...
« Reply #5 on: August 13, 2020, 07:55:04 AM »

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!
« Last Edit: August 13, 2020, 09:09:18 AM by veltesian »
Logged

veltesian

  • Little Newbie
  • *
  • Posts: 47
Re: i tried to make this work but to no avail...
« Reply #6 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.
Logged

Bumblebee

  • Junior Member
  • **
  • Posts: 50
Re: i tried to make this work but to no avail...
« Reply #7 on: August 13, 2020, 09:24:59 PM »

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

Josť Roca

  • Guru Member
  • *****
  • Posts: 3282
Re: i tried to make this work but to no avail...
« Reply #8 on: August 13, 2020, 10:30:11 PM »

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

  • Administrator
  • Guru Member
  • *****
  • Posts: 9313
  • Windows 10
    • PlanetSquires Software
Re: i tried to make this work but to no avail...
« Reply #9 on: August 14, 2020, 09:54:53 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.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

veltesian

  • Little Newbie
  • *
  • Posts: 47
Re: i tried to make this work but to no avail...
« Reply #10 on: August 14, 2020, 10:43:08 PM »

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.
Logged