OH no! i'm making a dropdown menu!!

Blitz3D Forums/Blitz3D Beginners Area/OH no! i'm making a dropdown menu!!

Hey, i'm making a dropdown menu function, after i'm done with it, it will be released into the code archive under userinput, this is the second GUI type thing i'v made (see 'Input "Field" ' under user input on CA's)

progress is great, in one day i got most of it done (i'm a newb yes i know)

i have a problem though...

This is what i have so far, im having a problem displaying the options, i'm using types as the options looping thru them and displaying all the "names" of all the objects under that type... and of course making them clickable...

heres my code, tell me what i'm doing wrong, i'm stumped it looks fine to me.. i'v been messing with this for multible hours, still no avail..



Graphics 300,500,16,2
SetBuffer BackBuffer()


Type item
   Field name$
End Type

test.item= New item
test\name="test"

test2.item = New item
test\name="test2"


drawdrop=False
words$=""

While Not KeyHit(1)
Cls

If RectsOverlap(125,50,25,20,MouseX(),MouseY(),10,10) And MouseHit(1)
If drawdrop=False
drawdrop=True
Else
drawdrop=False
End If
End If

If drawdrop=True
Rect 50,50,100,200,0
For itemname.item=Each item


Text 50,50+(i*20),itemname\name

If RectsOverlap(50,50+(i*20),75,20,MouseX(),MouseY(),10,10) And MouseDown(1)
words=itemname\name
End If

Next
End If


Rect 50,50,100,20,0
Rect 125,50,25,20,0
Text 50,50,words



Delay 5
Flip
Wend
End


Hmm, this works:



Graphics 300,500,16,2
SetBuffer BackBuffer()



drawdrop=False
words$=""
pickedword$="testing"

options=5

While Not KeyHit(1)
Cls

If RectsOverlap(125,50,25,20,MouseX(),MouseY(),10,10) And MouseHit(1)
If drawdrop=False
drawdrop=True
Else
drawdrop=False
End If
End If

If drawdrop=True
Rect 50,50,100,200,0
For i=1 To options

pickedword=i

Text 50,50+(i*20),pickedword

If RectsOverlap(50,50+(i*20),75,20,MouseX(),MouseY(),10,10) And MouseDown(1)
words=pickedword
End If


Next
End If


Rect 50,50,100,20,0
Rect 125,50,25,20,0
Text 50,50,words



Delay 5
Flip
Wend
End


but how do i get somthing like the first post to work??

Hmm, this works as well:


Graphics 300,500,16,2
SetBuffer BackBuffer()


drawdrop=False
words$=""
pickedword$="testing"

options=5

While Not KeyHit(1)
Cls

If RectsOverlap(125,50,25,20,MouseX(),MouseY(),10,10) And MouseHit(1)
If drawdrop=False
drawdrop=True
Else
drawdrop=False
End If
End If

If drawdrop=True
Rect 50,50,100,200,0
For i=1 To options

If i=1 pickedword="testing"
If i=2 pickedword="this"
If i=3 pickedword="dropdown"
If i=4 pickedword="cause"
If i=5 pickedword="i can"

Text 50,50+(i*20),pickedword

If RectsOverlap(50,50+(i*20),75,20,MouseX(),MouseY(),10,10) And MouseDown(1)
words=pickedword
End If


Next
End If


Rect 50,50,100,20,0
Rect 125,50,25,20,0
Text 50,50,words



Delay 5
Flip
Wend
End


but i want it to display a field of multible objects(types)

like the first post...

if you have 4 types:

type1.type = new type
type1\name$="type1"


ect ect..

i want to know how to display those "name" fields in the same way as the working code above?

This one works more like a WinXP dropdown.

Graphics 300,500,16,2
SetBuffer BackBuffer()


drawdrop=False
words$=""
pickedword$="testing"

options=5

While Not KeyHit(1)
Cls

If RectsOverlap(125,50,25,20,MouseX(),MouseY(),10,10) And MouseHit(1)
If drawdrop=False
drawdrop=True
Else
drawdrop=False
End If
End If

If drawdrop=True
Rect 50,50,100,200,0
For i=1 To options

If i=1 pickedword="testing"
If i=2 pickedword="this"
If i=3 pickedword="dropdown"
If i=4 pickedword="cause"
If i=5 pickedword="i can"

Text 50,50+(i*20),pickedword

If RectsOverlap(50,50+(i*20),75,20,MouseX(),MouseY(),10,10) And MouseDown(1)
words=pickedword
drawdrop=False
End If


Next
End If


Rect 50,50,100,20,0
Rect 125,50,25,20,0
Text 50,50,words



Delay 5
Flip
Wend
End


Cool, didnt think about that, I'm still stumped about displaying types... HELP!

I think you need For..Each for that:
For it.Type = Each Type
  Print it\name$
Next


Thats what i thought, tell me whats wrong with the example on the first post...

it uses For...Each

yet it doesnt work, i cant figure out why, any ideas?

i

? Yes, i notice the "i" error in the program, but my question more or less is what do i replace that with?

I can give you a little bit of code that allows you to move the window but it still works when you click the numbers

?

Hmmmmmm this is what i got so far, it still doesnt work! any ideas?:



Graphics 300,500,16,2
SetBuffer BackBuffer()

Type item
   Field name$
End Type

test.item= New item
test\name="test"

test2.item = New item
test\name="test2"

;Drawdrop=false for now until it is pressed, and words$="" thats the text thats at the top
drawdrop=False
words$=""


;Selection, to keep the menu going untill you hit "1"
selection=1

While selection=1
Cls

;If you click on the button, dropdown=true
If RectsOverlap(125,50,25,20,MouseX(),MouseY(),10,10) And MouseHit(1)
  If drawdrop=False
     drawdrop=True
Else
   drawdrop=False
  End If
End If

If drawdrop=True
Rect 50,50,100,200,0

;For...Each ... should get the name of all the objects.
For namei.item = Each item

;Made this for i...2 loop so the text can loop itself...
  For i=1 To 2
     Text 50,50+(i*20),namei\name

;If you click on one of the names it will put it up top.
     If RectsOverlap(50,50+(i*20),75,20,MouseX(),MouseY(),10,10) And MouseDown(1)
        words=namei\name
        drawdrop=False
     End If


  Next
Next
End If

;Draws the Button to dropdown and the main box, and draws the words you picked..
Rect 50,50,100,20,0
Rect 125,50,25,20,0
Text 50,50,words

;If you hit "1" go to the next screen
If KeyHit(2)
selection=2
End If

;If ESC then exit
If KeyHit(1) Then
End
End If

;Flip wend
Delay 5
Flip
Wend


;The next screen
While Not KeyHit(1)
Cls
Text 50,50,"You selected: "+words

Delay 5
Flip
Wend
End


There is one typo, after "test2.item = new item" it says "test\name" while it should be "test2\name"
And the "For i=1 to 2" loop should be removed. You could increase i yourself during the "For Each item" loop, like this:
i = 0
For namei.item = each item
 i = i + 1
 text etc..etc
Next


That simple eh? HOW ON EARTH DID I MISS THAT?!?!?!!


Thanks!

Well, heres a good question, how would you go about making a scroll-bar if the number of "options" is too much for the box?

i'll mess with it, at least i got a prototype going!

Well, maybe you could try the ViewPort command. Everything that is outside the defined viewport will not be drawn.
ViewPort 100, 100, 100, 200
..draw box..
ViewPort 0, 0, graphicswidth(), graphicsheight()

WOW, thats a neat little command, i'll mess with it, it looks to be just what i need.

Hmm, the scroll-bar is starting to work, but i notice one little strange bug, let me know if you have a fix for it.


my code:


Graphics 300,500,16,2
SetBuffer BackBuffer()

Type item
   Field name$
End Type

test.item= New item
test\name="test"

test2.item = New item
test2\name="test2"

test3.item = New item
test3\name="test3"

test4.item = New item
test4\name="test4"

test5.item = New item
test5\name="test5"

test6.item = New item
test6\name="test6"

test7.item = New item
test7\name="test7"

test8.item = New item
test8\name="test8"

test9.item = New item
test9\name="test9"

test10.item = New item
test10\name="test10"

test11.item = New item
test11\name="test11"

test12.item = New item
test12\name="test12"

;Drawdrop=false for now until it is pressed, and words$="" thats the text thats at the top
drawdrop=False
words$=""


;Selection, to keep the menu going untill you hit "1"
selection=1

scrolly=70

limit=0
shown=50

While selection=1
Cls

;If you click on the button, dropdown=true
If RectsOverlap(125,50,25,20,MouseX(),MouseY(),10,10) And MouseHit(1)
  If drawdrop=False
     drawdrop=True
Else
   drawdrop=False
  End If
End If

If drawdrop=True
Rect 50,50,100,200,0

;For...Each ... should get the name of all the objects.
i=0
For namei.item = Each item
i=i+1
;limit=i*20

;Scroll bar code
Rect 125,70,25,180,False
If i>9 
   Rect 125,scrolly,25,20,True
  If RectsOverlap(125,70,25,180,MouseX(),MouseY(),10,10) And MouseDown(1)
     scrolly=MouseY()
  End If
If scrolly<70 scrolly=70
If scrolly>230 scrolly=230

shown=-scrolly+120
End If

Viewport 50,70,100,180
;Made this for i...2 loop so the text can loop itself...
   Text 50,shown+(i*20),namei\name
Viewport 0,0,GraphicsWidth(),GraphicsHeight()

;If you click on one of the names it will put it up top.
     If RectsOverlap(50,shown+(i*20),75,20,MouseX(),MouseY(),10,10) And MouseDown(1)
        words=namei\name
        drawdrop=False
        shown=50
        scrolly=70
     End If


Next
End If

;Draws the Button to dropdown and the main box, and draws the words you picked..
Rect 50,50,100,20,0
Rect 125,50,25,20,0
Text 50,50,words
Text 0,0,scrolly

;If you hit "1" go to the next screen
If KeyHit(2)
selection=2
End If

;If ESC then exit
If KeyHit(1) Then
End
End If

;Flip wend
Delay 5
Flip
Wend


;The next screen
While Not KeyHit(1)
Cls
Text 50,50,"You selected: "+words

Delay 5
Flip
Wend
End


Notice how after "test9" the text seems to lagg behind the rest... test 10 - thru - 12, are laggying behind the ones ontop of it..

any ideas?

Move the section that is labelled ;scroll bar code outside the For..Each loop. Now the scrollbar is updated while the items are being drawn, causing the lag.
And I think you can move the ViewPort commands outside the loop as well, put one of them right before the loop, and the other one after it. But that shouldn't make a big difference, in the long run it might be faster.

Thanks at the moment i'm trying to figure out how to move the text faster then the scrollbar is being moved (like when i have alot of text in there)

got any advice?

nice! but why you don't use a pre-made GUI or do you make your own?

I like to understand on how things work (sounds wierd) but yeah. the best way to learn how they work is make it yourself :)

plus its fun, this is going into a calculator thingy i'm working on.

ok, at the moment i'm working on a system: the more "types" it reads off the faster scrolling speed it has, so it compensates for having more text:

