मेरे पास दो टेक्स्टबॉक्स हैं:
प्रथम:
Textbox1.lines(0) = 50
Textbox1.lines(1) = 65
Textbox1.lines(2) = 41
Textbox1.lines(3) = 27
Textbox1.lines(4) = 6
Textbox1.lines(5) = 6
दूसरा:
Textbox2.lines(0) = 27
Textbox2.lines(1) = 41
Textbox2.lines(2) = 65
Textbox2.lines(3) = 6
Textbox2.lines(4) = 50
Textbox2.lines(5) = 6
तीसरे टेक्स्टबॉक्स में मुझे उस इंडेक्स को प्रदर्शित करना चाहिए जिसमें पहले टेक्स्टबॉक्स से मान हों, लेकिन दूसरे में।
Textbox3.lines(0) = 4 (50 of the first textbox is on the second line (lines4)
Textbox3.lines(1) = 2 (65 of the first textbox is on the second line (lines2)
Textbox3.lines(2) = 1 (41 of the first textbox is on the second line (lines1)
Textbox3.lines(3) = 0 (27 of the first textbox is on the second line (lines0)
Textbox3.lines(4) = 3 (6 of the first textbox is on the second line (lines4)
Textbox3.lines(5) = 5 (6 of the first textbox is on the second line (lines5)
हालांकि यह पहले से ही लाइन ४ (नंबर ६) पर मौजूद है, हम अगली पंक्ति को आगे बढ़ाएंगे, क्योंकि उस लाइन पर पहले ही विचार किया जा चुका है। या दोनों सूचकांक प्रदर्शित किया जा सकता है। या किसी तरह लाइन मान शून्य (0) हो जाता है ताकि इसे न लिया जाए।
कोड: दुर्भाग्य से, यह ठीक से काम नहीं करता है।
For Each line In TextBox1.Lines
For l As Integer = 1 To TextBox1.Lines.Length - 1
If TextBox2.Lines(l) = line Then
TextBox3.AppendText(l)
End If
Next
Next
3 जवाब
यह काम करना चाहिए:
For Each line In TextBox1.Lines
Dim i As Integer = 0
While (i < TextBox1.Lines.Length)
If TextBox2.Lines(i) = line Then
TextBox3.AppendText(i & Environment.NewLine)
Continue For
End If
i += 1
End While
Next
इसके लिए जारी रखें के साथ, कोड अगले लूप के लिए जाता है।
या यदि आप सभी पुनरावृत्तियों को प्रदर्शित करना चाहते हैं:
For Each line In TextBox1.Lines
Dim i As Integer = 0
While (i < TextBox1.Lines.Length)
If TextBox2.Lines(i) = line Then
TextBox3.AppendText(i & " ")
End If
i += 1
End While
TextBox3.AppendText(Environment.NewLine)
Next
मैं एक सूची की मदद से ऐसा करने में कामयाब रहा। काम करने के लिए, लाइनों की संख्या बराबर होनी चाहिए।
Dim valI As New List(Of Integer)
For nIndex As Integer = 0 To Textbox2.Lines.Length -1
For i As Integer = 0 To TextBox1.Lines.Length - 1
If TextBox2.Lines(nIndex) = TextBox1.Lines(i) Then
If valI.Contains(i) Then
Else
valI.Add(i)
End If
End If
Next
Textbox3.AppendText(vbNewline & valI.Item(nIndex))
Next
यह दृष्टिकोण कुंजी के रूप में संख्या के साथ एक शब्दकोश का उपयोग करता है, और मूल्य के रूप में सूचकांकों की एक कतार का उपयोग करता है।
जब हम पहली बार टेक्स्टबॉक्स 1 से किसी संख्या का सामना करते हैं, तो हम उन सभी सूचकांकों की एक कतार बनाते हैं जहां टेक्स्टबॉक्स 2 में संख्या होती है। फिर हर बार जब हम उस नंबर का सामना करते हैं, तो हम अगले उपलब्ध नंबर को हटा देते हैं जहां यह हुआ था। यदि कोई नहीं बचा है, तो हम -1 लौटाते हैं।
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim results As New List(Of String)
Dim occurrences As New Dictionary(Of Integer, Queue(Of Integer))
For Each number As String In TextBox1.Lines
If Not occurrences.ContainsKey(number) Then
occurrences.Add(number, New Queue(Of Integer))
For i As Integer = 0 To TextBox2.Lines.Count - 1
If TextBox2.Lines(i) = number Then
occurrences(number).Enqueue(i)
End If
Next
End If
If occurrences(number).Count > 0 Then
results.Add(occurrences(number).Dequeue)
Else
results.Add("-1")
End If
Next
TextBox3.Lines = results.ToArray
End Sub
नए सवाल
vb.net
Visual Basic.NET (VB.NET) एक बहु-प्रतिमान, प्रबंधित, प्रकार-सुरक्षित, ऑब्जेक्ट-उन्मुख कंप्यूटर प्रोग्रामिंग भाषा है। C # और F # के साथ, यह .NET फ्रेमवर्क को लक्षित करने वाली मुख्य भाषाओं में से एक है। VB.NET को Microsoft के Visual Basic 6 (VB6) के विकास के रूप में देखा जा सकता है लेकिन Microsoft .NET फ्रेमवर्क पर लागू किया जा सकता है। VB6, VBA या VBScript प्रश्नों के लिए इस टैग का उपयोग न करें।