Re: [Gambas-user] A random sort of listview

2009-04-12 Thread jbskaggs

Hi yourself!  Here is the problem in the code:

FOR i = 0 TO ListView1.Count - 1 ' write items in listview2
TRY PRINT myArray[i]
listview1.MoveTo(myArray[i])
TRY c = listview1.Item.Key
TRY PRINT myArray[i], listview1.item.key , c,  counter i: , i,  total
count: , listview1.Count
TRY listview2.add(c, listview1.item.text) 
NEXT 

When the counter i reaches Listview1.Count -1  it gives an error and does
not write the last record!   I have compensated by writing an extra  dummy
record to the data file- but how do I code this properly to write the whole
list?  I have tried several things and they just give different errors.

Thanks

JB

Simonart Dominique wrote:
 
 Hi,
 
 jbskaggs a écrit :
 Okay I thought this was worked out but its still not working- I always
 end up
 losing the last two list items.
 
 Here is the console output from my print statements:
 This first list is printing i, a from this command SWAP myArray[i],
 myArray[a]
 
 21  21
 20  13
 19  0
 18  13
 17  11
 16  4
 15  9
 14  12
 13  4
 12  2
 11  6
 10  2
 9   4
 8   0
 7   5
 6   1
 5   3
 4   3
 3   0
 2   0
 1   0
 0   0
 
 
 Here, you listed i and a but the interesting values are i 
 and myArray[i] instead
 
 This list shows where listview1 is being copied into listview2:
 
 listview1.item.key  21   counter i: 21   total count:  
 22
 listview1.item.key  13   counter i: 20   total count:  
 22
 listview1.item.key  13   counter i: 19   total count:  
 22
 listview1.item.key  20   counter i: 18   total count:  
 22
 listview1.item.key  11   counter i: 17   total count:  
 22
 listview1.item.key  4counter i: 16   total count:  
 22
 listview1.item.key  9counter i: 15   total count:  
 22
 listview1.item.key  12   counter i: 14   total count:  
 22
 listview1.item.key  16   counter i: 13   total count:  
 22
 listview1.item.key  2counter i: 12   total count:  
 22
 listview1.item.key  6counter i: 11   total count:  
 22
 listview1.item.key  14   counter i: 10   total count:  
 22
 listview1.item.key  18   counter i: 9total count:  
 22
 listview1.item.key  19   counter i: 8total count:  
 22
 listview1.item.key  5counter i: 7total count:  
 22
 listview1.item.key  5counter i: 6total count:  
 22
 listview1.item.key  3counter i: 5total count:  
 22
 listview1.item.key  7counter i: 4total count:  
 22
 listview1.item.key  8counter i: 3total count:  
 22
 listview1.item.key  15   counter i: 2total count:  
 22
 listview1.item.key  10   counter i: 1total count:  
 22
 listview1.item.key  17   counter i: 0total count:  
 22
 
 here is a screen shot of the two lists: listview1 is on the left, you
 will
 notice that the last two items are not on the random sorted list on the
 right.
 
 
 First, is it correct that you have twice the keys 13 and 5 
 in ListView1 and that keys 0 and 1 are missing?
 I tried to reproduce exactly your keys sequence but as soon 
 as I want to add an identical key, I get a message and the 
 programme stop immediatly.
 
 http://www.nabble.com/file/p23005690/ScreenshotBug.png 
 
 
 Here is my code:
 
 PUBLIC SUB button4_click()
 DIM myArray AS Integer[ListView1.count]
 DIM a AS Integer
 DIM i AS Integer
 DIM c AS String
 
 FOR i = 0 TO ListView1.count - 1 STEP 1
  myArray[i] = i 
 NEXT 
 
 FOR i = ListView1.count - 1 TO 0 STEP -1
 a = Int(Rnd(i + 1))
 SWAP myArray[i], myArray[a]
 PRINT i, a
 NEXT 
 
 FOR i = ListView1.count - 1 TO 0 STEP -1 ' write items in listview2
 - I
 have also tried running this counting up as well but it changed nothing.
 
 listview1.MoveTo(myArray[i])
 TRY c = listview1.Item.Key
 TRY PRINT listview1.item.key , c,  counter i: , i,  total count: ,
 listview1.Count
 TRY listview2.add(c, listview1.item.text) 
 NEXT 
 'fGlobal.show
 'FRolldice.Show
 
 'ME.Hide
 
 END
 
 
 Sincerly JB SKaggs
 
 
 I run your code and it works quite fine!
 I think your missing items come from the duplicated keys
 
 Dominique Simonart
 
 
 --
 This SF.net email is sponsored by:
 High Quality Requirements in a Collaborative Environment.
 Download a free trial of Rational Requirements Composer Now!
 http://p.sf.net/sfu/www-ibm-com
 ___
 Gambas-user mailing list
 Gambas-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user
 
 