Graphics 300,500,16,2
SetBuffer BackBuffer()


Type item
   Field name$
End Type

For i=1 To 200;Play with this number and you will see the error
test.item = New item
test\name="test"+i
Next

;words$="" thats the text thats at the top
words$=""


;Selection, to keep the menu going untill you hit "1"
selection=1

scrolly=70

limit=70
shown=50

While selection=1
Cls

;If you click on the button, dropdown=true
If RectsOverlap(125,50,25,20,MouseX(),MouseY(),10,10) And MouseHit(1)
  If drawdrop=False
     drawdrop=True
Else
   drawdrop=False
  End If
End If

If drawdrop=True
Rect 50,50,100,200,0

;For...Each ... should get the name of all the objects.
i=0
For namei.item = Each item
i=i+1
;limit=i*20

;Made this for i...2 loop so the text can loop itself...
Viewport 50,70,100,180
   Text 50,shown+(i*20),namei\name
Viewport 0,0,GraphicsWidth(),GraphicsHeight()

;If you click on one of the names it will put it up top.
     If RectsOverlap(50,shown+(i*20),75,20,MouseX(),MouseY(),10,10) And MouseDown(1)
        words=namei\name
        drawdrop=False
        shown=50
        scrolly=70
     End If


Next
Rect 125,70,25,180,False
If i>9 
   Rect 125,scrolly,25,20,True
  If RectsOverlap(125,70,25,180,MouseX(),MouseY(),10,10) And MouseDown(1)
     scrolly=MouseY()
  End If
If scrolly<70 scrolly=70
If scrolly>230 scrolly=230
;TTS=-scrolly+10*4

scrollspeed#=i/8.38


;190 for *2
shown=120+scrollspeed*70-70-scrolly*scrollspeed


End If

End If

;Draws the Button to dropdown and the main box, and draws the words you picked..
Rect 50,50,100,20,0
Rect 125,50,25,20,0
Text 50,50,words
Text 0,0,"Scroll-Y: "+scrolly
Text 0,20,"DD Text: "+shown
;Text 0,40,"Limit"+limit
;If you hit "1" go to the next screen
If KeyHit(2)
selection=2
End If

;If ESC then exit
If KeyHit(1) Then
End
End If

;Flip wend
Delay 5
Flip
Wend


;The next screen
While Not KeyHit(1)
Cls
Text 50,50,"You selected: "+words

Delay 5
Flip
Wend
End


everything works good, now: Change the amount of "items" the top item creating loop makes.. and watch the error..

How do i solve this?

It seems to be working quite allright? Do you mean, that the list items don't 'fit' ?
It is caused by the conversion from 'scrolly' to 'shown'. It should be like this:
shown = 50 - (scrollbarpos * listsize / scrollbarmax)

Scrolly is in the range 70..230, easiest is to make it start from zero, so substract 70 from it:
ScrollbarPos = ScrollY - 70
ScrollbarMax = 230 - 70

The list length is the number of items * 20, but it is nicer to leave 9 items (max. visible) in view when scrolled down completely, so substract (9*20) from it:
ListSize = (i - 9) * 20

hmm, i don't think i get it, could you replace some of the veriables with names of veriables that i use? so i can figure what is what? i don't think i even have a "ScrollbarMax" type thing

Edit: and my problem is.. that the "scrollspeed#=i/8.38" and "shown=120+scrollspeed*70-70-scrolly*scrollspeed"

The basic idea is that every "8.38" loops add 1 to the veriable "Scrollspeed" then i multiply this number on how greater the text moves compared to the scrollbar .. Everytime "i" loops it means 1 more type is there.. so every 8.38 loops, the text should scroll faster

All this works, but the problem is i have make a different number (8.38 for 200 types) for different amount of types

any ideas?

But I did use your variables ? Replace the part that says:
;190 for *2
shown=120+scrollspeed*70-70-scrolly*scrollspeed

with this:
ScrollbarPos = ScrollY - 70
ScrollbarMax = 230 - 70
ListSize = (i - 9) * 20 
shown = 50 - (scrollbarpos * listsize / scrollbarmax)


No, he made ScollbarMax in order to better define your
shown=120+scrollspeed*70-70-scrolly*scrollspeed
It looks like it'll probably work to me (but I'm knew to all of this). You should be able to just replace the old line with his 4 lines.

Doh, Sorry about that, i see it now.

Thanks!!

Say, is there a way to pass a type thru a function?

like so:

type item
field blah
end type

test(item)

;---

Function test(typename)

for test.typename = each typename
next

end function


No, I don't believe that is possible. You could however use this:
Type itemtype
  Field blah
End Type

item.itemtype = New itemtype
item\blah = 4

test(item)

WaitKey()
End

;---

Function test(item.itemtype)

Print item\blah

End Function

But that is different from what you mean.
What do you need it for ? Maybe there is a better way of doing it. You could for instance use a single type:
	Type itemtype
		Field itemkind
	    Field blah
	End Type
	
	;create 4 items, kind 1
	item.itemtype = New itemtype
	item\itemkind = 1
	item\blah = 4
	
	item.itemtype = New itemtype
	item\itemkind = 1
	item\blah = 3
	
	item.itemtype = New itemtype
	item\itemkind = 1
	item\blah = 2
	
	item.itemtype = New itemtype
	item\itemkind = 1
	item\blah = 1
	
	;create 4 items, kind 2
	item.itemtype = New itemtype
	item\itemkind = 2
	item\blah = 100
	
	item.itemtype = New itemtype
	item\itemkind = 2
	item\blah = 102
	
	;test items
	Print "itemkind 1:"
	test(1)
	
	Print
	Print "itemkind 2:"
	test(2)
	
	WaitKey()
	End
	
;---

Function test(kind)

	For item.itemtype = Each itemtype
		If item\itemkind = kind Then
			Print item\blah
		End If
	Next

End Function


Well i'm making a function , trying to make it as portable and reuseable as possible..

the idea is.. the user makes a type, and then the drop down menu will tkae the fed type and read off all of the options in it, like the dropdown menu examples above..

i want the user to be able to feed a type name into the function, then the For...Each loop in the function will read off all the strings in the type, these strings will be selectable,

one they are selected, the main string that the function returns is filled with the selected string..

then this return string can be used..

thats what i want to do, unless theres a better way to do this.

Well, then I would take the 2nd example, and change the \itemkind field into a string. The string can be used to classify items, so you can determine for each item in the typelist, to which (sub)list it belongs. Sort of like this:
;itemlist type
Type itemlist
  Field name$        ;name of the item
  Field belongs_to$  ;to determine to which list the item belongs
End Type

;create two items for list called 'list one'
item.itemlist = New itemlist
item\name$ = "New"
item\belongs_to$ = "list one"

item.itemlist = New itemlist
item\name$ = "Load"
item\belongs_to$ = "list one"

;create two items for list called 'list two'
item.itemlist = New itemlist
item\name$ = "Dave"
item\belongs_to$ = "list two"

item.itemlist = New itemlist
item\name$ = "Dan"
item\belongs_to$ = "list two"

;print stuff that belongs to list one
For item.itemlist = Each itemlist
	If item\belongs_to$ = "list one" Then Print item\name$
Next

WaitKey()
End


interesting... i'll mess with that, Thanks!

is there a limit to how many If statments can be in a if statment?

Oi, Problem..

Why does it not change "dropdown" when this is clicked?

Function CreateDropDown$(words$,number)


;Selection, To keep the menu going untill you hit "1"

scrolly=70

shown=50


;If you click on the button, dropdown=True
If RectsOverlap(125,50,25,20,MouseX(),MouseY(),10,10) And MouseHit(1)
  If drawdrop=False
     drawdrop=True
Else
   drawdrop=False
  End If
End If

If drawdrop=True
Rect 50,50,100,200,0

;For...Each ... should get the name of all the objects.
;i=0
;For checklist.list = Each list

;If checklist\listnumber=number
;i=i+1

;Made this For i...2 loop so the Text can loop itself...
;Viewport 50,70,100,180
 ;  Text 50,shown+(i*20),checklist\name
;Viewport 0,0,GraphicsWidth(),GraphicsHeight()

;If you click on one of the names it will put it up top.
 ;   If RectsOverlap(50,shown+(i*20),75,20,MouseX(),MouseY(),10,10) And MouseDown(1)
  ;;       words$=checklist\name
    ;;    drawdrop=False
      ;;;  shown=50
     ;   scrolly=70
    ; End; If


;End If
;Next
;Rect 125,70,25,180,False
;If i>9 
 ;  Rect 125,scrolly,25,20,True
 ;;; If RectsOverlap(125,70,25,180,MouseX(),MouseY(),10,10) And MouseDown(1)
 ;    scrolly=MouseY()
 ; End If
;If scrolly<70 scrolly=70
;If scrolly>230 scrolly=230

;The more things in the text the faster it scrolls to compensate..
;ScrollbarPos = ScrollY - 70
;ScrollbarMax = 230 - 70
;ListSize = (i - 9) * 20 
;shown = 50 - (scrollbarpos * listsize / scrollbarmax)


;End If

End If



;Draws the Button to dropdown and the main box, and draws the words you picked..
Rect 50,50,100,20,0
Rect 125,50,25,20,0
Text 50,50,words




End Function



Graphics 300,500,16,2

SetBuffer BackBuffer()

Type list
   Field name$
   Field listnumber
End Type

For i=1 To 200

DD1.list = New list
DD1\name="Test"+i
DD1\listnumber=1

Next

For i=1 To 400

DD2.list = New list
DD2\listnumber=2
DD2\name="test"+i

Next

While Not KeyHit(1)

blah$=CreateDropDown$(blah$,1)



Wend 
End



i narrowed it down by blocking out everything else that doesnt have to do with the clicking working..

why does this example not work?

Thanks,
Yahfree

Maybe the main loop needs a 'Flip' ? Because the buffer is set to BackBuffer()

That works, but why doesnt it toggle it? (click it, if its open close, if its closed, open)

Edit: this is wierd, its like it doesnt update, the scrollbar doesnt work, the collisions with the texts doesnt work, it won't close back up when pressed again..

its in the main loop...

First, add a CLS to the loop. Then, add the line:
Global drawdrop
to the start of the program, to make 'drawdrop' a global variable. Else, it is cleared after the 'End Function' command, so it will be zero every time the function starts.

Doh, i missed that..

hey i'm trying to dress this up with a "InitDropDown()" function, that has "Global drawdrop=false,shown=50,scrolly=70"

but it gives me a error, "Global can only appear in main program"

anyway around this? or do i have to deal with it?

Just declare the Globals in the main code, then you can set them to whatever in the function.

k, Also i have to make a few of those global veriables equal to some info i feed into the function..

like:
function blahblah(x)

end function

global Shown=x

while not keyhit(1)
blahblah(100)
flip
wend
end


theirfore Shown=100?

possible or not?

No. x doesnt have scope outside the function. Just put Shown = x inside the function.

but then i have the problem of it constantly replacing itself in the main loop thats why i made the global veriables in the first place

Sorry, I'm lost as to what you're trying to do.

i have a veriable, that keeps track of where to draw the scrollbar part of the menu.

