Random labels.text [英] Random labels.text

查看:64
本文介绍了Random labels.text的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我在form1上有4个文本框。在运行时,将要求用户填写名称。之后,我希望这些名称随机放置在4个标签上(form2)。我该怎么办?我正在尝试它多年,但我仍然没有任何线索让他们随机。


请帮助我。


Cindy

解决方案


大家好,


我在form1上有4个文本框。在运行时,将要求用户填写名称。之后,我希望这些名称随机放置在4个标签上(form2)。我该怎么办?我正在尝试它多年,但我仍然没有任何线索让他们随机。


请帮助我。


Cindy



随机是关于vb6中的数字。


您应该将您的标签表示为数字,并在随机数生成器函数中询问其中一个数字。


因此,对于每个文本框。你可以说,RandomNumberGenerator函数,给我1到4之间的数字。


例如,

它返回3.


查看3标签是否有值,如果没有将名称放在那里(从文本框中)。


如果确实有值,请继续询问RandomNumberGenerator,给你另一个数字,直到你得到一个干净的标签来填充。


继续运行,直到你的标签被填满(所有4个)。


您的技术挑战在于随机生成器功能。你需要让它给你一个只有1到4之间的值。如果你需要帮助,请告诉我。



随机是关于vb6中的数字。


您应该将您的标签表示为数字,并在随机数生成器函数中询问其中一个数字。


因此,对于每个文本框。你可以说,RandomNumberGenerator函数,给我1到4之间的数字。


例如,

它返回3.


查看3标签是否有值,如果没有将名称放在那里(从文本框中)。


如果确实有值,请继续询问RandomNumberGenerator,给你另一个数字,直到你得到一个干净的标签来填充。


继续运行,直到你的标签被填满(所有4个)。


您的技术挑战在于随机生成器功能。你需要让它给你一个只有1到4的值。如果你需要帮助,请告诉我。



感谢您的帮助!


我不知道这是否是最优雅的方式(探测不到:)),但确实有效。我有一些看起来像随机发生器的东西:


我的module1看起来像这样:

函数随机(ByVal x As Single)As Single

Dim y As Single

x = Rnd()

如果x< 0.25然后

y = 1

ElseIf x< 0.5和0.25 < x然后

y = 2

ElseIf x< 0.75和0.5 < x然后

y = 3

ElseIf x< 1和0.75< 1 x然后

y = 4

结束如果

random = y

结束功能


我的form1(button_click)看起来像这样:

Dim g As Integer

Form2.Show()

Label1.Text = random(g)


但是我怎样才能将我的标签表示为数字。我是否必须将我的标签重命名为数字?


我不知道如何将生成器与文本框和标签连接起来。


Cindy


如果您查看VB文章区域中的索引,那么有一个例程可以在指定的限制内返回一个随机的整数值。 / BLOCKQUOTE>

Hi everyone,

I have 4 textboxes on form1. On runtime the user will be asked to fill in names. After that, I want these names placed RANDOMLY on 4 labels (form2). How should I do that? I am trying it for ages but I still don''t have a clue to get them random.

Please help me.

Cindy

解决方案

Hi everyone,

I have 4 textboxes on form1. On runtime the user will be asked to fill in names. After that, I want these names placed RANDOMLY on 4 labels (form2). How should I do that? I am trying it for ages but I still don''t have a clue to get them random.

Please help me.

Cindy

Random is about numbers in vb6.

You should represent your labels as a number, and ask for one of the numbers in a random number generator function.

So, for each textbox. You could say, "RandomNumberGenerator function, give me a number between 1 and 4."

For example,
It returns 3.

See if the 3 label has a value, if not put the name there (from the textbox).

If it does have a value, keep askin the RandomNumberGenerator to give you another number until you get a clean label to populate.

keep going until you get your labels filled (all 4 of them).

Your technical challenge is with the Random generator function. You''ll need to make it give you a value of only between 1 and 4. Let me know if you need help with this.


Random is about numbers in vb6.

You should represent your labels as a number, and ask for one of the numbers in a random number generator function.

So, for each textbox. You could say, "RandomNumberGenerator function, give me a number between 1 and 4."

For example,
It returns 3.

See if the 3 label has a value, if not put the name there (from the textbox).

If it does have a value, keep askin the RandomNumberGenerator to give you another number until you get a clean label to populate.

keep going until you get your labels filled (all 4 of them).

Your technical challenge is with the Random generator function. You''ll need to make it give you a value of only between 1 and 4. Let me know if you need help with this.


Thank you for your help!

I don''t know if this is the most elegant way (probebly not :)), but it does work. I have something that looks like a random generator:

My module1 looks like this:

Function random(ByVal x As Single) As Single
Dim y As Single
x = Rnd()
If x < 0.25 Then
y = 1
ElseIf x < 0.5 And 0.25 < x Then
y = 2
ElseIf x < 0.75 And 0.5 < x Then
y = 3
ElseIf x < 1 And 0.75 < x Then
y = 4
End If
random = y
End Function


And my form1 (button_click) looks like this:

Dim g As Integer
Form2.Show()
Label1.Text = random(g)


But how can I represent my labels as numbers. Do I have to rename my labels as numbers?

I don''t know how to connect the generator with the textboxes and labels.


Cindy


If you have a look at the index in the VB Articles area, there''s a routine there to return a random whole-number value within specified limits.


这篇关于Random labels.text的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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