-- 
View this message in context: 
http://www.nabble.com/A-random-sort-of-listview-tp22919766p23008540.html
Sent from the gambas-user mailing list 

Re: [Gambas-user] A random sort of listview

2009-04-12 Thread Doriano Blengino
jbskaggs ha scritto:

 FOR i = 0 TO ListView1.count - 1 STEP 1
  myArray[i] = i 
 NEXT 

 FOR i = ListView1.count - 1 TO 0 STEP -1
 a = Int(Rnd(i + 1))
 SWAP myArray[i], myArray[a]
 PRINT i, a
 NEXT 
   
Apart from the problem of missing records, there could be also a 
randomness problem in the algorithm... I am really not sure, but it 
seems that certain slots have more chances to be swapped than other - 
myarray[0] can be swapped COUNT times, while myarray[count-1] gets only 
a chance.  I am not sure of what this signifies: it is true that the 
swap affects the values contained in slots, and not the slots 
themselves, but anyway there could be another method. One could also do 
this:

for i = 0 to 1000   ' arbitrary value, large enough (100?)
  c1 = int(rnd(listview1.count))
  c2 = int(rnd(listview1.count))
  swap myarray[c1], myarray[c2]
next

This way, every slot gets the same chances to be swapped; for sufficient 
loops, it should make a good job... perhaps more random than before.
And perhaps, as the algorthm is different, it could solve the problem of 
missing records (which I didn't understand...).

Cheers,

-- 
Doriano Blengino

Listen twice before you speak.
This is why we have two ears, but only one mouth.


--
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] LinkedIn

2009-04-12 Thread Jeff
Cool.
I have set it up. It will be interesting to see how many join.

On Sat, 2009-04-11 at 22:28 +0200, Benoît Minisini wrote:
  Hey Benoit
  I thought about setting up a group on LinkedIn for Gambas users. Could
  help to spread the word. Are you ok with it or would you rather not?
 
 
 I am ok. :-)
 


--
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] sticker

2009-04-12 Thread Werner
cristian abarzua wrote:
 Hello.

 I sent you a sticker for their programs.
 I hope I do not bother Benoit

 Greetings
   
nice :-)

--
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] A random sort of listview

2009-04-12 Thread jbskaggs

This works much better at getting a more shuffled list!

Thanks



Doriano Blengino wrote:
 
 jbskaggs ha scritto:

 FOR i = 0 TO ListView1.count - 1 STEP 1
  myArray[i] = i 
 NEXT 

 FOR i = ListView1.count - 1 TO 0 STEP -1
 a = Int(Rnd(i + 1))
 SWAP myArray[i], myArray[a]
 PRINT i, a
 NEXT 
   
 Apart from the problem of missing records, there could be also a 
 randomness problem in the algorithm... I am really not sure, but it 
 seems that certain slots have more chances to be swapped than other - 
 myarray[0] can be swapped COUNT times, while myarray[count-1] gets only 
 a chance.  I am not sure of what this signifies: it is true that the 
 swap affects the values contained in slots, and not the slots 
 themselves, but anyway there could be another method. One could also do 
 this:
 
 for i = 0 to 1000   ' arbitrary value, large enough (100?)
   c1 = int(rnd(listview1.count))
   c2 = int(rnd(listview1.count))
   swap myarray[c1], myarray[c2]
 next
 
 This way, every slot gets the same chances to be swapped; for sufficient 
 loops, it should make a good job... perhaps more random than before.
 And perhaps, as the algorthm is different, it could solve the problem of 
 missing records (which I didn't understand...).
 
 Cheers,
 
 -- 
 Doriano Blengino
 
 Listen twice before you speak.
 This is why we have two ears, but only one mouth.
 
 
 --
 This SF.net email is sponsored by:
 High Quality Requirements in a Collaborative Environment.
 Download a free trial of Rational Requirements Composer Now!
 http://p.sf.net/sfu/www-ibm-com
 ___
 Gambas-user mailing list
 Gambas-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user
 
 

-- 
View this message in context: 
http://www.nabble.com/A-random-sort-of-listview-tp22919766p23013584.html
Sent from the gambas-user mailing list archive at Nabble.com.


--
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] A random sort of listview

2009-04-12 Thread jbskaggs

You were correct! There was a extra comma in the data file that was breaking
the loop!

BTW to you an everyone else if you celebrate it, Happy Easter! If not ignore
me. ;)

JB SKaggs



