Home > Software engineering >  VB how to define a set of number [only a is 1, the other is 0]?
VB how to define a set of number [only a is 1, the other is 0]?

Time:09-29

Such as array Arr (10)
I want to assign a value
But did not give specific refers to the first
Only qualified
Only one of their values is 1
Everything else is 0
How to do?

(PS: they are at the same time, not the if one took 1, then everything else is 0, there is no order, to ensure a 1 at the same time, N - 1 0)

CodePudding user response:

Arr (10), there is only one element of the value is 1, 0, all the rest?
Then do you still use an array? Directly with an integer said don't have to do is: if the number is a non-negative integer power of 2, said legal, if not in both cases, said it would be illegal,

CodePudding user response:

You define an array directly, and then they assign to a 1, isn't it just finished the rest of the 0.
Is this your code, you have the final say.

CodePudding user response:

If in the array is a chance, you can use the vb random function, it is not good,

A random out of the array, then the assignment for one, the other is zero

CodePudding user response:

Array can do this job, you must write their own code

CodePudding user response:

Use OptionButton controls

CodePudding user response:

This???????
Dim arr (10) as string
For I=0 to ubound (arr)
If I=0 then
Arr (I)=1
The else
Arr (I)=0
End the if
I=I + 1
Next

CodePudding user response:

reference 5 floor zhao4zhong1 reply:
use OptionButton controls


Of an arbitrary value is set to true, the other is False,

CodePudding user response:

It can be:

Dim As Integer I

For I=0 To 10
Arr (I)=0
Next I

Randomize
I=Int (Rnd * 11)
Arr (I)=1
  • Related