For i = 0 To 27
Dim value As Integer = CInt(Int((10 * Rnd()) + 1))
If i / 9 = 0 Then
'...
End If
Next i
If I havd the Labels, there are Label1,Label2,Label3,Label4...etc...Label27
If i / 9 = 0, then the i th of label text is "Hello", otherwise, it will show "Hi"
how can I do it?
the for loop will add i from 1 to 27, then so
i/9=0:
label1's text= "HI"
label2's text="HI"
.
.
.
label9's text="Hello"
.
.
.
label18's text="Hello"
.
.
.
label27's text="Hello"
If you put your 27 labels into an array then you can reference them by index
Code:
Dim Labels() As Label = {Label1, Label2, Label3, ..., Label27}
For i As Integer = 0 To 26
If (i Mod 9) = 0 Then
Labels(i).Text = "Hello"
Else
Labels(i).Text = "Hi"
End If
Next
If you put your 27 labels into an array then you can reference them by index
Code:
Dim Labels() As Label = {Label1, Label2, Label3, ..., Label27}
For i As Integer = 0 To 26
If (i Mod 9) = 0 Then
Labels(i).Text = "Hello"
Else
Labels(i).Text = "Hi"
End If
Next
how can i modify their location? If I count the location, it seems quite trouble
And...Actually, I have 90 labels 27 is simple to say
the for loop will add i from 1 to 27, then so
i/9=0:
label1's text= "HI"
label2's text="HI"
.
.
.
label9's text="Hello"
.
.
.
label18's text="Hello"
.
.
.
label27's text="Hello"
i/9 = 0 happens only when i = 0 where as i \ 9 = 0 happens when i < 9
The difference? The / operator is for floating point division and the \ operator is for integer division.
i/9 = 0 happens only when i = 0 where as i \ 9 = 0 happens when i < 9
The difference? The / operator is for floating point division and the \ operator is for integer division.
I see...After read yr atricle, now I think mod is equal to \
I see...After read yr atricle, now I think mod is equal to \
Nope... Mod is modulus division. That is, it'll return the remainder of an integer division
For example
5 \ 9 = 0 where as 5 Mod 9 = 5
9 \ 9 = 1 where as 9 Mod 9 = 0
If you set a breakpoint on that line, you could then copy it, go to the Command Window (this is all in the debugger), type "?" and then paste it, hit enter, and it would display what that code evaluates to at that moment.
You could paste any part of it that you want, for instance:
"?(Mid(ctl.Text.ToString, 6)) Mod 9"
or
"?Mid(ctl.Text.ToString, 6)"
If you learn how to use breakpoints and other features, you can solve many of your problems.
You click to the left of the code. I have attached a pic. Now, when the program reaches that line of code, execution will come to a halt. Then, you can look at values of variables and such.
Use F11 to step through the code one line at a time, and F5 to resume execution. You can set as many breakpoints as you would like.
Last edited by 18experience; Mar 23rd, 2010 at 09:37 AM.
This is a picture of the Command Window, commonly found in the bottom right corner of the IDE. You just type "?" and then whatever else afterwards and it will attempt to evaluate it.
Like:
"?5 + 3" will return 8
"?Me.Text" will return the title of your app
and so on and so on...
You can also use the Command Window when your app crashes in debug mode. It usually shows you the line that it errored on, and you can look at what could have done that (possibly an out of bounds exception on an array, thats fairly common).
Last edited by 18experience; Mar 23rd, 2010 at 09:37 AM.
Dim myArr As String() = {"◕", "▲", "●", "◆", "★", "☆", "*", "♀", "↗", "→"}
Dim i As Integer = 0
Dim j As Integer = 9
Dim myRnd As New Random
Dim myVal As Integer = myRnd.Next(0, 9)
For Each ctl As Control In Me.Controls
Dim myVal1 As Integer = myRnd.Next(0, 9)
Console.WriteLine("value1: " & myVal)
Console.WriteLine("value: " & myVal1)
If TypeOf ctl Is Label Then
If (Mid(ctl.Text.ToString, 6)) Mod 9 Then
i += 1
ctl.Text = i & ": " & myArr(myVal1)
Else
ctl.Text = j & ": " & myArr(myVal)
j += 9
i += 1
End If
End If
You need to trace the code then you will get the solution, I think this problem is occurring due to the value of the I and J because , if IF part you are putting the value I on the label and In Else part you are putting the value of J on the Label
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myArr As String() = {"◕", "▲", "●", "◆", "★", "☆", "*", "♀", "↗", "→"}
Dim i As Integer = 0
Dim myRnd As New Random
Dim myVal As Integer = myRnd.Next(0, 9)
For Each ctl As Control In Me.Controls
Dim myVal1 As Integer = myRnd.Next(0, 9)
Console.WriteLine("value1: " & myVal)
Console.WriteLine("value: " & myVal1)
If TypeOf ctl Is Label Then
If (Mid(ctl.Text.ToString, 6)) Mod 9 Then
i += 1
ctl.Text = i & ": " & myArr(myVal1)
Else
ctl.Text = i & ": " & myArr(myVal)
i += 1
End If
End If
Next
End Sub
If i dun use i and j, the num will not be repeated , but it is really confusing
You are doing the old divide by 9 trick (think of a number, add the digits, subract it from the original).
What you need to do is re-sort the string order at the very beginning. Then loop through and take the mod 9. of all the numbers. If the remainder is 0 use the first char, 1 use the second char, etc...
I haven't looked at your code, but knowing what you want to do and why will help you create the program. Break it down into the steps and have fun. This is a interesting project to do.
You are doing the old divide by 9 trick (think of a number, add the digits, subract it from the original).
What you need to do is re-sort the string order at the very beginning. Then loop through and take the mod 9. of all the numbers. If the remainder is 0 use the first char, 1 use the second char, etc...
I haven't looked at your code, but knowing what you want to do and why will help you create the program. Break it down into the steps and have fun. This is a interesting project to do.
U know what I am doing?
That's a really interesting program, when I finish it, I will post it to share with yours