从列表框中选择随机项目 [英] choose random item from the listbox

查看:95
本文介绍了从列表框中选择随机项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

当列表框包含从组合框中选择的项目(字符串类型)时,我们如何编写代码以选择随机项目并通过msgbox从列表框中显示?

每当执行程序时,它应该总是返回一个不同的随机项.


谢谢

Hi all,

How can we write code for choosing random item, and displaying it through msgbox, from listbox when the listbox contains the selected item (that is of type string) from a combobox?

It should return always a different random item whenever the program is executed.


Thanks

推荐答案

您可以使用随机函数.
在其中清单项目的供应计数中.


来自Jitendra Tikudia.

请投票.
you can use random function.
in that supply count of list item in it.


From Jitendra Tikudia.

Please Do Vote .


此解决方案可以使您满意.

如您所说,您尝试使用整数类型.因此,您可以对数字的列表框项目的索引值使用随机选择逻辑.

然后,您可以获取列表框的选定索引的值,该值可以是任何整数或字符串值.
May this solution satisfy you.

As you said you tried for integer type. So instead you use that random selection logic on index value of listbox items which is numeric.

You can then get value of selected index of listbox which can be any integer or string value.


您应注意,如果它是随机的,则可能会在相同的位置上多次获得相同的结果.小跑,因为这是随机的性质.

您对它的坚持总是不同的,它将需要一个包含最后N个选择的数组(其中N是框中的项目数),并且除非任何事情不是随机选择的,否则不要放任其走.完成所有操作后,清除数组,然后重新开始.
You should note that if it is random, you may get the same result a few times on the trot, for that is the nature of random.

Your insistance on it always being different would require an array containing the last N choices (where N is the number of items in the box), and not letting anything go unless it had not been selected by random chance. Once all had been, clear the array and start again.


这篇关于从列表框中选择随机项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