Greetings,

I want to add some numbers to a combobox, i want the numbers to be from 1-100 but instead of writing example

combobox1.items.addrange({1, 2, 3, 4, 5, etc, 100})

how can i else write it ? :) TY

i don't know how to do that, thats why i ask here :) i tried to search for it, but didn't know what exactly to search for.

Loops are programming 101. You really shouldn't be trying to write a GUI until you at least understand the most basic core concepts of the language. It's also not very wise to jump right in without any kind of beginner text; you should find yourself a book on VB.NET, any of them will do.

Comments
Words :)

Well, my problem is that i have a hard time learning reading such stuff. I have a "sickness" which makes my memory less durable to such readings. And i found forums the best way for me to learn.

Anyways

    Dim i As Integer = 0
    For i = 1 To 60
        LevelCombo.Items.Add(i)
    Next

i tried this code @ my levelcombo.click - however it seems to have a delay time, can i add this code directly to mybase.load ? :)

Edited 4 Years Ago by fRodzet

And i found forums the best way for me to learn.

People will quickly become tired of teaching you basics that are written in every beginner book in print, especially if you try to write programs that are far beyond your current level.

however it seems to have a delay time, can i add this code directly to mybase.load ? :)

I'm not sure what you mean by "delay time", but the items won't be added until after you click levelcombo to fire the event. You could certainly add the items from your Load event, and unless they depend on user action or are completely static that would probably be the best approach. If they're static (ie. set at design time) then you should consider creating them at design time and avoiding the overhead of generating them at runtime.

Hate to tell you this guys, but this is a forum set up to help people learn to program. It doesn't matter if they are still on the basics, you should still help....and if you don't want to help then don't reply!!

fRodzet, to add numbers you just have to create a "FOR" loop as follows

For i = 1 to 100
    combobox1.items.add(i)
Next

Basically, this starts with i=1, it then adds the value of i (in this case 1) to the combobox. It then loops round and makes i=2, then adds i to the combobox...and so on and so on.

You dont want the "Dim i as integer = 0" before it because it just adds extra processing.

Edited 4 Years Ago by ObSys

It doesn't matter if they are still on the basics, you should still help....and if you don't want to help then don't reply!!

I don't see any lack of helping in this thread, to what are you referring? Perhaps you should actually read the thread in its entirety before acting like a net nanny.

I believe if you go to the DaniWeb home page you will see

Technical Support Question? Free Help.

I don't recall seeing anywhere something that says "we are here to teach you how to program". There are many resources out there for teaching programming. There is no shortage of good websites and books. A lot of the material is free. Because the OP claims to have a problem with printed material (dyslexia is one valid reason), I suggested an excellent (and free) video series. I believe that qualifies as "help".

Reverend Jim, I was not refering to your comment. I was talking about deceptikon, I am sorry, I should have made that more clear.

As for deceptikon, the way you write responses comes across rude and arrogant. I personally have no problem with you but the fact that you were so blunt with someone who is obviously new to IT annoys me as everyone has to start somewhere. So stop getting your knickers in a twist.

Comments
Well said

So stop getting your knickers in a twist.

Please consider taking your own advice. You seem to be the only one who has a problem with my responses, so maybe the problem is you being overly sensitive and not me being unhelpful, rude, or arrogant.

Use System.Linq.Enumerable.Range(start,count) method to sequence of Integer numbers.

For example,

 ComboBox1.Items.AddRange(Enumerable.Range(1, 100).Cast(Of Object)().ToArray())

Thanks for the Answers everyone.

_avd, that code seems more confusing than:

For i = 0 to 100
combobox1.items.add(i)
next

Is there any reasons to use your code over the one i showed above ?

While it is a pretty cool and concise way to do what you wanted, I strongly suggest that as a beginner you stick with the simpler, clearer version (for loop). I wouldn't personally use the complicated version in a program without also including a comment stating exactly what it is doing.

This article has been dead for over six months. Start a new discussion instead.