Listbox coding help

Hey again folks. I have a question. I have searched far and wide for ideas on how to go about coding this. The below image will show you what I am trying to achieve.

How would you all go about coding this? I would like the user to click on the Generate button to achieve the Half Cycles value like in the image.

Brian.

thelistbox.cell(somerownumber,0) = cstr(halfcycles)

Not quite working. It kicks back a sub action wanting to create a method.

Your response does not make sense. Could you post some code to show what you mean by “not quite working”?

thelistbox.cell(somerownumber,0) = cstr(halfcycles)

halfcycles means Textfield.Text (replace Textfield with the name of your Textfiled)

No idea what that means.
You didnt just paste the code in and run it, did you?

Thats not the name of your listbox
Thats not the variable you have the rownumber in.
And there needs to be an existing row in the listbox to amend if you address the cells individually like this.

If there isnt, then you need to be doing a

mylistbox.addrow "some data" mylistbox.cell(mylistbox.lastindex,1) = "some data for the second column"

That would have been thelistbox.cell(somerownumber,0) = Textfield.Text

Or are you trying to add multiple rows from 1 to the value that’s entered in Half Cycles?
Something like:

[code]dim total as integer = Val(halfCyclesTextField.Text)

for i as integer = 1 to total
theListBox.AddRow( str(i) )
next[/code]

Bingo Jared. That works.

Here’s your code and what I had to edit.

[code]
dim total as integer = Val(txtHalfCycles.Text)

for i as integer = 1 to total
lbRunList.AddRow( str(i) )
next[/code]

When you come back and ask how to put words into the second cell too, I repeat:

(but using your variable names since you dont work well with generic examples)

for i as integer = 1 to total lbRunList.addrow str(i) lbRunList.cell(lbRunList.lastindex,1) = "some data for the second column" next

[quote=319613:@Jeff Tullin]When you come back and ask how to put words into the second cell too, I repeat:

(but using your variable names since you dont work well with generic examples)

for i as integer = 1 to total lbRunList.addrow str(i) lbRunList.cell(lbRunList.lastindex,1) = "some data for the second column" next[/quote]
Thank you Jeff.

[quote=319613:@Jeff Tullin]When you come back and ask how to put words into the second cell too, I repeat:

(but using your variable names since you dont work well with generic examples)

dim total as integer = Val(txtHalfCycles.Text) for i as integer = 1 to total lbRunList.addrow str(i) lbRunList.cell(lbRunList.lastindex,1) = "Free Run " + txtWraps.text + " Turn(s)" next[/quote]

Hi Jeff. I was wondering how to make the above still show all the halfcycles and in the second cell at the top only show by default
“Free Run " + txtWraps.text + " Turn(s)” only in the second cell?

You just need to take that line out of the for loop and specify which cell you want to write the string into.

So remove this from the for loop:

lbRunList.cell(lbRunList.lastindex,1)  =  "Free Run " + txtWraps.text + " Turn(s)"

Change it to this and place it after the for loop:

lbRunList.cell(0,1)  =  "Free Run " + txtWraps.text + " Turn(s)"

Bingo Jared. I was trying to take out the array, forgive my lack of nomenclature for it.

Okay. After reading a few books and doing some searching through the xdev and the sort. I am stuck with this below image shows that the first part of the Generate button works quite well. But I’m getting a repeat of the user input from,

dim total as integer = Val(txtHalfCycles.Text) for i as integer = 1 to total lbRunList.addrow str(i) lbRunList.cell(0,1) = "Free Run For " + txtPartsField.text + " Part(s) " + " X " + txtBightsField.text + " Bight(s) " + txtWraps.text + " - ½ Turn(s) "_ + "OR " + txtWraps1.Text + " Full Wraps" lbRunList.Cell(lbRunList.LastIndex, 1) = txtCoding.Text next

Is the repeats from the str(i)? or something else.

The repeating “U1 O1” string is coming from:

lbRunList.Cell(lbRunList.LastIndex, 1) = txtCoding.Text

So to explain what’s going on as clearly as I can.
The line below adds a new row to the listbox every time you go through the loop and puts the value of the variable i, as a string, into the first column in the newly added row:

lbRunList.addrow str(i)

This next line of code is setting the value of cell(0,1) to the concatenated string that you are defining here. Since the values of row and column in cell(0,1), which is row 1 column 2, are hard coded, you are actually doing the exact same thing every loop. You should ideally remove this line from the loop and put it after, so that it only runs once.

lbRunList.cell(0,1) = "Free Run For " + txtPartsField.text + " Part(s) " + " X " + txtBightsField.text + " Bight(s) " + txtWraps.text + " - ½ Turn(s) "_ + "OR " + txtWraps1.Text + " Full Wraps"

The last line of code says to put the value of txtCoding.Text in the second column (column index 1) of the last row (identified by lbRunList.LastIndex). The last row had just been created previously by the lbRunList.addrow method. So each time you go through the loop, this will reference the newly created row in the list box and put the same value into the second column of every row.

lbRunList.Cell(lbRunList.LastIndex, 1) = txtCoding.Text

So that’s the wordy version of why it’s happening, but without knowing how you intend for the application to function, it’s hard to provide an example that will do exactly what you are looking for.

I have drop box and a video of where this concept came from. Would you like to view it Jared? It will explain alot.

You are definitely better off understanding what is going on and writing the code yourself. It’s the best way to learn.

I was trying to say that example code will rarely be exactly what you are looking for, but it’s good to use as a functioning starting point on which to expand and implement your own ideas.

5part 4bight Algorithm

That’s a drop box link.

I have RealBasic The Definitive Guide. I do look at that a lot. I also have from novice to professional book. that one is not so good. But the definitive guide has been helpful for the most part.