Simonart Dominique wrote:
 
 Hi again :)
 
 May be you did not see the last sentence of my answer wich 
 is written in 3 places? Your code is just fine and I don't 
 have any problem with the ListViews. Of course, I had to 
 initialize the ListView1 with my own data like this:
 
 FOR i = 0 to 21
 ListView1.Add(Str(i), number   Str(i))
 NEXT
 After that, I run your code and all is fine!
 If you have problem, this is therefore with the content of 
 your Listview1. I think it is not correct to have identical 
 keys in a ListView because if I attempt to do it the program 
 stop immediatly. I even don't understand how you could get 
 this situation! Here is what I tried:
 
 FOR i = 0 to 21
 SELECT CASE i
 CASE 0
ListView1.Add(5, number   Str(i))
 CASE 1
ListView1.Add(13, number   Str(i))
 CASE ELSE
ListView1.Add(Str(i), number   Str(i))
 END SELECT
 NEXT
 this code stop with i=5 and say that the key is already used!
 
 Could you make a try with unique keys only?
 Plus, could you run it without TRY?
 
 Hope we could identify the error
 Dominique Simonart
 
 jbskaggs a écrit :
 Hi yourself!  Here is the problem in the code:
 
 FOR i = 0 TO ListView1.Count - 1 ' write items in listview2
 TRY PRINT myArray[i]
 listview1.MoveTo(myArray[i])
 TRY c = listview1.Item.Key
 TRY PRINT myArray[i], listview1.item.key , c,  counter i: , i, 
 total
 count: , listview1.Count
 TRY listview2.add(c, listview1.item.text) 
 NEXT 
 
 When the counter i reaches Listview1.Count -1  it gives an error and does
 not write the last record!   I have compensated by writing an extra 
 dummy
 record to the data file- but how do I code this properly to write the
 whole
 list?  I have tried several things and they just give different errors.
 
 Thanks
 
 JB
 
 Simonart Dominique wrote:
 Hi,

 jbskaggs a écrit :
 Okay I thought this was worked out but its still not working- I always
 end up
 losing the last two list items.

 Here is the console output from my print statements:
 This first list is printing i, a from this command SWAP myArray[i],
 myArray[a]

 21  21
 20  13
 19  0
 18  13
 17  11
 16  4
 15  9
 14  12
 13  4
 12  2
 11  6
 10  2
 9   4
 8   0
 7   5
 6   1
 5   3
 4   3
 3   0
 2   0
 1   0
 0   0

 Here, you listed i and a but the interesting values are i 
 and myArray[i] instead

 This list shows where listview1 is being copied into listview2:

 listview1.item.key  21   counter i: 21   total count:  
 22
 listview1.item.key  13   counter i: 20   total count:  
 22
 listview1.item.key  13   counter i: 19   total count:  
 22
 listview1.item.key  20   counter i: 18   total count:  
 22
 listview1.item.key  11   counter i: 17   total count:  
 22
 listview1.item.key  4counter i: 16   total count:  
 22
 listview1.item.key  9counter i: 15   total count:  
 22
 listview1.item.key  12   counter i: 14   total count:  
 22
 listview1.item.key  16   counter i: 13   total count:  
 22
 listview1.item.key  2counter i: 12   total count:  
 22
 listview1.item.key  6counter i: 11   total count:  
 22
 listview1.item.key  14   counter i: 10   total count:  
 22
 listview1.item.key  18   counter i: 9total count:  
 22
 listview1.item.key  19   counter i: 8total count:  
 22
 listview1.item.key  5counter i: 7total count:  
 22
 listview1.item.key  5counter i: 6total count:  
 22
 listview1.item.key  3counter i: 5total count:  
 22
 listview1.item.key  7counter i: 4total count:  
 22
 listview1.item.key  8counter i: 3total count:  
 22
 listview1.item.key  15   counter i: 2total count:  
 22
 listview1.item.key  10   counter i: 1total count:  
 22
 listview1.item.key  17   counter i: 0total count:  
 22

 here is a screen shot of the two lists: listview1 is on the left, you
 will
 notice that the last two items are not on the random sorted list on the
 right.

 First, is it correct that you have twice the keys 13 and 5 
 in ListView1 and that keys 0 and 1 are missing?
 I tried to reproduce exactly your keys sequence but as soon 
 as I want to add an identical key, I get a message and the 
 programme stop immediatly.

 http://www.nabble.com/file/p23005690/ScreenshotBug.png 


 Here is my code:

 PUBLIC SUB button4_click()
 DIM myArray AS Integer[ListView1.count]
 DIM a AS Integer
 DIM i AS Integer
 DIM c AS 

Re: [Gambas-user] A random sort of listview

2009-04-12 Thread Dominique SIMONART

--
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


[Gambas-user] Input box incorrect size of the text control. My first problem.

2009-04-12 Thread agrgal

Hi, everybody! Excuse my English.

I've noticed an embarrasing 'bug' when I use an Input Box in my programs.
Functionality isn't put at risk but looks horrible. I think an image is
better than words... http://www.nabble.com/file/p23013689/inputbox.png 