if i don't declare it before the main loop it keeps resetting itself, EG the scrollbar won't move.

but, the functions in the main loop.

and the veriable must equal somthing you feed into the function.

so i need somthing that can get info from somthing you feed into the function, outside the function.

any ideas?

and the veriable must equal somthing you feed into the function.
So, why doesn't setting the global variable inside the function work?

Because it has to be able to change, and because the function is in the main loop, if i declare it in the function, then it keeps resetting itself

thats why i was thinking of a InitDropDown function.. where you can feed the x/y into that and declare the globals in there. but no, no globaling outside the main prog

But again that method above would take away being able to use the function more then once i think..

HELP!

this is a brick wall, i cant make this reuseable if this doesnt work, thats the whole point :\

I'll keep messing with it.. any of you more experienced people have an idea?

You can make the variables global, and then initialize them in the function:
Global x

Function Init()
 x = 3
End Function

Else, you could make a variable called init and set it to one after the variables are set:
Global init

Function DrawStuff()
  If init = 0 then x = 3: init = 1
End Function


The best way to proceed however from here is turning your DropDown gadget into a type, then create a function that creates the DropDown, and another function that draws it.

I like the second one.. but i gave it a go and it didnt work:

;-----------------------------------------------------------------
;                       CreateDropDown()
;-----------------------------------------------------------------

Function CreateDropDown$(x,y,words$,number)

If InitDD=0
drawdrop=False
scrolly=x+20
shown=x
InitDD=1
End If


;If you click on the button, dropdown=True
If RectsOverlap(x+75,y,25,20,MouseX(),MouseY(),10,10) And MouseHit(1)
  If drawdrop=False
     drawdrop=True
Else
   drawdrop=False
  End If
End If

If drawdrop=True
Rect x,y,100,200,0

;For...Each ... should get the name of all the objects.
i=0
For checklist.list = Each list

If checklist\listnumber=number
i=i+1

;Made this For i...2 loop so the Text can loop itself...
Viewport x,y+20,100,180
   Text x,shown+(i*20),checklist\name
Viewport 0,0,GraphicsWidth(),GraphicsHeight()

;If you click on one of the names it will put it up top.
    If RectsOverlap(x,shown+(i*20),75,20,MouseX(),MouseY(),10,10) And MouseDown(1)
        words$=checklist\name
        drawdrop=False
        shown=10+20
        scrolly=10
     End If


End If
Next
Rect x+75,y+20,25,180,False
If i>9 
   Rect x+75,scrolly,25,20,True
  If RectsOverlap(x+75,y+20,25,180,MouseX(),MouseY(),10,10) And MouseDown(1)
     scrolly=MouseY()
  End If
If scrolly<y+20 scrolly=y+20
If scrolly>y+180 scrolly=y+180

;The more things in the Text the faster it scrolls To compensate..
ScrollbarPos = ScrollY - y-20
ScrollbarMax = y+180- y-20
ListSize = (i - 9) * 20 
shown = 10 - (scrollbarpos * listsize / scrollbarmax)


End If

End If



;Draws the Button to dropdown and the main box, and draws the words you picked..
Rect x,y,100,20,0
Rect x+75,y,25,20,0
Text x,y,words


Return words$

End Function


;-------------------------------------------------
;                         Main prog
;-------------------------------------------------

Graphics 300,500,16,2

SetBuffer BackBuffer()


Type list
   Field name$
   Field listnumber
End Type

For i=1 To 200

DD1.list = New list
DD1\name="tester"+i
DD1\listnumber=1

Next

For i=1 To 400

DD2.list = New list
DD2\listnumber=2
DD2\name="test"+i

Next


Global InitDD=0



While Not KeyHit(1)
Cls

blah$=CreateDropDown$(10,10,blah$,2)



Delay 5
Flip
Wend 
End


The line 'Global InitDD' should be placed before the function. Also, some other vars. should be global, too:
Global InitDD=0, drawdrop, scrolly, shown


;-----------------------------------------------------------------
;                       CreateDropDown()
;-----------------------------------------------------------------

Function CreateDropDown$(x,y,words$,number)

If InitDD=0
	drawdrop=False
	scrolly=x+20
	shown=x
	InitDD=1
End If


;If you click on the button, dropdown=True
If RectsOverlap(x+75,y,25,20,MouseX(),MouseY(),10,10) And MouseHit(1)
  If drawdrop=False
     drawdrop=True
Else
   drawdrop=False
  End If
End If

If drawdrop=True
Rect x,y,100,200,0

;For...Each ... should get the name of all the objects.
i=0
For checklist.list = Each list

If checklist\listnumber=number
i=i+1

;Made this For i...2 loop so the Text can loop itself...
Viewport x,y+20,100,180
   Text x,shown+(i*20),checklist\name
Viewport 0,0,GraphicsWidth(),GraphicsHeight()

;If you click on one of the names it will put it up top.
    If RectsOverlap(x,shown+(i*20),75,20,MouseX(),MouseY(),10,10) And MouseDown(1)
        words$=checklist\name
        drawdrop=False
        shown=10+20
        scrolly=10
     End If


End If
Next
Rect x+75,y+20,25,180,False
If i>9 
   Rect x+75,scrolly,25,20,True
  If RectsOverlap(x+75,y+20,25,180,MouseX(),MouseY(),10,10) And MouseDown(1)
     scrolly=MouseY()
  End If
If scrolly<y+20 scrolly=y+20
If scrolly>y+180 scrolly=y+180

;The more things in the Text the faster it scrolls To compensate..
ScrollbarPos = ScrollY - y-20
ScrollbarMax = y+180- y-20
ListSize = (i - 9) * 20 
shown = 10 - (scrollbarpos * listsize / scrollbarmax)


End If

End If



;Draws the Button to dropdown and the main box, and draws the words you picked..
Rect x,y,100,20,0
Rect x+75,y,25,20,0
Text x,y,words


Return words$

End Function


;-------------------------------------------------
;                         Main prog
;-------------------------------------------------

Graphics 300,500,16,2

SetBuffer BackBuffer()


Type list
   Field name$
   Field listnumber
End Type

For i=1 To 200

DD1.list = New list
DD1\name="tester"+i
DD1\listnumber=1

Next

For i=1 To 400

DD2.list = New list
DD2\listnumber=2
DD2\name="test"+i

Next




While Not KeyHit(1)
Cls

blah$=CreateDropDown$(10,10,blah$,2)



Delay 5
Flip
Wend 
End


Very nice, ok, now that its working nicely i'm now working on making it work with multible drodowns..

i ran into a problem, it doesnt seem to work for some reason, any ideas? it looks alright to me..

Global InitDD,drawdrop,scrolly,shown

;-----------------------------------------------------------------
;                       CreateDropDown()
;-----------------------------------------------------------------

Function CreateDropDown$(x,y,words$,number)

If InitDD=0
drawdrop=False
scrolly=x+20
shown=x
InitDD=1
End If


;If you click on the button, dropdown=True
If RectsOverlap(x+75,y,25,20,MouseX(),MouseY(),10,10) And MouseHit(1)
  If drawdrop=False
     drawdrop=True
Else
   drawdrop=False
  End If
End If

If drawdrop=True
Rect x,y,100,200,0

;For...Each ... should get the name of all the objects.
i=0
For checklist.list = Each list

If checklist\listnumber=number
i=i+1

;Made this For i...2 loop so the Text can loop itself...
Viewport x,y+20,100,180
   Text x,shown+(i*20),checklist\name
Viewport 0,0,GraphicsWidth(),GraphicsHeight()

;If you click on one of the names it will put it up top.
    If RectsOverlap(x,shown+(i*20),75,20,MouseX(),MouseY(),10,10) And MouseDown(1)
        words$=checklist\name
        drawdrop=False
        shown=10+20
        scrolly=10
     End If


End If
Next
Rect x+75,y+20,25,180,False
If i>9 
   Rect x+75,scrolly,25,20,True
  If RectsOverlap(x+75,y+20,25,180,MouseX(),MouseY(),10,10) And MouseDown(1)
     scrolly=MouseY()
  End If
If scrolly<y+20 scrolly=y+20
If scrolly>y+180 scrolly=y+180

;The more things in the Text the faster it scrolls To compensate..
ScrollbarPos = ScrollY - y-20
ScrollbarMax = y+180- y-20
ListSize = (i - 9) * 20 
shown = 10 - (scrollbarpos * listsize / scrollbarmax)


End If

End If



;Draws the Button to dropdown and the main box, and draws the words you picked..
Rect x,y,100,20,0
Rect x+75,y,25,20,0
Text x,y,words


Return words$

End Function

;-----------------------------------
;            main prog
;-----------------------------------

Graphics 300,500,16,2

SetBuffer BackBuffer()

Type list
   Field name$
   Field listnumber
End Type

For i=1 To 200

DD1.list = New list
DD1\name="tester"+i
DD1\listnumber=1

Next

For i=1 To 400

DD2.list = New list
DD2\listnumber=2
DD2\name="test"+i

Next





While Not KeyHit(1)
Cls

blah$=CreateDropDown$(10,10,blah$,2)
blah2$=CreateDropDown$(150,10,blah2$,1)



Delay 5
Flip
Wend 
End


Also, i tried modifing your "more objects = faster scrolling" code, with little success, it seems to get wierder if the box is placed deeper on the "Y" axis..

------------
EDIT: I looked at your code deeper, and i fixed the problem with the faster scrolling ect.. still need help with the multible dropdown support though..
----------

any ideas?

by the way, thanks for putting up with me lol..

HMM, i think the problem is the functions are relying on the same veribs, i tried this:

Global InitDD,drawdrop,scrolly,shown,used=0

Global NO_OF_DDS=2


and this in the function:

If used<NO_OF_DDS
drawdrop=False
scrolly=y+20
shown=x
used=used+1
End If

If used > NO_OF_DDS
used=0
End If



no success... Any ideas?

I think the best approach is using a type to store the variables for each dropdown. That way you can create as many as you like. It is probably the best to calculate 'shown' at the start of the function, before drawing anything.
That way it doesn't need to be stored. The Type should contain all variables that are required outside the funciton: drawdrop, scrolly and words$.

I would write a function that creates (and initializes) the dropdown, and use the function that you have to draw the dropdown.

Then, in your main loop, you can do this to write the dropdowns:
For dropdown = Each TDropDown
DrawDropDown dropdown
Next

Later on, you could maybe write a function to dispose the dropdowns again, and a function that adds items to a specific dropdown.

If you are going to use MouseX/Y and MouseHit more than once, it is best to store them into (global) variables. MouseHit can only be read once and MouseXY can be different every time you read them.

hmm, could you give me a small example, on where these would be placed?

Do you mean the mouse stuff ? Or the types ?
About the mouse, I meant something like this:
Global InitDD,drawdrop,scrolly,shown
Global CursorX, CursorY, CursorHit

;-----------------------------------------------------------------
;                       CreateDropDown()
;-----------------------------------------------------------------

Function CreateDropDown$(x,y,words$,number)

If InitDD=0
drawdrop=False
scrolly=x+20
shown=x
InitDD=1
End If


