Problem with Types

Post your coding questions such as 'how to' here.
Post Reply
technical
Newcomer
Posts: 2
Joined: Fri Oct 26, 2012 3:00 pm

Problem with Types

Post by technical »

Hello, I have the following code, but does not work as I want
Will you help me with this please?

This is the source code:

Code: Select all

'Define Type
Type USERS
Field name As String
EndType

'Create five instances
us.USERS = New(USERS)
us\name= "John"

us.USERS = New(USERS)
us\name= "Michael"

us.USERS = New(USERS)
us\name= "Peter"

us.USERS = New(USERS)
us\name= "Jason"

us.USERS = New(USERS)
us\name= "Charlie"

'Read information of instances
For us = Each USERS
Print us\name
Next us

'Press any key
WaitKey 

'Empty space
Print " "

'Create new instance and insert in second position
us.USERS = New(USERS)
us\name= "Ralph"
Insert us, After(First(USERS))

'Read information of instances with new change
For us = Each USERS
Print us\name
Next us

'Press any key to exit program
WaitKey 
I created five instances for the type USERS. Instances are names of people. Then when you press a key displays the list of instances. Then again I press a key and sixth instance is created, which has the name "Ralph". Finally, with the instruction "Insert", I need to position the new instance in the second position, and for that I use "Insert us, After (First (USERS))". However, the instance is positioned in the third position, and not the second! Why is this?

Thanks for your help friends :)
User avatar
Jonez
Devoted Member
Posts: 575
Joined: Mon Aug 27, 2007 8:37 pm

Re: Problem with Types

Post by Jonez »

I'm sorry for a short and bad reply (I'm in a hurry), but the insert-command (or after- or before-command, can't remember which) is a bit bugged. You should try to test these to figure out how they work exactly, or wait for someone else to explain this in further detail.

Edit. try to add an empty instance to the beginning, it might be that they work incorrectly only when the first instance is in question.
-Vuoden 2008 aloittelijan ystävä -palkinnon voittaja-
Image <- protestipelikilpailun voittaja.
Space War
technical
Newcomer
Posts: 2
Joined: Fri Oct 26, 2012 3:00 pm

Re: Problem with Types

Post by technical »

Thanks for answer!!!! Help me please u.u someone!!!
User avatar
Jonez
Devoted Member
Posts: 575
Joined: Mon Aug 27, 2007 8:37 pm

Re: Problem with Types

Post by Jonez »

Well, as I said, there is a bug of some sort involving the first slot. To get around it, I edited your code a bit:

This is the code for adding Ralph an setting it to the second slot only:

Code: Select all

'Create new instance and insert in second position
us.USERS = New(USERS)

temp.USERS = New (USERS) //create a temporary field to circle the bug involving cb types on FIRST
Insert temp, First(USERS) //set it as first

us\name= "Ralph"
Insert us, After(First(USERS))

Delete temp //delete the temp as it's not needed anymore
-Vuoden 2008 aloittelijan ystävä -palkinnon voittaja-
Image <- protestipelikilpailun voittaja.
Space War
Post Reply