How can I fix this problem? It happens whatever computer is used.
-- 
View this message in context: 
http://www.nabble.com/Input-box-incorrect-size-of-the-text-control.-My-first-problem.-tp23013689p23013689.html
Sent from the gambas-user mailing list archive at Nabble.com.
--
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] A random sort of listview

2009-04-12 Thread Dominique SIMONART
Doriano Blengino a écrit :
 jbskaggs ha scritto:
   
 FOR i = 0 TO ListView1.count - 1 STEP 1
  myArray[i] = i 
 NEXT 

 FOR i = ListView1.count - 1 TO 0 STEP -1
 a = Int(Rnd(i + 1))
 SWAP myArray[i], myArray[a]
 PRINT i, a
 NEXT 
   
 
 Apart from the problem of missing records, there could be also a 
 randomness problem in the algorithm... I am really not sure, but it 
 seems that certain slots have more chances to be swapped than other - 
 myarray[0] can be swapped COUNT times, while myarray[count-1] gets only 
 a chance.  I am not sure of what this signifies: it is true that the 
 swap affects the values contained in slots, and not the slots 
 themselves, but anyway there could be another method. One could also do 
 this:

 for i = 0 to 1000   ' arbitrary value, large enough (100?)
   c1 = int(rnd(listview1.count))
   c2 = int(rnd(listview1.count))
   swap myarray[c1], myarray[c2]
 next

 This way, every slot gets the same chances to be swapped; for sufficient 
 loops, it should make a good job... perhaps more random than before.
 And perhaps, as the algorthm is different, it could solve the problem of 
 missing records (which I didn't understand...).

 Cheers,

   
= I resend my message because it seems the text is missing?! :-\   

This is not really a problem. The Randomizing process could be explained
like this:
1) You align a sorted card deck in front of you on a table
2) then, from all the cards on the table you take a random card in your
hand so there is a place without card on the table
3) you put the last card on the table in this hole, so the hole is now
at the last place
4) you continue by returning to 2 until you got all the cards in your hand
Now you have a randomized deck of cards in your hand
5) you put the first card you got in the last place on the table and
continue to do that until you have no card in your hand.
Now the randomized deck of cards is on the table.
If you examine carefully this process, you will remark that each time
you filled a hole with the last remaining card on the table, you could
place the card you got just before in the last place, because it is
free! You only have to remember to not take these cards already
selected. So you could do the 5) between 3) and 4) and this is exactly
which is done by the SWAP instruction!

It is true that some places will be selected several times, but their
content change each time (there is another card on these places each time).
In no way you could loose a card in this process!!. The JBskaggs'
problem, I think, is that, before he starts the process, there are twice
2 identical cards in his deck and Gambas does not admit that, so when
Gambas encounters the duplicated cards it reject them, (but since TRY is
used, you don't see the error!!) and finally, 2 cards are missing.

Hope this is clearer :)
cheers
Dominique Simonart
--
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


[Gambas-user] X coordinate of a Form Frame. My Second Problem.

2009-04-12 Thread agrgal

I wrote some code to center a Form window, even the Desktop Size is
different. Here it is:

  FMain.X = Int((Desktop.Width - FMain.Width) / 2)

FMain.Y = Int((Desktop.Height - FMain.Height) / 2)


Meanwhile the Form is resized regarding to the Y coordinate, it doesn't work
as well for the X coordinate. Why? It seems that FMain.X doesn't 'catch up'
a number (FMain.X=100 won't work too) 

What's happening? Please, help me!!! :-)
-- 
View this message in context: 
http://www.nabble.com/X-coordinate-of-a-Form-Frame.-My-Second-Problem.-tp23013834p23013834.html
Sent from the gambas-user mailing list archive at Nabble.com.
--
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] X coordinate of a Form Frame. My Second Problem.

2009-04-12 Thread jbskaggs

Have you tried me.center?

agrgal wrote:
 
 I wrote some code to center a Form window, even the Desktop Size is
 different. Here it is:
 
 pcode  FMain.X = Int((Desktop.Width - FMain.Width) / 2)/code/p
 pcodeFMain.Y = Int((Desktop.Height - FMain.Height) / 2)/code/p
 
 Meanwhile the Form is resized regarding to the Y coordinate, it doesn't
 work as well for the X coordinate. Why? It seems that FMain.X doesn't
 'catch up' a number (FMain.X=100 won't work too) 
 
 What's happening? Please, help me!!! :-)
 

-- 
View this message in context: 
http://www.nabble.com/X-coordinate-of-a-Form-Frame.-My-Second-Problem.-tp23013834p23016773.html
Sent from the gambas-user mailing list archive at Nabble.com.


--
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user