;If you click on the button, dropdown=True
If RectsOverlap(x+75,y,25,20,CursorX,CursorY,10,10) And MouseHit(1)
  If drawdrop=False
     drawdrop=True
Else
   drawdrop=False
  End If
End If

If drawdrop=True
Rect x,y,100,200,0

;For...Each ... should get the name of all the objects.
i=0
For checklist.list = Each list

If checklist\listnumber=number
i=i+1

;Made this For i...2 loop so the Text can loop itself...
Viewport x,y+20,100,180
   Text x,shown+(i*20),checklist\name
Viewport 0,0,GraphicsWidth(),GraphicsHeight()

;If you click on one of the names it will put it up top.
    If RectsOverlap(x,shown+(i*20),75,20,CursorX,CursorY,10,10) And MouseDown(1)
        words$=checklist\name
        drawdrop=False
        shown=10+20
        scrolly=10
     End If


End If
Next
Rect x+75,y+20,25,180,False
If i>9 
   Rect x+75,scrolly,25,20,True
  If RectsOverlap(x+75,y+20,25,180,CursorX,CursorY,10,10) And MouseDown(1)
     scrolly=CursorY
  End If
If scrolly<y+20 scrolly=y+20
If scrolly>y+180 scrolly=y+180

;The more things in the Text the faster it scrolls To compensate..
ScrollbarPos = ScrollY - y-20
ScrollbarMax = y+180- y-20
ListSize = (i - 9) * 20 
shown = 10 - (scrollbarpos * listsize / scrollbarmax)


End If

End If



;Draws the Button to dropdown and the main box, and draws the words you picked..
Rect x,y,100,20,0
Rect x+75,y,25,20,0
Text x,y,words


Return words$

End Function

;-----------------------------------
;            main prog
;-----------------------------------

Graphics 300,500,16,2

SetBuffer BackBuffer()

Type list
   Field name$
   Field listnumber
End Type

For i=1 To 200

DD1.list = New list
DD1\name="tester"+i
DD1\listnumber=1

Next

For i=1 To 400

DD2.list = New list
DD2\listnumber=2
DD2\name="test"+i

Next





While Not KeyHit(1)
Cls

CursorX = MouseX()
CursorY = MouseY()
CursorHit = MouseHit(1)

blah$=CreateDropDown$(10,10,blah$,2)
blah2$=CreateDropDown$(150,10,blah2$,1)



Delay 5
Flip
Wend 
End


The types, i'v been messing with it, i'm still a bit new to types if you would give me a example that would be awsome.


Thanks for the MouseX/Y ect that makes sense

I don't know if this example is best, but it shows the idea. It uses a type to store buttons:
;-------------------------------------------------------------------------------------------------------
;											Globals&Types
;-------------------------------------------------------------------------------------------------------

	;to store mouse stuff
	Global Cursor_X, Cursor_Y, Cursor_Hit
	
	;button type
	Type Button
		Field x, y
		Field width, height
		Field name$
	End Type


;-------------------------------------------------------------------------------------------------------
;												Main Loop
;-------------------------------------------------------------------------------------------------------

	;setup graphics
	Graphics 800, 600, 0, 2
	SetBuffer BackBuffer()
	
	;create button
	CreateButton "Test", 400, 300, 120, 80
	CreateButton "Other", 200, 400, 120, 80
	
	;main loop
	Repeat
	
		Cls
		button$ = DrawButtons$()
		Text 0, 0, button$
		
		If button$ = "Test" Then RuntimeError "You clicked on the 'Test' button!"
		Flip
		
	Until KeyHit(1)
	
	End

;-------------------------------------------------------------------------------------------------------
;											CreateButton()
;-------------------------------------------------------------------------------------------------------
;creates new button
Function CreateButton.Button(name$, x, y, width, height)

	;create new button
	b.Button = New Button
	b\name$ = name$
	b\x = x
	b\y = y
	b\width = width
	b\height = height
	
	;return new button
	Return b

End Function

;-------------------------------------------------------------------------------------------------------
;											DrawButtons()
;-------------------------------------------------------------------------------------------------------
;draws all buttons
Function DrawButtons$()

	Cursor_X = MouseX()
	Cursor_Y = MouseY()
	Cursor_Hit = MouseHit(1)

	test$ = ""
	
	For b.Button = Each Button
	
		If DrawButton(b) Then test$ = b\name$
		
	Next
	
	Return test$
	
End Function

;-------------------------------------------------------------------------------------------------------
;											DrawButton()
;-------------------------------------------------------------------------------------------------------
;draws a single button
Function DrawButton( b.Button )

	;test if mouse is over button
	mouseover = RectsOverlap( Cursor_X, Cursor_Y, 1, 1, b\x, b\y, b\width, b\height)

	;draw frame
	Rect b\x, b\y, b\width, b\height, 0

	;determine color
	If mouseover Then Color 0, 255, 0 Else Color 255, 255, 255
	;draw text
	Text b\x + (b\width / 2), b\y + (b\height / 2), b\name$, 1, 1
	;reset color
	Color 255, 255, 255

	;return true if button is clicked	
	Return (mouseover And Cursor_Hit)
	
End Function


i'll mess with it, Thanks.

Hmm, i took some time to mess with it, it looks like this is the right direction, but for the life of me i cant figure out whats wrong with this:

Global InitDD,drawdrop,scrolly,shown
Global CursorX, CursorY, CursorHit

;-----------------------------------------------------------------
;                       CreateDropDown()
;-----------------------------------------------------------------


Type dd
Field drawdrop
Field scrolly
Field shown
Field InitDD
End Type

Function CreateDropDown$(x,y,words$,number)

If InitDD>2
b.dd = New dd
b\drawdrop=False
b\scrolly=x+20
b\shown=x
InitDD=InitDD+1
End If



;If you click on the button, dropdown=True
If RectsOverlap(x+75,y,25,20,CursorX,CursorY,10,10) And CursorHit
  If b\drawdrop=False
     b\drawdrop=True
Else
   b\drawdrop=False
  End If
End If

If b\drawdrop=True
Rect x,y,100,200,0

;For...Each ... should get the name of all the objects.
i=0
For checklist.list = Each list

If checklist\listnumber=number
i=i+1

;Made this For i...2 loop so the Text can loop itself...
Viewport x,y+20,100,180
   Text x,b\shown+(i*20),checklist\name
Viewport 0,0,GraphicsWidth(),GraphicsHeight()

;If you click on one of the names it will put it up top.
    If RectsOverlap(x,shown+(i*20),75,20,CursorX,CursorY,10,10) And MouseDown(1)
        words$=checklist\name
        b\drawdrop=False
        b\shown=10+20
        b\scrolly=10
     End If


End If
Next
Rect x+75,y+20,25,180,False
If i>9 
   Rect x+75,b\scrolly,25,20,True
  If RectsOverlap(x+75,y+20,25,180,CursorX,CursorY,10,10) And MouseDown(1)
     b\scrolly=CursorY
  End If
If b\scrolly<y+20 b\scrolly=y+20
If b\scrolly>y+180 b\scrolly=y+180

;The more things in the Text the faster it scrolls To compensate..
ScrollbarPos = ScrollY - y-20
ScrollbarMax = y+180- y-20
ListSize = (i - 9) * 20 
b\shown = 10 - (scrollbarpos * listsize / scrollbarmax)


End If

End If



;Draws the Button to dropdown and the main box, and draws the words you picked..
Rect x,y,100,20,0
Rect x+75,y,25,20,0
Text x,y,words


Return words$

End Function

;-----------------------------------
;            main prog
;-----------------------------------

Graphics 300,500,16,2

SetBuffer BackBuffer()

Type list
   Field name$
   Field listnumber
End Type

For i=1 To 200

DD1.list = New list
DD1\name="bah"+i
DD1\listnumber=1

Next

For i=1 To 400

DD2.list = New list
DD2\listnumber=2
DD2\name="meh"+i

Next





While Not KeyHit(1)
Cls

CursorX = MouseX()
CursorY = MouseY()
CursorHit = MouseHit(1)

blah$=CreateDropDown$(10,10,blah$,2)
blah2$=CreateDropDown$(150,10,blah2$,1)



Delay 5
Flip
Wend 




i get a MAV error, thats a first.. but thats the right direction?

Any ideas?

Yes, it is going allright. The MAV is an 'object doesn't exist' error. To see the right error message, enable debug.
Now, the first two times CreateDropDown is called, 'b.dd' exists. However, after two times, it isn't created anymore.

I think it is best to split CreateDropDown into CreateDropDown and DrawDropDown.

The CreateDropDown$() can be mostly the same. Right after the If-block "If InitDD > 2 etc .. End If", add an End Function.
The rest of the function could become DrawDropDown.
The DrawDropDown$() function then should take "b.dd" as a parameter:
Function DrawDropDown$(b.dd)


Right after that, read everything you need for the function from the type:
x = b\x
y = b\y
shown = b\shown
etc.

Everything that needs to be relative to a certain dragdrop, should be in the type.

When the function is done, store everything that has changed, back into the type:
b\x = x
b\y = y
etc.
End Function


The order should be this:
1) create dragdrops with CreateDragDrop. There is no need for the InitDD variable.
2) add items
3) calculate length for each dragdrop (b\listsize)
4) in mainloop, call DrawDragDrop() that does this:
move scrollbar
calculate 'shown'
draw dragdrops
respond to mouseclick

So CreateDropDown should hold the inits create the types ect, while DrawDropDown handles the drawing, if statments loops (basicly almost the whole thing)..

I'll mess with it, Thanks!

Hmm, it still gives me a MAV error:

Global InitDD,drawdrop,scrolly,shown
Global CursorX, CursorY, CursorHit

;-----------------------------------------------------------------
;                       CreateDropDown()
;-----------------------------------------------------------------


Type dd
Field drawdrop
Field scrolly
Field shown
Field InitDD
End Type

Function CreateDropDown(x,y)

b.dd = New dd
b\drawdrop=False
b\scrolly=x+20
b\shown=x

End Function


Function DrawDropDown$(words$,number,b.dd)

drawdrop=b\drawdrop
scrolly=b\scrolly
shown=b\shown

;If you click on the button, dropdown=True
If RectsOverlap(x+75,y,25,20,CursorX,CursorY,10,10) And CursorHit
  If drawdrop=False
     drawdrop=True
Else
   drawdrop=False
  End If
End If

If drawdrop=True
Rect x,y,100,200,0

;For...Each ... should get the name of all the objects.
i=0
For checklist.list = Each list

If checklist\listnumber=number
i=i+1

;Made this For i...2 loop so the Text can loop itself...
Viewport x,y+20,100,180
   Text x,shown+(i*20),checklist\name
Viewport 0,0,GraphicsWidth(),GraphicsHeight()

;If you click on one of the names it will put it up top.
    If RectsOverlap(x,shown+(i*20),75,20,CursorX,CursorY,10,10) And MouseDown(1)
        words$=checklist\name
        drawdrop=False
        shown=10+20
        scrolly=10
     End If


