how to sorther variable is too multiple variable
How can I make this code shorter?
I tried, but it does not work because I have that txtDraws.Lines (it's in line). So I want to make this code shorter, but the code has to stay in line, txtdraws. I want to make the code shorter, but follow all of the below, +1 plus each. just txtIntDraws is different, as can be seen in the code.
On Error Resume Next
' Draw 1
Dim firstBoxList1 = txtIntDraws.Lines(1).Split(",").ToArray
Dim secondBoxList1 = txtIntDraws.Lines(2).Split(",").ToList()
Dim intersectionList1 = firstBoxList1.Intersect(secondBoxList1)
For Each str As String In intersectionList1
txtIntDraw1.Text = txtIntDraw1.Text & str & ","
Next
Dim notRepeatedCharacter1 = firstBoxList1.Union(secondBoxList1).ToList
notRepeatedCharacter1.RemoveAll(Function(x) intersectionList1.Contains(x))
For Each str As String In firstBoxList1
txtIntNonI1.Text = txtIntNonI1.Text & str & ","
Next
' Draw 2
Dim firstBoxList2 = txtIntDraws.Lines(2).Split(",").ToArray
Dim secondBoxList2 = txtIntDraws.Lines(3).Split(",").ToList()
Dim intersectionList2 = firstBoxList2.Intersect(secondBoxList2)
For Each str As String In intersectionList2
TxtIntDraw2.Text = TxtIntDraw2.Text & str & ","
Next
Dim notRepeatedCharacter2 = firstBoxList2.Union(secondBoxList2).ToList
notRepeatedCharacter2.RemoveAll(Function(x) intersectionList2.Contains(x))
For Each str As String In firstBoxList2
TxtIntNonI2.Text = TxtIntNonI2.Text & str & ","
Next
' Draw 3
Dim firstBoxList3 = txtIntDraws.Lines(3).Split(",").ToArray
Dim secondBoxList3 = txtIntDraws.Lines(4).Split(",").ToList()
Dim intersectionList3 = firstBoxList3.Intersect(secondBoxList3)
For Each str As String In intersectionList3
TxtIntDraw3.Text = TxtIntDraw3.Text & str & ","
Next
Dim notRepeatedCharacter3 = firstBoxList3.Union(secondBoxList3).ToList
notRepeatedCharacter3.RemoveAll(Function(x) intersectionList3.Contains(x))
For Each str As String In firstBoxList3
TxtIntNonI3.Text = TxtIntNonI3.Text & str & ","
Next
' Draw 4
Dim firstBoxList4 = txtIntDraws.Lines(4).Split(",").ToArray
Dim secondBoxList4 = txtIntDraws.Lines(5).Split(",").ToList()
Dim intersectionList4 = firstBoxList4.Intersect(secondBoxList4)
For Each str As String In intersectionList4
TxtIntDraw4.Text = TxtIntDraw4.Text & str & ","
Next
Dim notRepeatedCharacter4 = firstBoxList4.Union(secondBoxList4).ToList
notRepeatedCharacter4.RemoveAll(Function(x) intersectionList4.Contains(x))
For Each str As String In firstBoxList4
TxtIntNonI4.Text = TxtIntNonI4.Text & str & ","
Next
' Draw 5
Dim firstBoxList5 = txtIntDraws.Lines(5).Split(",").ToArray
Dim secondBoxList5 = txtIntDraws.Lines(6).Split(",").ToList()
Dim intersectionList5 = firstBoxList5.Intersect(secondBoxList5)
For Each str As String In intersectionList5
TxtIntDraw5.Text = TxtIntDraw5.Text & str & ","
Next
Dim notRepeatedCharacter5 = firstBoxList5.Union(secondBoxList5).ToList
notRepeatedCharacter5.RemoveAll(Function(x) intersectionList5.Contains(x))
For Each str As String In firstBoxList5
TxtIntNonI5.Text = TxtIntNonI5.Text & str & ","
Next
vb.net
add a comment |
How can I make this code shorter?
I tried, but it does not work because I have that txtDraws.Lines (it's in line). So I want to make this code shorter, but the code has to stay in line, txtdraws. I want to make the code shorter, but follow all of the below, +1 plus each. just txtIntDraws is different, as can be seen in the code.
On Error Resume Next
' Draw 1
Dim firstBoxList1 = txtIntDraws.Lines(1).Split(",").ToArray
Dim secondBoxList1 = txtIntDraws.Lines(2).Split(",").ToList()
Dim intersectionList1 = firstBoxList1.Intersect(secondBoxList1)
For Each str As String In intersectionList1
txtIntDraw1.Text = txtIntDraw1.Text & str & ","
Next
Dim notRepeatedCharacter1 = firstBoxList1.Union(secondBoxList1).ToList
notRepeatedCharacter1.RemoveAll(Function(x) intersectionList1.Contains(x))
For Each str As String In firstBoxList1
txtIntNonI1.Text = txtIntNonI1.Text & str & ","
Next
' Draw 2
Dim firstBoxList2 = txtIntDraws.Lines(2).Split(",").ToArray
Dim secondBoxList2 = txtIntDraws.Lines(3).Split(",").ToList()
Dim intersectionList2 = firstBoxList2.Intersect(secondBoxList2)
For Each str As String In intersectionList2
TxtIntDraw2.Text = TxtIntDraw2.Text & str & ","
Next
Dim notRepeatedCharacter2 = firstBoxList2.Union(secondBoxList2).ToList
notRepeatedCharacter2.RemoveAll(Function(x) intersectionList2.Contains(x))
For Each str As String In firstBoxList2
TxtIntNonI2.Text = TxtIntNonI2.Text & str & ","
Next
' Draw 3
Dim firstBoxList3 = txtIntDraws.Lines(3).Split(",").ToArray
Dim secondBoxList3 = txtIntDraws.Lines(4).Split(",").ToList()
Dim intersectionList3 = firstBoxList3.Intersect(secondBoxList3)
For Each str As String In intersectionList3
TxtIntDraw3.Text = TxtIntDraw3.Text & str & ","
Next
Dim notRepeatedCharacter3 = firstBoxList3.Union(secondBoxList3).ToList
notRepeatedCharacter3.RemoveAll(Function(x) intersectionList3.Contains(x))
For Each str As String In firstBoxList3
TxtIntNonI3.Text = TxtIntNonI3.Text & str & ","
Next
' Draw 4
Dim firstBoxList4 = txtIntDraws.Lines(4).Split(",").ToArray
Dim secondBoxList4 = txtIntDraws.Lines(5).Split(",").ToList()
Dim intersectionList4 = firstBoxList4.Intersect(secondBoxList4)
For Each str As String In intersectionList4
TxtIntDraw4.Text = TxtIntDraw4.Text & str & ","
Next
Dim notRepeatedCharacter4 = firstBoxList4.Union(secondBoxList4).ToList
notRepeatedCharacter4.RemoveAll(Function(x) intersectionList4.Contains(x))
For Each str As String In firstBoxList4
TxtIntNonI4.Text = TxtIntNonI4.Text & str & ","
Next
' Draw 5
Dim firstBoxList5 = txtIntDraws.Lines(5).Split(",").ToArray
Dim secondBoxList5 = txtIntDraws.Lines(6).Split(",").ToList()
Dim intersectionList5 = firstBoxList5.Intersect(secondBoxList5)
For Each str As String In intersectionList5
TxtIntDraw5.Text = TxtIntDraw5.Text & str & ","
Next
Dim notRepeatedCharacter5 = firstBoxList5.Union(secondBoxList5).ToList
notRepeatedCharacter5.RemoveAll(Function(x) intersectionList5.Contains(x))
For Each str As String In firstBoxList5
TxtIntNonI5.Text = TxtIntNonI5.Text & str & ","
Next
vb.net
A new account? Again? Really man?
– zack raiyan
Jan 1 at 14:54
I'm only Join this My account, this.
– Aji Pangestu
Jan 1 at 14:55
add a comment |
How can I make this code shorter?
I tried, but it does not work because I have that txtDraws.Lines (it's in line). So I want to make this code shorter, but the code has to stay in line, txtdraws. I want to make the code shorter, but follow all of the below, +1 plus each. just txtIntDraws is different, as can be seen in the code.
On Error Resume Next
' Draw 1
Dim firstBoxList1 = txtIntDraws.Lines(1).Split(",").ToArray
Dim secondBoxList1 = txtIntDraws.Lines(2).Split(",").ToList()
Dim intersectionList1 = firstBoxList1.Intersect(secondBoxList1)
For Each str As String In intersectionList1
txtIntDraw1.Text = txtIntDraw1.Text & str & ","
Next
Dim notRepeatedCharacter1 = firstBoxList1.Union(secondBoxList1).ToList
notRepeatedCharacter1.RemoveAll(Function(x) intersectionList1.Contains(x))
For Each str As String In firstBoxList1
txtIntNonI1.Text = txtIntNonI1.Text & str & ","
Next
' Draw 2
Dim firstBoxList2 = txtIntDraws.Lines(2).Split(",").ToArray
Dim secondBoxList2 = txtIntDraws.Lines(3).Split(",").ToList()
Dim intersectionList2 = firstBoxList2.Intersect(secondBoxList2)
For Each str As String In intersectionList2
TxtIntDraw2.Text = TxtIntDraw2.Text & str & ","
Next
Dim notRepeatedCharacter2 = firstBoxList2.Union(secondBoxList2).ToList
notRepeatedCharacter2.RemoveAll(Function(x) intersectionList2.Contains(x))
For Each str As String In firstBoxList2
TxtIntNonI2.Text = TxtIntNonI2.Text & str & ","
Next
' Draw 3
Dim firstBoxList3 = txtIntDraws.Lines(3).Split(",").ToArray
Dim secondBoxList3 = txtIntDraws.Lines(4).Split(",").ToList()
Dim intersectionList3 = firstBoxList3.Intersect(secondBoxList3)
For Each str As String In intersectionList3
TxtIntDraw3.Text = TxtIntDraw3.Text & str & ","
Next
Dim notRepeatedCharacter3 = firstBoxList3.Union(secondBoxList3).ToList
notRepeatedCharacter3.RemoveAll(Function(x) intersectionList3.Contains(x))
For Each str As String In firstBoxList3
TxtIntNonI3.Text = TxtIntNonI3.Text & str & ","
Next
' Draw 4
Dim firstBoxList4 = txtIntDraws.Lines(4).Split(",").ToArray
Dim secondBoxList4 = txtIntDraws.Lines(5).Split(",").ToList()
Dim intersectionList4 = firstBoxList4.Intersect(secondBoxList4)
For Each str As String In intersectionList4
TxtIntDraw4.Text = TxtIntDraw4.Text & str & ","
Next
Dim notRepeatedCharacter4 = firstBoxList4.Union(secondBoxList4).ToList
notRepeatedCharacter4.RemoveAll(Function(x) intersectionList4.Contains(x))
For Each str As String In firstBoxList4
TxtIntNonI4.Text = TxtIntNonI4.Text & str & ","
Next
' Draw 5
Dim firstBoxList5 = txtIntDraws.Lines(5).Split(",").ToArray
Dim secondBoxList5 = txtIntDraws.Lines(6).Split(",").ToList()
Dim intersectionList5 = firstBoxList5.Intersect(secondBoxList5)
For Each str As String In intersectionList5
TxtIntDraw5.Text = TxtIntDraw5.Text & str & ","
Next
Dim notRepeatedCharacter5 = firstBoxList5.Union(secondBoxList5).ToList
notRepeatedCharacter5.RemoveAll(Function(x) intersectionList5.Contains(x))
For Each str As String In firstBoxList5
TxtIntNonI5.Text = TxtIntNonI5.Text & str & ","
Next
vb.net
How can I make this code shorter?
I tried, but it does not work because I have that txtDraws.Lines (it's in line). So I want to make this code shorter, but the code has to stay in line, txtdraws. I want to make the code shorter, but follow all of the below, +1 plus each. just txtIntDraws is different, as can be seen in the code.
On Error Resume Next
' Draw 1
Dim firstBoxList1 = txtIntDraws.Lines(1).Split(",").ToArray
Dim secondBoxList1 = txtIntDraws.Lines(2).Split(",").ToList()
Dim intersectionList1 = firstBoxList1.Intersect(secondBoxList1)
For Each str As String In intersectionList1
txtIntDraw1.Text = txtIntDraw1.Text & str & ","
Next
Dim notRepeatedCharacter1 = firstBoxList1.Union(secondBoxList1).ToList
notRepeatedCharacter1.RemoveAll(Function(x) intersectionList1.Contains(x))
For Each str As String In firstBoxList1
txtIntNonI1.Text = txtIntNonI1.Text & str & ","
Next
' Draw 2
Dim firstBoxList2 = txtIntDraws.Lines(2).Split(",").ToArray
Dim secondBoxList2 = txtIntDraws.Lines(3).Split(",").ToList()
Dim intersectionList2 = firstBoxList2.Intersect(secondBoxList2)
For Each str As String In intersectionList2
TxtIntDraw2.Text = TxtIntDraw2.Text & str & ","
Next
Dim notRepeatedCharacter2 = firstBoxList2.Union(secondBoxList2).ToList
notRepeatedCharacter2.RemoveAll(Function(x) intersectionList2.Contains(x))
For Each str As String In firstBoxList2
TxtIntNonI2.Text = TxtIntNonI2.Text & str & ","
Next
' Draw 3
Dim firstBoxList3 = txtIntDraws.Lines(3).Split(",").ToArray
Dim secondBoxList3 = txtIntDraws.Lines(4).Split(",").ToList()
Dim intersectionList3 = firstBoxList3.Intersect(secondBoxList3)
For Each str As String In intersectionList3
TxtIntDraw3.Text = TxtIntDraw3.Text & str & ","
Next
Dim notRepeatedCharacter3 = firstBoxList3.Union(secondBoxList3).ToList
notRepeatedCharacter3.RemoveAll(Function(x) intersectionList3.Contains(x))
For Each str As String In firstBoxList3
TxtIntNonI3.Text = TxtIntNonI3.Text & str & ","
Next
' Draw 4
Dim firstBoxList4 = txtIntDraws.Lines(4).Split(",").ToArray
Dim secondBoxList4 = txtIntDraws.Lines(5).Split(",").ToList()
Dim intersectionList4 = firstBoxList4.Intersect(secondBoxList4)
For Each str As String In intersectionList4
TxtIntDraw4.Text = TxtIntDraw4.Text & str & ","
Next
Dim notRepeatedCharacter4 = firstBoxList4.Union(secondBoxList4).ToList
notRepeatedCharacter4.RemoveAll(Function(x) intersectionList4.Contains(x))
For Each str As String In firstBoxList4
TxtIntNonI4.Text = TxtIntNonI4.Text & str & ","
Next
' Draw 5
Dim firstBoxList5 = txtIntDraws.Lines(5).Split(",").ToArray
Dim secondBoxList5 = txtIntDraws.Lines(6).Split(",").ToList()
Dim intersectionList5 = firstBoxList5.Intersect(secondBoxList5)
For Each str As String In intersectionList5
TxtIntDraw5.Text = TxtIntDraw5.Text & str & ","
Next
Dim notRepeatedCharacter5 = firstBoxList5.Union(secondBoxList5).ToList
notRepeatedCharacter5.RemoveAll(Function(x) intersectionList5.Contains(x))
For Each str As String In firstBoxList5
TxtIntNonI5.Text = TxtIntNonI5.Text & str & ","
Next
vb.net
vb.net
asked Jan 1 at 10:18
Aji PangestuAji Pangestu
44
44
A new account? Again? Really man?
– zack raiyan
Jan 1 at 14:54
I'm only Join this My account, this.
– Aji Pangestu
Jan 1 at 14:55
add a comment |
A new account? Again? Really man?
– zack raiyan
Jan 1 at 14:54
I'm only Join this My account, this.
– Aji Pangestu
Jan 1 at 14:55
A new account? Again? Really man?
– zack raiyan
Jan 1 at 14:54
A new account? Again? Really man?
– zack raiyan
Jan 1 at 14:54
I'm only Join this My account, this.
– Aji Pangestu
Jan 1 at 14:55
I'm only Join this My account, this.
– Aji Pangestu
Jan 1 at 14:55
add a comment |
1 Answer
1
active
oldest
votes
You need the Controls.Find() method, which allows you to retrieve a reference to controls "by name".
With that, your code simple becomes:
On Error Resume Next
Dim TB As TextBox
Dim SB As New System.Text.StringBuilder
For i As Integer = 1 To 5
Dim firstBoxList = txtIntDraws.Lines(i).Split(",").ToArray
Dim secondBoxList = txtIntDraws.Lines(i + 1).Split(",").ToList()
Dim intersectionList = firstBoxList.Intersect(secondBoxList)
TB = Me.Controls.Find("txtIntDraw" & i, True).FirstOrDefault
If Not IsNothing(TB) Then
SB.Clear()
SB.Append(TB.Text)
For Each str As String In intersectionList
SB.Append(str & ",")
Next
TB.Text = SB.ToString
End If
Dim notRepeatedCharacter = firstBoxList.Union(secondBoxList).ToList
notRepeatedCharacter.RemoveAll(Function(x) intersectionList.Contains(x))
TB = Me.Controls.Find("txtIntNonI" & i, True).FirstOrDefault
If Not IsNothing(TB) Then
SB.Clear()
SB.Append(TB.Text)
For Each str As String In firstBoxList
SB.Append(str & ",")
Next
TB.Text = SB.ToString
End If
Next
Just change the number 5
in the For
loop so that it goes up as high as you need it to.
It seems like you're not using thenotRepeatedCharacter
list, though. Is that lastFor Each
loop possibly using the wrong variable? Maybe you need to changefirstBoxList
tonotRepeatedCharacter
? Not sure what you're doing here, so ignore this comment if it is working the way you want it to...
– Idle_Mind
Jan 1 at 14:14
Public member 'Intersect' on type 'String()' not found. Line Error: intersectionList = firstBoxList.Intersect(secondBoxList)
– Aji Pangestu
Jan 1 at 14:45
That part was the same as you had before. I simply changed the name and moved the declaration outside the loop. I moved the declaration down inside the loop, but this shouldn't really make any difference. I'm guessing you implemented it incorrectly. Show us your new code if it continues to give you problems.
– Idle_Mind
Jan 1 at 15:01
For Each str As String In firstBoxList TB.AppendText(str & ",") Next - Object reference not set to an instance of an object.
– Aji Pangestu
Jan 1 at 15:08
Now is worked... haha , I needed to be here - txtIntNonI "instead of txtIntNon. Thanks!
– Aji Pangestu
Jan 1 at 15:10
|
show 3 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53994662%2fhow-to-sorther-variable-is-too-multiple-variable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need the Controls.Find() method, which allows you to retrieve a reference to controls "by name".
With that, your code simple becomes:
On Error Resume Next
Dim TB As TextBox
Dim SB As New System.Text.StringBuilder
For i As Integer = 1 To 5
Dim firstBoxList = txtIntDraws.Lines(i).Split(",").ToArray
Dim secondBoxList = txtIntDraws.Lines(i + 1).Split(",").ToList()
Dim intersectionList = firstBoxList.Intersect(secondBoxList)
TB = Me.Controls.Find("txtIntDraw" & i, True).FirstOrDefault
If Not IsNothing(TB) Then
SB.Clear()
SB.Append(TB.Text)
For Each str As String In intersectionList
SB.Append(str & ",")
Next
TB.Text = SB.ToString
End If
Dim notRepeatedCharacter = firstBoxList.Union(secondBoxList).ToList
notRepeatedCharacter.RemoveAll(Function(x) intersectionList.Contains(x))
TB = Me.Controls.Find("txtIntNonI" & i, True).FirstOrDefault
If Not IsNothing(TB) Then
SB.Clear()
SB.Append(TB.Text)
For Each str As String In firstBoxList
SB.Append(str & ",")
Next
TB.Text = SB.ToString
End If
Next
Just change the number 5
in the For
loop so that it goes up as high as you need it to.
It seems like you're not using thenotRepeatedCharacter
list, though. Is that lastFor Each
loop possibly using the wrong variable? Maybe you need to changefirstBoxList
tonotRepeatedCharacter
? Not sure what you're doing here, so ignore this comment if it is working the way you want it to...
– Idle_Mind
Jan 1 at 14:14
Public member 'Intersect' on type 'String()' not found. Line Error: intersectionList = firstBoxList.Intersect(secondBoxList)
– Aji Pangestu
Jan 1 at 14:45
That part was the same as you had before. I simply changed the name and moved the declaration outside the loop. I moved the declaration down inside the loop, but this shouldn't really make any difference. I'm guessing you implemented it incorrectly. Show us your new code if it continues to give you problems.
– Idle_Mind
Jan 1 at 15:01
For Each str As String In firstBoxList TB.AppendText(str & ",") Next - Object reference not set to an instance of an object.
– Aji Pangestu
Jan 1 at 15:08
Now is worked... haha , I needed to be here - txtIntNonI "instead of txtIntNon. Thanks!
– Aji Pangestu
Jan 1 at 15:10
|
show 3 more comments
You need the Controls.Find() method, which allows you to retrieve a reference to controls "by name".
With that, your code simple becomes:
On Error Resume Next
Dim TB As TextBox
Dim SB As New System.Text.StringBuilder
For i As Integer = 1 To 5
Dim firstBoxList = txtIntDraws.Lines(i).Split(",").ToArray
Dim secondBoxList = txtIntDraws.Lines(i + 1).Split(",").ToList()
Dim intersectionList = firstBoxList.Intersect(secondBoxList)
TB = Me.Controls.Find("txtIntDraw" & i, True).FirstOrDefault
If Not IsNothing(TB) Then
SB.Clear()
SB.Append(TB.Text)
For Each str As String In intersectionList
SB.Append(str & ",")
Next
TB.Text = SB.ToString
End If
Dim notRepeatedCharacter = firstBoxList.Union(secondBoxList).ToList
notRepeatedCharacter.RemoveAll(Function(x) intersectionList.Contains(x))
TB = Me.Controls.Find("txtIntNonI" & i, True).FirstOrDefault
If Not IsNothing(TB) Then
SB.Clear()
SB.Append(TB.Text)
For Each str As String In firstBoxList
SB.Append(str & ",")
Next
TB.Text = SB.ToString
End If
Next
Just change the number 5
in the For
loop so that it goes up as high as you need it to.
It seems like you're not using thenotRepeatedCharacter
list, though. Is that lastFor Each
loop possibly using the wrong variable? Maybe you need to changefirstBoxList
tonotRepeatedCharacter
? Not sure what you're doing here, so ignore this comment if it is working the way you want it to...
– Idle_Mind
Jan 1 at 14:14
Public member 'Intersect' on type 'String()' not found. Line Error: intersectionList = firstBoxList.Intersect(secondBoxList)
– Aji Pangestu
Jan 1 at 14:45
That part was the same as you had before. I simply changed the name and moved the declaration outside the loop. I moved the declaration down inside the loop, but this shouldn't really make any difference. I'm guessing you implemented it incorrectly. Show us your new code if it continues to give you problems.
– Idle_Mind
Jan 1 at 15:01
For Each str As String In firstBoxList TB.AppendText(str & ",") Next - Object reference not set to an instance of an object.
– Aji Pangestu
Jan 1 at 15:08
Now is worked... haha , I needed to be here - txtIntNonI "instead of txtIntNon. Thanks!
– Aji Pangestu
Jan 1 at 15:10
|
show 3 more comments
You need the Controls.Find() method, which allows you to retrieve a reference to controls "by name".
With that, your code simple becomes:
On Error Resume Next
Dim TB As TextBox
Dim SB As New System.Text.StringBuilder
For i As Integer = 1 To 5
Dim firstBoxList = txtIntDraws.Lines(i).Split(",").ToArray
Dim secondBoxList = txtIntDraws.Lines(i + 1).Split(",").ToList()
Dim intersectionList = firstBoxList.Intersect(secondBoxList)
TB = Me.Controls.Find("txtIntDraw" & i, True).FirstOrDefault
If Not IsNothing(TB) Then
SB.Clear()
SB.Append(TB.Text)
For Each str As String In intersectionList
SB.Append(str & ",")
Next
TB.Text = SB.ToString
End If
Dim notRepeatedCharacter = firstBoxList.Union(secondBoxList).ToList
notRepeatedCharacter.RemoveAll(Function(x) intersectionList.Contains(x))
TB = Me.Controls.Find("txtIntNonI" & i, True).FirstOrDefault
If Not IsNothing(TB) Then
SB.Clear()
SB.Append(TB.Text)
For Each str As String In firstBoxList
SB.Append(str & ",")
Next
TB.Text = SB.ToString
End If
Next
Just change the number 5
in the For
loop so that it goes up as high as you need it to.
You need the Controls.Find() method, which allows you to retrieve a reference to controls "by name".
With that, your code simple becomes:
On Error Resume Next
Dim TB As TextBox
Dim SB As New System.Text.StringBuilder
For i As Integer = 1 To 5
Dim firstBoxList = txtIntDraws.Lines(i).Split(",").ToArray
Dim secondBoxList = txtIntDraws.Lines(i + 1).Split(",").ToList()
Dim intersectionList = firstBoxList.Intersect(secondBoxList)
TB = Me.Controls.Find("txtIntDraw" & i, True).FirstOrDefault
If Not IsNothing(TB) Then
SB.Clear()
SB.Append(TB.Text)
For Each str As String In intersectionList
SB.Append(str & ",")
Next
TB.Text = SB.ToString
End If
Dim notRepeatedCharacter = firstBoxList.Union(secondBoxList).ToList
notRepeatedCharacter.RemoveAll(Function(x) intersectionList.Contains(x))
TB = Me.Controls.Find("txtIntNonI" & i, True).FirstOrDefault
If Not IsNothing(TB) Then
SB.Clear()
SB.Append(TB.Text)
For Each str As String In firstBoxList
SB.Append(str & ",")
Next
TB.Text = SB.ToString
End If
Next
Just change the number 5
in the For
loop so that it goes up as high as you need it to.
edited Jan 1 at 16:56
answered Jan 1 at 14:07


Idle_MindIdle_Mind
23.5k21424
23.5k21424
It seems like you're not using thenotRepeatedCharacter
list, though. Is that lastFor Each
loop possibly using the wrong variable? Maybe you need to changefirstBoxList
tonotRepeatedCharacter
? Not sure what you're doing here, so ignore this comment if it is working the way you want it to...
– Idle_Mind
Jan 1 at 14:14
Public member 'Intersect' on type 'String()' not found. Line Error: intersectionList = firstBoxList.Intersect(secondBoxList)
– Aji Pangestu
Jan 1 at 14:45
That part was the same as you had before. I simply changed the name and moved the declaration outside the loop. I moved the declaration down inside the loop, but this shouldn't really make any difference. I'm guessing you implemented it incorrectly. Show us your new code if it continues to give you problems.
– Idle_Mind
Jan 1 at 15:01
For Each str As String In firstBoxList TB.AppendText(str & ",") Next - Object reference not set to an instance of an object.
– Aji Pangestu
Jan 1 at 15:08
Now is worked... haha , I needed to be here - txtIntNonI "instead of txtIntNon. Thanks!
– Aji Pangestu
Jan 1 at 15:10
|
show 3 more comments
It seems like you're not using thenotRepeatedCharacter
list, though. Is that lastFor Each
loop possibly using the wrong variable? Maybe you need to changefirstBoxList
tonotRepeatedCharacter
? Not sure what you're doing here, so ignore this comment if it is working the way you want it to...
– Idle_Mind
Jan 1 at 14:14
Public member 'Intersect' on type 'String()' not found. Line Error: intersectionList = firstBoxList.Intersect(secondBoxList)
– Aji Pangestu
Jan 1 at 14:45
That part was the same as you had before. I simply changed the name and moved the declaration outside the loop. I moved the declaration down inside the loop, but this shouldn't really make any difference. I'm guessing you implemented it incorrectly. Show us your new code if it continues to give you problems.
– Idle_Mind
Jan 1 at 15:01
For Each str As String In firstBoxList TB.AppendText(str & ",") Next - Object reference not set to an instance of an object.
– Aji Pangestu
Jan 1 at 15:08
Now is worked... haha , I needed to be here - txtIntNonI "instead of txtIntNon. Thanks!
– Aji Pangestu
Jan 1 at 15:10
It seems like you're not using the
notRepeatedCharacter
list, though. Is that last For Each
loop possibly using the wrong variable? Maybe you need to change firstBoxList
to notRepeatedCharacter
? Not sure what you're doing here, so ignore this comment if it is working the way you want it to...– Idle_Mind
Jan 1 at 14:14
It seems like you're not using the
notRepeatedCharacter
list, though. Is that last For Each
loop possibly using the wrong variable? Maybe you need to change firstBoxList
to notRepeatedCharacter
? Not sure what you're doing here, so ignore this comment if it is working the way you want it to...– Idle_Mind
Jan 1 at 14:14
Public member 'Intersect' on type 'String()' not found. Line Error: intersectionList = firstBoxList.Intersect(secondBoxList)
– Aji Pangestu
Jan 1 at 14:45
Public member 'Intersect' on type 'String()' not found. Line Error: intersectionList = firstBoxList.Intersect(secondBoxList)
– Aji Pangestu
Jan 1 at 14:45
That part was the same as you had before. I simply changed the name and moved the declaration outside the loop. I moved the declaration down inside the loop, but this shouldn't really make any difference. I'm guessing you implemented it incorrectly. Show us your new code if it continues to give you problems.
– Idle_Mind
Jan 1 at 15:01
That part was the same as you had before. I simply changed the name and moved the declaration outside the loop. I moved the declaration down inside the loop, but this shouldn't really make any difference. I'm guessing you implemented it incorrectly. Show us your new code if it continues to give you problems.
– Idle_Mind
Jan 1 at 15:01
For Each str As String In firstBoxList TB.AppendText(str & ",") Next - Object reference not set to an instance of an object.
– Aji Pangestu
Jan 1 at 15:08
For Each str As String In firstBoxList TB.AppendText(str & ",") Next - Object reference not set to an instance of an object.
– Aji Pangestu
Jan 1 at 15:08
Now is worked... haha , I needed to be here - txtIntNonI "instead of txtIntNon. Thanks!
– Aji Pangestu
Jan 1 at 15:10
Now is worked... haha , I needed to be here - txtIntNonI "instead of txtIntNon. Thanks!
– Aji Pangestu
Jan 1 at 15:10
|
show 3 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53994662%2fhow-to-sorther-variable-is-too-multiple-variable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
A new account? Again? Really man?
– zack raiyan
Jan 1 at 14:54
I'm only Join this My account, this.
– Aji Pangestu
Jan 1 at 14:55