End If
Next
Rect x+75,y+20,25,180,False
If i>9 
   Rect x+75,scrolly,25,20,True
  If RectsOverlap(x+75,y+20,25,180,CursorX,CursorY,10,10) And MouseDown(1)
     scrolly=CursorY
  End If
If scrolly<y+20 scrolly=y+20
If scrolly>y+180 scrolly=y+180

;The more things in the Text the faster it scrolls To compensate..
ScrollbarPos = ScrollY - y-20
ScrollbarMax = y+180- y-20
ListSize = (i - 9) * 20 
b\shown = 10 - (scrollbarpos * listsize / scrollbarmax)


End If

End If



;Draws the Button to dropdown and the main box, and draws the words you picked..
Rect x,y,100,20,0
Rect x+75,y,25,20,0
Text x,y,words


Return words$
End Function



;-----------------------------------
;            main prog
;-----------------------------------

Graphics 300,500,16,2

SetBuffer BackBuffer()

Type list
   Field name$
   Field listnumber
End Type

For i=1 To 200

DD1.list = New list
DD1\name="bah"+i
DD1\listnumber=1

Next

For i=1 To 400

DD2.list = New list
DD2\listnumber=2
DD2\name="meh"+i

Next



CreateDropDown(10,10)
CreateDropDown(150,10)

While Not KeyHit(1)
Cls

CursorX = MouseX()
CursorY = MouseY()
CursorHit = MouseHit(1)

blah$=DrawDropDown$(blah$,1,b.dd)
blah2$=DrawDropDown$(words$,2,b.dd)



Delay 5
Flip
Wend 
End


It is again an 'object does not exist' error. In bb, goto Program->Debug Enabled? Else, every error is a MAV, which can be very confusing.
The reason for the error is this:
blah$=DrawDropDown$(blah$,1,b.dd)
blah2$=DrawDropDown$(words$,2,b.dd)

When these lines are executed, 'b.dd' does not exist.
Instead use this:
For b.dd = Each dd
blah$=DrawDropDown$(blah$,1,b.dd)
Next

This way, all 'dd's are drawn.
Then, at the end of the DrawDropDown() function, add the line:
b\drawdrop = drawdrop

So the drawdrop mode is stored for each dd when the function ends.
Then, in CreateDropDown, add:
b\x=x
b\y=y

And add an x and y field to the 'dd' type. Finally, add:
x=b\x
y=b\y

To the start of the function. Else, all dropdowns are drawn in the same place.

Ok, awsome, this is starting to look like its working, one small problem, i'm having the problem of it resetting itself again, i tried the Init dropdown, but it doesnt work, because thats only for 1..

Could you point me in the right direction?

Also Thank you so much for all the help, esp. teaching me types in depth..

:) np, I'm glad I can help out. At the end of the drawing function, add:
b\scrolly = scrolly

If you want to set the labels individually, do the same thing for words$:
At the start of the function use:
words$ = b\words$

And at the end, use:
b\words$ = words$

instead of "return words$"

I don't think i was clear, heres some code:
;-----------------------------------------------------------------
;                       CreateDropDown()
;-----------------------------------------------------------------


Type dd
Field drawdrop
Field scrolly
Field shown
Field x,y


End Type

Function CreateDropDown(x,y)

b.dd = New dd
b\x=x
b\y=y
b\drawdrop=False
b\scrolly=x+20
b\shown=x


End Function


Function DrawDropDown$(words$,number,b.dd)



drawdrop=b\drawdrop
scrolly=b\scrolly
shown=b\shown
x=b\x
y=b\y



;If you click on the button, dropdown=True
If RectsOverlap(x+75,y,25,20,CursorX,CursorY,10,10) And CursorHit
  If drawdrop=False
     drawdrop=True
Else
   drawdrop=False
  End If
End If

If drawdrop=True
Rect x,y,100,200,0

;For...Each ... should get the name of all the objects.
i=0
For checklist.list = Each list

If checklist\listnumber=number
i=i+1

;Made this For i...2 loop so the Text can loop itself...
Viewport x,y+20,100,180
   Text x,shown+(i*20),checklist\name
Viewport 0,0,GraphicsWidth(),GraphicsHeight()

;If you click on one of the names it will put it up top.
    If RectsOverlap(x,shown+(i*20),75,20,CursorX,CursorY,10,10) And MouseDown(1)
        words$=checklist\name
        drawdrop=False
        shown=10+20
        scrolly=10
     End If


End If
Next
Rect x+75,y+20,25,180,False
If i>9 
   Rect x+75,scrolly,25,20,True
  If RectsOverlap(x+75,y+20,25,180,CursorX,CursorY,10,10) And MouseDown(1)
     scrolly=CursorY
  End If
If scrolly<y+20 scrolly=y+20
If scrolly>y+180 scrolly=y+180

;The more things in the Text the faster it scrolls To compensate..
ScrollbarPos = ScrollY - y-20
ScrollbarMax = y+180- y-20
ListSize = (i - 9) * 20 
b\shown = 10 - (scrollbarpos * listsize / scrollbarmax)


End If

End If



;Draws the Button to dropdown and the main box, and draws the words you picked..
Rect x,y,100,20,0
Rect x+75,y,25,20,0
Text x,y,words

b\scrolly = scrolly
b\drawdrop = drawdrop


Return words$
End Function



;-----------------------------------
;            main prog
;-----------------------------------

Graphics 300,500,16,2

SetBuffer BackBuffer()

Type list
   Field name$
   Field listnumber
End Type

For i=1 To 200

DD1.list = New list
DD1\name="bah"+i
DD1\listnumber=1

Next

For i=1 To 400

DD2.list = New list
DD2\listnumber=2
DD2\name="meh"+i

Next



CreateDropDown(10,10)
CreateDropDown(150,10)

While Not KeyHit(1)
Cls

CursorX = MouseX()
CursorY = MouseY()
CursorHit = MouseHit(1)

For b.dd = Each dd
blah$=DrawDropDown$(blah$,1,b.dd)
blah2$=DrawDropDown$(words$,2,b.dd)
Next


Delay 5
Flip
Wend 


It keeps resetting, any ideas?

When I ran this example, it didn't respond at all ? It seemed that it needed "Global CursorX, CursorY, CursorHit" at the start of the program.
In the For Each..Next loop that draws the dd's, you only need one DrawDropDown command. The For..Next loop ensures that all dd's are drawn. If you draw them twice, they open and then close again in the same loop.

but if i only write one DrawDropDown, how do i get the other one to get its own words? hmm... Also it looks like the scrollbars arent working... any ideas?

Edit heres the new example, sorry about the other one it all didnt get copyed :)

Global InitDD,drawdrop,scrolly,shown
Global CursorX, CursorY, CursorHit

;-----------------------------------------------------------------
;                       CreateDropDown()
;-----------------------------------------------------------------


Type dd
Field drawdrop
Field scrolly
Field shown
Field x,y


End Type

Function CreateDropDown(x,y)

b.dd = New dd
b\x=x
b\y=y
b\drawdrop=False
b\scrolly=x+20
b\shown=x


End Function


Function DrawDropDown$(words$,number,b.dd)



drawdrop=b\drawdrop
scrolly=b\scrolly
shown=b\shown
x=b\x
y=b\y



;If you click on the button, dropdown=True
If RectsOverlap(x+75,y,25,20,CursorX,CursorY,10,10) And CursorHit
  If drawdrop=False
     drawdrop=True
Else
   drawdrop=False
  End If
End If

If drawdrop=True
Rect x,y,100,200,0

;For...Each ... should get the name of all the objects.
i=0
For checklist.list = Each list

If checklist\listnumber=number
i=i+1

;Made this For i...2 loop so the Text can loop itself...
Viewport x,y+20,100,180
   Text x,shown+(i*20),checklist\name
Viewport 0,0,GraphicsWidth(),GraphicsHeight()

;If you click on one of the names it will put it up top.
    If RectsOverlap(x,shown+(i*20),75,20,CursorX,CursorY,10,10) And MouseDown(1)
        words$=checklist\name
        drawdrop=False
        shown=10+20
        scrolly=10
     End If


End If
Next
Rect x+75,y+20,25,180,False
If i>9 
   Rect x+75,scrolly,25,20,True
  If RectsOverlap(x+75,y+20,25,180,CursorX,CursorY,10,10) And MouseDown(1)
     scrolly=CursorY
  End If
If scrolly<y+20 scrolly=y+20
If scrolly>y+180 scrolly=y+180

;The more things in the Text the faster it scrolls To compensate..
ScrollbarPos = b\scrolly - y-20
ScrollbarMax = y+180- y-20
ListSize = (i - 9) * 20 
b\shown = 10 - (scrollbarpos * listsize / scrollbarmax)


End If

End If



;Draws the Button to dropdown and the main box, and draws the words you picked..
Rect x,y,100,20,0
Rect x+75,y,25,20,0
Text x,y,words

b\scrolly = scrolly
b\drawdrop = drawdrop


b\shown=shown
x=b\x
y=b\y


;Return words$
End Function



;-----------------------------------
;            main prog
;-----------------------------------

Graphics 300,500,16,2

SetBuffer BackBuffer()

Type list
   Field name$
   Field listnumber
End Type

For i=1 To 200

DD1.list = New list
DD1\name="bah"+i
DD1\listnumber=1

Next

For i=1 To 400

DD2.list = New list
DD2\listnumber=2
DD2\name="meh"+i

Next



CreateDropDown(10,10)
CreateDropDown(150,10)

While Not KeyHit(1)
Cls

CursorX = MouseX()
CursorY = MouseY()
CursorHit = MouseHit(1)

For b.dd = Each dd
blah$=DrawDropDown$(blah$,1,b.dd)
;blah2$=DrawDropDown$(words$,2,b.dd)
Next


Delay 5
Flip
Wend 
End


That is just a typo in the line:
b\shown = 10 - (scrollbarpos * listsize / scrollbarmax)

It should be "shown = 10 etc" (without the b\)

If you want each scrollbar to be able to have it's own words$, add that as a field to the dd type.
In the function DrawDropDown$(), you can leave out the words$ parameter, and use the words$ that is stored in the type:
words$ = b\words$

When the function ends, you can store words$ back into the type:
b\words$ = words$


What about the stuff that goes into the drop down.. see the "number" param.. i give the list types their own number or id. so i can pick what goes into the dropdown... i cant choose a number for each drop down if i only call drawdropdown only once

This is really coming togetther now :), brings a smile to my face having 4 dropdowns and having them work perfectly... :D .. After the problem above is solved i think this is about done, Huge Thanks to you B23..

How long have you been programming? you have to have at least a few years, you seem to know the answer to all my questions : \

though i feel bad i cant help you with one of your questions.

For 21 years .. I started when I was 8, which was .. erm in 1814, during WWI. It were tuff times: we had no food, so we had to eat our C64 tapes to survive. We made 'Terrys Big Burger' and 'Giana soup' .. sigh ..
I really like to help out. My friends can't write programs -at all- and I want to talk about it with people. That is why I appreciate the forums so much.
But have you solved the id thing then ? You need to pass the 'number' parameter to CreateDropDown function, instead of the DrawDropDown, and make a field that contains the number.
Then, in DrawDropDown, use:
number = b\number

alright, Yeah, i'm still young (14) still learning, dabbing in C++, ect, but yeah, i also have another problem, i'm trying to give these dropdowns an ID, so i can then say "if id=1 then display this ones current picked item"

so i tried this in the creation process:
Function CreateDropDown(x,y)

b.dd = New dd
b\x=x
b\y=y
b\drawdrop=False
b\scrolly=y+20
b\shown=y
b\num=num2

num2=num2+1

End Function


and this to display:

For b.dd = Each dd
If b\num=1 Text 0,0,"DropDown 1: "+b\words
If b\num=2 Text 0,0,"DropDown 2: "+b\words
Next


No workie :(

Edit: and i know how you feel, my friends think its wierd to program, because they cant understand it :D, but they like trying stuff i made, i love it when they say: yeah right, you didnt make that...

then ofcourse i have no proof but oh well :\

Hmm, it seems like it should work. Is num2 global ? Else, all dropdowns will get the same id.
edit: and num2 starts off at zero, so the id's will be: 0, 1

Doh, That worked, Thank you B32 if i don't run into any problems, i should have this done very soon :D

I created a function to delete dropdowns by ID:

Function DeleteDropDown(ID)
For FindDD.DropDown = Each DropDown
If FindDD\DropDown_ID=ID Delete FindDD
Next
End Function


This works find, tested and confirmed, but, i wanted to use this to delete and recreate a dropdown, again and again, incase somthing changes.

like so:

For CheckDD.DropDown = Each DropDown
If CheckDD\words="test1" Catagory=1
If CheckDD\words="test2" Catagory=2
Next

Select Catagory
Case 1
DeleteDropDown(2)
CreateDropDown(350,120,2)
Case 2
DeleteDropDown(2)
CreateDropDown(350,120,3)
End Select


but somthing doesnt work, it seems to lagg, or somthing, because it doesnt work half the time, any ideas?

In the Select..Case, in both case 1&2, you are deleting dropdown(2), is that right ?
\words and 'Catagory' are never reset, so if this code is executed in a loop, and the dragdrop is set to, say, 'test1', it will keep on deleting and creating the dropdowns until Catagory is reset and \words$ is no longer "test1"/"test2"
I think that is causing the lag.

Hmm, heres a bigger chunk of code to look at.. i don't think its deletedropdown, because you saw how it works, it deletes by the dropdowns id, not the list id..

the example above, should say, if you select this in another dropdown the other dropdown will be erased and rewrittin with a new list id...

but, it looks like its constantly deleting/rewriting every loop, i don't want this, i only want it to delete/rewrite if Catagory changes (once)

like:

2 drop downs.

a user selects somthing out of the first dropdown

the second dropdown changes whats in it, (deletes/rewrites ONCE)

user selects somthing else out of the first dropdown,

the second dropdown changes again (deletes rewrites ONCE)

in the code above it seems like its deleting and rewriting everyloop, any ideas?

To do that, you should reset \words$ and Catagory:
Catagory=0
For CheckDD.DropDown = Each DropDown
If CheckDD\words="test1" Catagory=1: CheckDD\words$=""
If CheckDD\words="test2" Catagory=2: CheckDD\words$=""
Next


still laggs

heres the updated code (in the main loop)
Catagory=0
For CheckDD.DropDown = Each DropDown
If CheckDD\DropDown_ID=1 And CheckDD\words="test1" Catagory=1
If CheckDD\DropDown_ID=1 And CheckDD\words="test2" Catagory=2
Next

Select Catagory
Case 1
DeleteDropDown(2)
CreateDropDown(350,120,2)
Case 2
DeleteDropDown(2)
CreateDropDown(350,120,3)
End Select


also anything wrong with my deleting method?
Function DeleteDropDown(ID)
For FindDD.DropDown = Each DropDown
If FindDD\DropDown_ID=ID Delete FindDD
Next
End Function



Edit: Hmm, mabye a Do once if catagory changes type deal would work?

like so:

;Catagory=0
For CheckDD.DropDown = Each DropDown
If CheckDD\DropDown_ID=1 And CheckDD\words="HybridTurrs" Catagory=1
If CheckDD\DropDown_ID=1 And CheckDD\words="EnergyTurrs" Catagory=2
Next

If Catagory <> Catagory doOnce=0

If doOnce=0
Select Catagory
Case 1
DeleteDropDown(2)
CreateDropDown(350,120,2)
Case 2
DeleteDropDown(2)
CreateDropDown(350,120,3)
End Select
doOnce=1
End If

For DrawDrops.DropDown = Each DropDown
DrawDropDowns(DrawDrops.DropDown)
Next


But i don't think thats the correct method of doing that (last i checked the operator "<>" means if it moves?) but the above doesnt work..

Maybe you should delete dropdowns with the type 3 as well ? Because now, you are only deleting type 2 dropdowns:
Catagory=0
For CheckDD.DropDown = Each DropDown
If CheckDD\DropDown_ID=1 And CheckDD\words="test1" Catagory=1: CheckDD\words$=""
If CheckDD\DropDown_ID=1 And CheckDD\words="test2" Catagory=2: CheckDD\words$=""
Next

Select Catagory
Case 1
DeleteDropDown(2)
DeleteDropDown(3)
CreateDropDown(350,120,2)
Case 2
DeleteDropDown(2)
DeleteDropDown(3)
CreateDropDown(350,120,3)
End Select

If it still lags, could you post the entire code? It is much easier for me to see what is wrong that way.

alright,

heres the whole code:
Global CursorX, CursorY, CursorHit, ID_Number=1


;-----------------------------------------------------------------------------------------------------
;											ScanCode Type
;-----------------------------------------------------------------------------------------------------
Type TKeyDown
	Field s.ScanCode
End Type
	
;type to hold scancodes
Type ScanCode
	Field code
	Field key$
	Field upkey$
	Field isdown
End Type


Type DropDown
Field drawdrop
Field scrolly
Field shown
Field x,y
Field words$
Field Accepts
Field DropDown_ID
End Type


;-----------------------------------------------------------------------------------------------------
;											InitGetKey()
;-----------------------------------------------------------------------------------------------------
;reads all scancodes into ScanCode type
Function InitGetKey()

	;read scancodes
	tel = 1
	Restore scancodez
	Repeat
		Read scanc
		If scanc = -1 Then Exit
		s.ScanCode = New ScanCode
		s\code = scanc
		s\key$ = Lower$(Mid$("1234567890-=QWERTYUIOP[]ASDFGHJKL;'\ZXCVBNM,./* 789-456+1230.,/" + Chr$(8) + Chr$(13) + Chr$(13), tel, 1))
		s\upkey$ = Mid$("!@#$%^&*()_+QWERTYUIOP{}ASDFGHJKL:" + Chr$(34) + "|ZXCVBNM<>?* 789-456+1230.,/" + Chr$(8) + Chr$(13) + Chr$(13), tel, 1)
		tel = tel + 1
	Forever

End Function

Global oldkdown
;-----------------------------------------------------------------------------------------------------
;											iGetKey()
;-----------------------------------------------------------------------------------------------------
;imitates GetKey() using scancodes
Function iGetKey()

	;read scancodes
	For s.ScanCode = Each ScanCode
		down = KeyDown(s\code)
		If down And (Not s\isdown) Then 
			tk.TKeyDown = New TKeyDown
			tk\s = s
		End If
		s\isdown = down
	Next

	tk.TKeyDown = First TKeyDown
	If tk = Null Then Return
	
	sel.ScanCode = tk\s
	If sel = Null Then Return
	
	oldkdown = sel\code
	
	Delete tk
			
	;shift for uppercase	
	If KeyDown(42) Or KeyDown(54) Then
		sc$ = sel\upkey$
	Else
		sc$ = sel\key$
	End If

	;return ascii value of key	
	Return Asc(sc$)

End Function

;"1234567890-=QWERTYUIOP[]ASDFGHJKL;'\ZXCVBNM,./* 789-456+7890.,/" (no shift)
;"!@#$%^&*()_+QWERTYUIOP{}ASDFGHJKL:"|ZXCVBNM<>?* 789-456+7890.,/" (shift)
.scancodez
Data 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
Data 12, 13, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
Data 26, 27, 30, 31, 32, 33, 34, 35, 36, 37, 38
Data 39, 40, 43, 44, 45, 46, 47, 48, 49, 50, 51
Data 52, 53, 55, 57, 71, 72, 73, 74, 75, 76, 77
Data 78, 79, 80, 81, 82, 83, 179, 181
Data 14, 28, 156
Data -1


;-------------------------------------------------------------------------------------------------------
;                                          CreateInputBox()
;-------------------------------------------------------------------------------------------------------

Function CreateInputBox$(box_x,box_y,box_w,useable,returnstr$,letters)
	
	Rect box_x, box_y, box_w,20, False

If useable=True
   key=iGetKey()
	If MilliSecs() > blinky+500
   Rect box_x+3+Len(returnstr$)*9,box_y+2,1,17,1
		End If
		
		If MilliSecs() > blinky+1000 blinky=MilliSecs()
	
  If letters=True
    If (key=>48 And key=<57) Or (key>=65 And key<=90) Or (key>=97 And key<=122)
     If(Len(returnstr$)<box_w/10)
        returnstr$ = returnstr$ + Chr(key)
				
End If
  End If
     End If
  If letters=False
    If (key=>48 And key=<57)
	If(Len(returnstr$)<box_w/10)
        returnstr$ = returnstr$ + Chr(key)
	  End If
	End If
	End If
	End If



If useable=True
If KeyHit(14)
   If Len(returnstr$)>0 returnstr$=Left(returnstr$,Len(returnstr$)-1)
End If
If KeyHit(57)
  returnstr$=returnstr$+" "
End If
End If


	Text box_x+3,box_y, returnstr$

	Return(returnstr$)
	
		
End Function

;-------------------------------------------------------------------
;                         lvlCreateInputBox
;-------------------------------------------------------------------
Function lvlCreateInputBox$(box_x,box_y,box_w,useable,returnstr$,startnum,lastnum)
	
	Rect box_x, box_y, box_w,20, False

If useable=True
   key=iGetKey()
	If MilliSecs() > blinky+500
   Rect box_x+3+Len(returnstr$)*9,box_y+2,1,17,1
		End If
		
		If MilliSecs() > blinky+1000 blinky=MilliSecs()
	
				
End If
    If (key=>startnum And key=<lastnum)
	If (Len(returnstr$)<1)
        returnstr$ = returnstr$ + Chr(key)
	  End If
	End If




If useable=True
If KeyHit(14)
   If Len(returnstr$)>0 returnstr$=Left(returnstr$,Len(returnstr$)-1)
End If
If KeyHit(57)
  returnstr$=returnstr$+" "
End If
End If


	Text box_x+3,box_y, returnstr$

	Return(returnstr$)
	
		
End Function

;Function InitDropDown()

;drawdrop=False
;scrolly=70
;shown=50

;End Function


;-----------------------------------------------------------------
;                       CreateDropDown()
;-----------------------------------------------------------------




Function CreateDropDown(x,y,Accepted)



NewDD.DropDown = New DropDown
NewDD\x=x
NewDD\y=y
NewDD\drawdrop=False
NewDD\scrolly=y+20
NewDD\shown=y
NewDD\DropDown_ID=ID_Number
NewDD\Accepts=Accepted


ID_Number=ID_Number+1
End Function

;----------------------------------------------------------------
;              DrawDropDowns()
;----------------------------------------------------------------

Function DrawDropDowns(Creation_Info.DropDown)



drawdrop = Creation_Info\drawdrop
scrolly = Creation_Info\scrolly
shown = Creation_Info\shown
x = Creation_Info\x
y = Creation_Info\y
words$ = Creation_Info\words$
number = Creation_Info\Accepts

;If you click on the button, dropdown=True
If RectsOverlap(x+100,y,25,20,CursorX,CursorY,5,5) And CursorHit
  If drawdrop=False
     drawdrop=True
Else
   drawdrop=False
  End If
End If

If drawdrop=True
Rect x,y,125,200,0

;For...Each ... should get the name of all the objects.
i=0
For checklist.list = Each list

If checklist\ID=number
i=i+1

;Made this For i...2 loop so the Text can loop itself...
Viewport x,y+20,125,180
   Text x,shown+(i*20),checklist\name
Viewport 0,0,GraphicsWidth(),GraphicsHeight()

;If you click on one of the names it will put it up top.
    If RectsOverlap(x,shown+(i*20),100,20,CursorX,CursorY,5,5) And CursorX > x And CursorX< x+125 And CursorY > y+20 And CursorY < y+200 And MouseDown(1)
        words$=checklist\name
        drawdrop=False
        shown=y
        scrolly=y+20
     End If


End If
Next
Rect x+100,y+20,25,180,False
If i>9 

 


   Rect x+100,scrolly,25,20,True
  If RectsOverlap(x+100,y+20,25,180,CursorX,CursorY,5,5) And MouseDown(1)
     scrolly=MouseY()
End If




If scrolly<y+20 scrolly=y+20
If scrolly>y+180 scrolly=y+180

;The more things in the Text the faster it scrolls To compensate..
ScrollbarPos = ScrollY - y-20
ScrollbarMax = y+180- y-20
ListSize = (i - 9) * 20 
shown = y - (scrollbarpos * listsize / scrollbarmax)


End If

End If



;Draws the 3 main parts of the dropdown, with all the math from above: Main box, DD button, 
Rect x,y,125,20,0
Rect x+100,y,25,20,0
Text x,y,words


;Takes the Creation info and Equals it to the messed with dropdown info.
Creation_Info\scrolly = scrolly
Creation_Info\drawdrop = drawdrop
Creation_Info\shown = shown
Creation_Info\words$ = words$

End Function

;-------------------------------------------------------------------------
;                          DeleteDropDown(DropDown_ID)
;-------------------------------------------------------------------------

Function DeleteDropDown(ID)
For FindDD.DropDown = Each DropDown
If FindDD\DropDown_ID=ID Delete FindDD
Next
End Function

;Sets the apptitle.
AppTitle "Fitting Calculator","Exit Fitting calculator?"
;Includes my function libary


;Sets the graphics modes
Graphics 500,400,16,2
SetBuffer BackBuffer()

Type ship
   Field powergrid
   Field cpu
   Field name$
   Field h,m,l
End Type

Type list
   Field name$
   Field ID
End Type

testship.ship = New ship
testship\powergrid=750
testship\cpu=400
testship\name="Test"

test3.list = New list
test3\name="Test"
test3\ID=1

test1.list = New list
test1\name="Test2"
test1\ID=1

test.list = New list
test\name="Test"
test\ID=2

test2.list =New list
test2\name="Test2"
test2\ID=3

Global doOnce=0


;Current PG/CPU
C_POWER=0
C_CPU=0

;Added CPU/PG to add with Current CPU/PG
ADD_CPU$=""
ADD_POWER$=""
NO_OFMODS$=""
SLOTOFMOD$=""


F_HS=0
F_MS=0
F_LS=0
C_SLOT=0
C_SLOT2=0

;Sets the current textbox veriable this keeps track of the current textbox in use
c_textbox=1
c_textbox2=1

;menus True/False Veriables For the textboxs To work
TF1=False
TF2=False
TF3=False
TF4=False
TF5=False
TF6=False
TF7=False


;Special function that makes the special iGetKey() function work
InitGetKey()

;Sets the timer veriable
Global blinky=MilliSecs()

;Answer=1 so the first loop can start
answer=1


;The picked ship string
PickedShip$=""
Engineering$=""
Electronics$=""

;Creates the DropDowns
CreateDropDown(10,120,1) ;ID=1
CreateDropDown(350,120,2) ;ID=2

.start
;-------------------------------------------------------------------------------
;-                              Startup loop
;-------------------------------------------------------------------------------
While answer=1
Cls

CursorX = MouseX()
CursorY = MouseY()
CursorHit = MouseHit(1)

;If you click on a text box make it the active one
If RectsOverlap(0,0,100,20,MouseX(),MouseY(),10,10) And MouseDown(1)
c_textbox2=1
End If
If RectsOverlap(0,30,100,20,MouseX(),MouseY(),10,10) And MouseDown(1)
c_textbox2=2
End If
If RectsOverlap(0,60,100,20,MouseX(),MouseY(),10,10) And MouseDown(1)
c_textbox2=3
End If


;Looks at the c_textbox2 ver. and turns the textboxs on/off
Select c_textbox2
Case 1
TF5=True
TF4=False
TF6=False
Case 2
TF4=True
TF5=False
TF6=False
Case 3
TF6=True
TF4=False
TF5=False
End Select

;Makes the first letter in the ship input always uppercase
If Pickedship=Lower(Left(PickedShip,1)) Pickedship=Upper(Left(PickedShip,1))

;Creates a input boxs
PickedShip=CreateInputBox$(0,0,100,TF5,PickedShip,True)
Engineering=lvlCreateInputBox$(0,30,100,TF4,Engineering$,49,53)
Electronics=lvlCreateInputBox$(0,60,100,TF6,Electronics$,49,53)
Text 100,0,":What ship are you in? Full name."
Text 100,30,":Whats your Engineering at?"
Text 100,60,":Whats your Electronics at?"

;Turns a string into a interger
F_Engineering%=Engineering$
F_Electronics%=Electronics$

;Percentage maths depending on what you typed in
Select F_Engineering
Case 1
Engineering_percentage#=1.05
Case 2
Engineering_percentage#=1.1
Case 3
Engineering_percentage#=1.15
Case 4
Engineering_percentage#=1.2
Case 5
Engineering_percentage#=1.25
End Select

;Percentage maths depending on what you typed in
Select F_Electronics
Case 1
Electronics_percentage#=1.05
Case 2
Electronics_percentage#=1.1
Case 3
Electronics_percentage#=1.15
Case 4
Electronics_percentage#=1.2
Case 5
Electronics_percentage#=1.25
End Select


;Creates the "NEXT" button
Rect 200,350,60,25,True
Color 0,0,0
Text 210,354,"Next"
Color 255,255,255


;If ESC is pressed end the program
If KeyHit(1)
End
End If

;if you didnt type anything in, add nothing
If F_Engineering=0 Then Engineering_percentage=1.0
If F_Electronics=0 Then Electronics_percentage=1.0

;did you find anything?
found=0

;Does what you typed in match up with anything in the database?
For shipname.ship=Each ship
If shipname\name=PickedShip$
   shipCPU$=shipname\cpu*Electronics_percentage
   shippower$=shipname\powergrid*Engineering_percentage
   HS=shipname\h
   MS=shipname\m
   LS=shipname\l
   found=1
End If
Next


;Turns a string into a int.
ship_CPU%=shipCPU$
ship_power%=shippower$

;Yay it matchs up continue with the program
If found=1
 If RectsOverlap(200,350,60,25,MouseX(),MouseY(),10,10) And MouseDown(1) Or KeyHit(28)
   answer=2
 End If
End If

;Boo you didnt type it in right print a error and try again!
If found=0
 If RectsOverlap(200,350,60,25,MouseX(),MouseY(),10,10) And MouseDown(1) Or KeyHit(28)
   PickedShip$=""
   Text 40,130,"This ship is not in the database"
 End If
End If

;Delay flip wend..
Delay 5
Flip
Wend






;---------------------------------------------------------------------------------------
;-                                      MAIN LOOP                                      -
;---------------------------------------------------------------------------------------


While Not KeyHit(1)
Cls

CursorX = MouseX()
CursorY = MouseY()
CursorHit = MouseHit(1)




;colors PG depending on if its over PG or not
If C_POWER>ship_power
   Color 255,0,0
Else
   Color 0,255,0
End If
  Text 0,0,"PG: ("+C_POWER+"/"+ship_power+")"

;Same as above but for CPU
If C_CPU>ship_CPU
   Color 255,0,0
Else
   Color 0,255,0
End If
  Text 0,15,"CPU: ("+C_CPU+"/"+ship_CPU+")"


;Sets color to white
Color 255,255,255

;Draws the Add module text at the top
;  Text 180,80,"Add module:"

;Draws the Power of mod Textbox
;Text 0,120,"Power of mod:"

;Draws the CPU of mod textbox
;

;Draws the number of mods textbox
;Text 0,180,"How many of these?:"

;Draws the slot text
;Text 0,210,"What slot? (1-3):"
;Text 0,230,"H=1, M=2, L=3"

;Draws the Update button
   Rect 300,350,60,25,True
Color 0,0,0
Text 302,354,"Update"
Color 255,255,255

;Draws the Clear button
   Rect 220,350,60,25,True
Color 0,0,0
Text 224,354,"Clear"
Color 255,255,255


   Rect 135,350,60,25,True
Color 0,0,0
Text 146,355,"New"
Color 255,255,255



;Creates 4 input boxs, with their own veriables to feed the info to
;ADD_POWER$=CreateInputBox$(180,120,100,TF1,ADD_POWER$,False)
;ADD_CPU$=CreateInputBox$(180,150,100,TF2,ADD_CPU$,False)
;NO_OFMODS$=CreateInputBox$(180,180,100,TF3,NO_OFMODS$,False)
;SLOTOFMOD$=lvlCreateInputBox$(180,210,100,TF7,SLOTOFMOD$,49,51)







;If you click on another text box change the selection
;If RectsOverlap(180,120,100,20,MouseX(),MouseY(),10,10) And MouseDown(1)
 ;  c_textbox=1
;End If
;If RectsOverlap(180,150,100,20,MouseX(),MouseY(),10,10) And MouseDown(1)
 ;  c_textbox=2
;End If
;If RectsOverlap(180,180,100,20,MouseX(),MouseY(),10,10) And MouseDown(1)
 ;  c_textbox=3
;End If
;If RectsOverlap(180,210,100,20,MouseX(),MouseY(),10,10) And MouseDown(1)
 ;  c_textbox=4
;End If

;If the Currect Textbox changes ... Change the current active textbox
;Select c_textbox
;Case 1
;TF1=True
;TF2=False
;TF3=False
;TF7=False
;Case 2
;TF2=True
;TF1=False
;TF3=False
;TF7=False
;Case 3
;TF3=True
;TF2=False
;TF1=False
;TF7=False
;Case 4
;TF7=True
;TF3=False
;TF1=False
;TF2=False
;End Select

;Few maths to translate a String into a pure number easyer to do math with this new number
;F_POWER%=ADD_POWER
;F_CPU%=ADD_CPU
;F_MODS%=NO_OFMODS


;if you type in somthing it turns into its slot
;If SLOTOFMOD="1" C_SLOT=F_HS C_SLOT2=HS
;If SLOTOFMOD="2" C_SLOT=F_MS C_SLOT2=MS
;If SLOTOFMOD="3" C_SLOT=F_LS C_SLOT2=LS

;If C_SLOT<C_SLOT2
;Makes the "Clear" and "Update" buttons work
If RectsOverlap(300,350,60,25,MouseX(),MouseY(),10,10) And MouseHit(1) Or KeyHit(28)
;If F_MODS=0 F_MODS=1
;If SLOTOFMOD="1" F_HS=F_HS+F_MODS
;If SLOTOFMOD="2" F_MS=F_MS+F_MODS
;If SLOTOFMOD="3" F_LS=F_LS+F_MODS
 ;  C_POWER=C_POWER+F_POWER*F_MODS
 ;  C_CPU=C_CPU+F_CPU*F_MODS
 ;  NO_OFMODS=""
   ;ADD_CPU=""
   ;ADD_POWER=""
;End If
End If
If RectsOverlap(220,350,60,25,MouseX(),MouseY(),10,10) And MouseDown(1)
  ; C_CPU=0
;  ; C_POWER=0
;  NO_OFMODS=""
;   ADD_CPU=""
;   ADD_POWER=""
End If
If RectsOverlap(135,350,60,25,MouseX(),MouseY(),10,10) And MouseDown(1)
answer=1
Goto start
End If




Catagory=0
For CheckDD.DropDown = Each DropDown
If CheckDD\DropDown_ID=1 And CheckDD\words="HybridTurrs" Catagory=1
If CheckDD\DropDown_ID=1 And CheckDD\words="EnergyTurrs" Catagory=2
Next

;If Catagory <> Catagory doOnce=0

;If doOnce=0
Select Catagory
Case 1
DeleteDropDown(2)
DeleteDropDown(3)
CreateDropDown(350,120,2)
Case 2
DeleteDropDown(2)
DeleteDropDown(3)
CreateDropDown(350,120,3)
End Select
;doOnce=1
;End If

For DrawDrops.DropDown = Each DropDown
DrawDropDowns(DrawDrops.DropDown)
Next


;Draws the Highs the mediums and the lows, and draws them filled if they have somthing in em

For i=1 To HS
   Oval 280+(i*18),0,15,15,False
Next
For i=1 To MS
   Oval 280+(i*18),20,15,15,False
Next
For i=1 To LS
   Oval 280+(i*18),40,15,15,False
Next

If F_HS>HS F_HS=HS
If F_MS>MS F_MS=MS
If F_LS>LS F_LS=LS

For i=1 To F_HS
   Oval 280+(i*18),0,15,15,True
Next
For i=1 To F_MS
   Oval 280+(i*18),20,15,15,True
Next
For i=1 To F_LS
   Oval 280+(i*18),40,15,15,True
Next

Text 220,0,"Highs:"
Text 220,20,"Mediums:"
Text 220,40,"Lows:"


;Delay to use less CPU on computer, flips the buffer and if the main loop ends, terminate the process
 Delay 5
Flip
Wend
End


When it prompts you for what "ship" your in type in "test" then click next, you'll see the dropdowns :D

sorry bout the messy code, didnt have time to coment it or make it look pretty

I didn't notice any lag, but I could see that a lot of dropdowns were made.
The trouble is that the 'ID' and 'Accepts' are confused.
In DrawDropDown, Accepts is used, and in both CreateDropDown and DeleteDropDown, the ID is used. This prevents the dropdowns to be deleted after a while.
You still need to change the code:
Catagory=0
For CheckDD.DropDown = Each DropDown
If CheckDD\DropDown_ID=1 And CheckDD\words="test1" Catagory=1: CheckDD\words$=""
If CheckDD\DropDown_ID=1 And CheckDD\words="test2" Catagory=2: CheckDD\words$=""
Next

Select Catagory
Case 1
DeleteDropDown(2)
DeleteDropDown(3)
CreateDropDown(350,120,2)
Case 2
DeleteDropDown(2)
DeleteDropDown(3)
CreateDropDown(350,120,3)
End Select

to stop the program to generate a lot of dropdowns once 'test' or 'test2' is chosen, but also, you should take a look at Accepts vs. ID.

so the main problem here is the way i assign ID's i do them in order of them being created,

i had an idea, to make the id like so:

myid=CreateDropDown(x,y,AcceptedList)

DeleteDropDown(myid)

how would i go about doing somthing like that?

Assigning a name to control the dropdown..

For that, use the 'Return' command at the end of the function.
You can use it to return any value, depending on the type of function.
Say, the function is called CreateDropDown$, then 'return' returns a string.
If the function is called CreateDropDown, it will return an integer. (Officially, there should be a % after it, but it is the default type.)
With a #, the function returns a float, but I suppose either an integer or string should work best for what you want.

You could however, also return the complete dropdown as the result:
Function CreateDropDown.DropDown(blablah)
 b.DropDown = new DropDown
 return b
End function


Then you can use something like this:

FirstDropDown = CreateDropDown(blablah)
..
..
DrawDropDown(FirstDropDown)


i get a Iligal type conversion error... from doing this:

Function CreateDropDown.DropDown(x,y,Accepted)



NewDD.DropDown = New DropDown
NewDD\x=x
NewDD\y=y
NewDD\drawdrop=False
NewDD\scrolly=y+20
NewDD\shown=y
;NewDD\DropDown_ID=ID_Number
NewDD\Accepts=Accepted


;ID_Number=ID_Number+1
Return NewDD
End Function


dd1=CreateDropDown(10,120,1) ;ID=1
dd2=CreateDropDown(350,120,2) ;ID=2


comented out the deleting rewriting code for now, so the error isnt from that

Ow seems I forgot something:
dd1.dropdown=CreateDropDown(10,120,1) ;ID=1
dd2.dropdown=CreateDropDown(350,120,2) ;ID=2

They need to be declared as a dropdown as well.

Interesting, so how would i check stuff with this? i modified the delete function, it seems to work:

Function DeleteDropDown(ID.Dropdown)
Delete ID
End Function


:D

but how do i check stuff with it?
like i did before:
If CheckDD\DropDown_ID=1
If CheckDD\DropDown_ID=1


how do i do it with the new id system?

Well, suppose you created the first dropdown with this:
FirstDropDown.DropDown = CreateDropDown(etc)

Then, later on, you can check the \words$ with:
If FirstDropDown\words$ = "test" Then ..
If FirstDropDown\words$ = "test2" Then ..

Instead of using the For Each..Next loop.

awsome, thanks B23 :D

i'll do some lagg testing in a bit and i'll report back

Cool, i think i might have the nail in the coffen for this..

i need some sort of method of doing somthing only once if something changes.

In this case, if Catagory changes i want it to delete/rewrite the dropdown.. ONCE not every loop.. then if it changes again, Delete and rewrite ONCE again..

heres what i have so far:

If dd1\words="test1" Catagory=1
If dd1\words="test2" Catagory=2


Select Catagory
Case 1
DeleteDropDown(dd2.DropDown)
dd2.DropDown=CreateDropDown(350,120,2)
Case 2
DeleteDropDown(dd2.DropDown)
dd2.DropDown=CreateDropDown(350,120,3)
End Select




For DrawDrops.DropDown = Each DropDown
DrawDropDowns(DrawDrops.DropDown)
Next


So why is it doing that every loop ?

Because that sniplet of code is in the main loop, because it has to be able to change, but its deleting/redrawing every loop

Well, it keeps repeating the same action over and over again, because Catagory, once set to one or two, doesn't change back. So then the next question is -and that one is mory tricky-: why doesn't Catagory change back ?
At first sight, one would say: add the line:
Catagory = 0

before the part:
If dd1\words="test1" Catagory=1
If dd1\words="test2" Catagory=2

But then still, it doesn't change. Why ?
Because dd1\words$ doesn't change back.
So: as long as dd1\words$="test", Catagory will be one, and the second menu will be created and destroyed, over and over again.

I need somthing like this:

Global CatagoryDraw=0
..
..
..
If dd1\words="HybridTurrs" Catagory=1
If dd1\words="EnergyTurrs" Catagory=2


If Catagory <> Catagory CatagoryDraw=0

If CatagoryDraw=0
Select Catagory
Case 1
DeleteDropDown(dd2.DropDown)
dd2.DropDown=CreateDropDown(350,120,2)
Case 2
DeleteDropDown(dd2.DropDown)
dd2.DropDown=CreateDropDown(350,120,3)
End Select
CatagoryDraw=1
End If



For DrawDrops.DropDown = Each DropDown
DrawDropDowns(DrawDrops.DropDown)
Next


Notice the "<>" i thought that is to check if it moves, i guess not, how do i check if somthing changes..?

You could do that by storing Catagory in another variable, for example oldCatagory.
If Catagory <> oldCatagory then
    oldCatagory = Catagory
    ..respond..
End if


What does "<>" do?

It means: unequal to, so it is the reverse of "="

3 = 3
4 <> 3

YAY!!

Perfect....

Edit: DANG! 102 posts on this thread, never knew making a GUI would have this many problems

Thank you B23

No problem. As the Spanish people so beautifully phrase: "El ser programador significa tener una vida de problemas"

uh yeah Thanks!

hmmm, whats wrong with the following statement?

If RectsOverlap(300,350,60,25,MouseX(),MouseY(),10,10) And MouseHit(1) Or KeyHit(28)

For getstats.list = Each list
If getstats\name$=dd2\words$

C_POWER=C_POWER+getstats\pg
C_CPU=C_CPU+getstats\cpu
End If
Next

End If


Nothing really .. Maybe the usage of MouseHit() and Keyhit()? Because they can only be read once each loop. They reset themselves after being read.
Edit: wait .. maybe they should have extra brackets, like this: ... And (MouseHit(1) Or KeyHit(28))

:) duh, that worked, WHY DIDNT I REMEMBER THAT?!?! note to self, always make a ver. to store Mousehit(1)

Well, thats it, its completed, Thank you b23, go check it out, leave a coment:

feel free to improve it or add suggestions :D

http://blitzbasic.com/codearcs/codearcs.php?code=2018

b23? I think you mean b32.

EDIT: Maybe you should make one dropdown close when another dropdown opens.

You can do that effect yourself, its easy, just call the DrawDrop attribute of the dropdown and change it..

something like this before the DrawDropDowns() in the main loop:

if dd1\drawdrop=true
dd2\drawdrop=false
dd3\drawdrop=false
..
..
end if


If you have any more questions ask in the code archives

I (sorta) knew that, but I didn't exactly know how your code worked, and I didn't really feel like reading through every little bit.