Sync Two Textbox Lines VB.Net - vb.net

How do I sync 2 Textboxes? I mean, if I randomize the first Textbox (Randomize Text Lines) how do the 2nd Textbox be synchronized after the first Textbox?
I also want the 4 Textboxes containing the items to be saved in (Answer.dat) for example if in the first Textbox I have the element (BlackJack) in the 2nd Textbox element (21) in the 3rd Textbox the Poker element and the fourth Textbox element Bingo.
I want to save this in the new line (in my text file) to be something like the model (Blank Empty + Word(Textbox3) + Space + Word(Textbox4) + Space + Word(Textbox5) + Space + Word(Textbox6) this is the Screenshot how the items want to be saved. Unfortunately, I'm not doing too well with the blank at first.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = System.IO.File.ReadAllText(My.Application.Info.DirectoryPath + ("\Data\Question.dat"))
TextBox2.Text = System.IO.File.ReadAllText(My.Application.Info.DirectoryPath + ("\Data\Answer.dat"))
End Sub
End Class
So how can I do to save in a new line of Textbox (Save to my text file) the question and the answers in the textbox? following the example given?

The code below will keep the rows synchronized on a random shuffle. If you don't want repeated rows, you will have to code validation to throw-out draws that have already occurred.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim text1 As String
Dim text2 As String
Dim textarray1 As New ArrayList
Dim textarray2 As New ArrayList
Dim NextMember As String = ""
Dim Rand As New Random
Dim RandNum As Integer = 0
TextBox1.Clear()
TextBox2.Clear()
text1 = "one" & vbCrLf & "two" & vbCrLf & "three" & vbCrLf
text2 = "A" & vbCrLf & "B" & vbCrLf & "C" & vbCrLf
For i = 1 To Len(text1)
Do Until Mid(text1, i, 1) = vbCr
NextMember = NextMember & Mid(text1, i, 1)
i = i + 1
Loop
textarray1.Add(NextMember)
i = i + 1
NextMember = ""
Next
For i = 1 To Len(text2)
Do Until Mid(text2, i, 1) = vbCr
NextMember = NextMember & Mid(text2, i, 1)
i = i + 1
Loop
textarray2.Add(NextMember)
i = i + 1
NextMember = ""
Next
For i = 0 To textarray1.Count - 1
RandNum = Rand.Next(textarray1.Count)
TextBox1.Text = TextBox1.Text & textarray1(RandNum) & vbCrLf
TextBox2.Text = TextBox2.Text & textarray2(RandNum) & vbCrLf
Next
End Sub

Related

I need to print multiple copies of a barcode label in VB.NET with crystal report

i have tried
Private Sub MOSTRAR_Click(sender As Object, e As EventArgs) Handles MOSTRARButton.Click
BARCODEReportViewer.ReportSource = Application.StartupPath + "\BARCODE\BarcodeReport.rpt"
Dim box As Integer = TextBox2.Text
Dim index As Integer = 0
Dim stringFormula As String
stringFormula = "{PRODUCT.PRO_UNIT_BARCODE} = '" & TextBox1.Text.ToString() & "'"
stringFormula &= "Or {PRODUCT.PRO_BARCODE_PACK} = '" & TextBox1.Text.ToString() & "'"
While index <= box
BARCODEReportViewer.SelectionFormula = stringFormula
index += 1
End While
BARCODEReportViewer.Refresh()
BARCODEReportViewer.RefreshReport()
End Sub

How to insert a numbered bullet list in richtextbox

I am trying to insert a numbered bullet list when a user selects the button it will increment the counter
I have searched questions online and different types of loop condition statements
Private Sub ToolStripButton16_Click(sender As Object, e As EventArgs) Handles ToolStripButton16.Click
ToolStripButton16.CheckOnClick = False
Dim i As Integer
i = 0
Dim numbList As String
Dim buttonClickCount As Integer
buttonClickCount = 0
Do While (i = buttonClickCount)
i += 1
numbList = " " & i & "." & vbCrLf
RichTextBox1.AppendText(numbList)
Loop
buttonClickCount += 1
End Sub
Expected result:
1.
2.
3.
4.
Probably not the most elegant solution but it should put you in the right direction.
'Using a class variable here allows you to keep an "application state".
Dim buttonClickCount as Integer = 0
Private Sub ToolStripButton16_Click(sender As Object, e As EventArgs) Handles ToolStripButton16.Click
ToolStripButton16.CheckOnClick = False
buttonClickCount += 1
Dim newValue As String = " " & buttonClickCount & "." & vbCrLf
RichTextBox1.AppendText(newValue)
End Sub

Index Val List VB.Net

I have a Listbox called ListTxtDrawR4. Every time I select an item, I want to display the value corresponding to the index in a textbox with name TxtNumberListScan.Lines(i). for example, if I select the 5th line in ListTxtDrawR4, I want to display the value of line 5 from TxtNumberListScan in another Textbox. how do I do that?
TxtTop10HighestResult.Text &= Environment.NewLine & TxtNumberListScan.Lines(TxtTop10HighestCount.Lines(0))
TxtTop10HighestResult.Text &= Environment.NewLine & TxtNumberListScan.Lines(TxtTop10HighestCount.Lines(1))
TxtTop10HighestResult.Text &= Environment.NewLine & TxtNumberListScan.Lines(TxtTop10HighestCount.Lines(2))
TxtTop10HighestResult.Text &= Environment.NewLine & TxtNumberListScan.Lines(TxtTop10HighestCount.Lines(3))
TxtTop10HighestResult.Text &= Environment.NewLine & TxtNumberListScan.Lines(TxtTop10HighestCount.Lines(4))
TxtTop10HighestResult.Text &= Environment.NewLine & TxtNumberListScan.Lines(TxtTop10HighestCount.Lines(5))
Names of controls have been changed to protect the innocent. (I watch Dragnet :-)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'This is just some data to test with
Dim A() As String = {"Mathew", "Mark", "Luke", "John"}
Dim B() As String = {"Peter", "Paul", "James", "Judas"}
ListBox1.Items.AddRange(A)
For Each s In B
TextBox1.Text &= s & Environment.NewLine
Next
TextBox1.Text.TrimEnd() 'Remove final new line
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
Dim index As Integer = ListBox1.SelectedIndex
'Check that the index does not exceed the number of lines.
If index < TextBox1.Lines.Count Then
Dim StringToCopy = TextBox1.Lines(index)
TextBox2.Text &= StringToCopy & Environment.NewLine
End If
End Sub

How would I insert items from textbox into listview?

I have a listview with two columns. I also have a textbox. In the textbox, there are lines with strings that I want to insert into the listview.
Every 1st line will be inserted into the first column and every 2nd line will be inserted into the second column. How would I achieve this.
This is my current code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox3.Text = My.Resources.clsid
Dim ListArr(230) As String
Dim i As Integer = 0
For Each line As String In TextBox3.Lines
ListArr(i) = line(i)
i += 1
For Each litem As String In ListArr
AddLitem(litem, litem)
Next
Next
End Sub
Public Function AddLitem(ByVal Desc As String, ByVal CLSID As String)
Dim litem As ListViewItem
If i = 0 Then
Lstr(0) = Desc
i += 1
ElseIf i = 1 Then
Lstr(1) = Desc
litem = New ListViewItem(Lstr)
ListView1.Items.Add(litem)
ListView1.Items.RemoveAt(ListView1.Items.Count)
End If
Lstr(0) = Desc
'Lstr(1) = CLSID
End Function
Note:
You can us Math.Mod to check if you have to handle the first or second row.
For example
0 mod 2 result 0
1 mod 2 result 1
2 mod 2 result 0
3 mod 2 result 1
I use ListView1.Clear to make sure, i'm refilling an empty ListView.
Example Code. This copies all lines from the TextBox1 to the ListView1.
Separeted by a pipe |.
Delete the IIf(String.IsNullOrEmpty(strView2), "", "|") & if you don't want this separation.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim strView1 As String = ""
Dim strView2 As String = ""
For i As Integer = 0 To TextBox1.Lines.Count - 1
If (i Mod 2) Then
strView2 &= IIf(String.IsNullOrEmpty(strView2), "", "|") & TextBox1.Lines(i)
Else
strView1 &= IIf(String.IsNullOrEmpty(strView1), "", "|") & TextBox1.Lines(i)
End If
Next
ListView1.Clear()
ListView1.Items.Add(strView1)
ListView1.Items.Add(strView2)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TextBox1.Text = "cat" & vbCrLf & "street" & vbCrLf & "dog" & vbCrLf & "house" & vbCrLf & "bird" & vbCrLf & "garden"
End Sub
End Class

Backgroundworker doesn't work... VB.Net

this is my code:
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
For i = 0 To 1000
Dim inum As String = i & "0"
Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://www.google.nl/search?q=site:" & combobox1.Text & "&hl=nl&start=" & inum)
Dim response As System.Net.HttpWebResponse = request.GetResponse
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
Dim sourcecode As String = sr.ReadToEnd
Dim search As String = combobox1.Text
Dim r As New System.Text.RegularExpressions.Regex("http://" & search & "/\w*")
Dim matches As MatchCollection = r.Matches(sourcecode)
For Each itemcode As Match In matches
Dim item As String = (itemcode.ToString.Split("""").GetValue(0))
Dim url As New Net.WebClient
Dim str As String = url.DownloadString("http://www.prcheck.nl/results.php?url=" & item)
If str.Contains(">0/10") Then
ListBox1.Items.Add("(0/10) " & item)
ElseIf str.Contains("1/10") Then
ListBox1.Items.Add("(1/10) " & item)
ElseIf str.Contains("2/10") Then
ListBox1.Items.Add("(2/10) " & item)
ElseIf str.Contains("3/10") Then
ListBox1.Items.Add("(3/10) " & item)
ElseIf str.Contains("4/10") Then
ListBox1.Items.Add("(4/10) " & item)
ElseIf str.Contains("5/10") Then
ListBox1.Items.Add("(5/10) " & item)
ElseIf str.Contains("6/10") Then
ListBox1.Items.Add("(6/10) " & item)
ElseIf str.Contains("7/10") Then
ListBox1.Items.Add("(7/10) " & item)
ElseIf str.Contains("8/10") Then
ListBox1.Items.Add("(8/10) " & item)
ElseIf str.Contains("9/10") Then
ListBox1.Items.Add("(9/10) " & item)
ElseIf str.Contains("10/10") Then
ListBox1.Items.Add("(10/10) " & item)
Else
ListBox1.Items.Add("(0/10) " & item)
End If
Label2.Text = ListBox1.Items.Count
Next
If Not sourcecode.Contains("<b>Volgende</b>") Then
MsgBox("")
Exit For
End If
Next
End Sub
and combobox1.text = www.google.nl ( example )
at button 1 the code is:
BackgroundWorker1.RunWorkerAsync()
and if backgroundworker is done:
Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
MsgBox("Done")
End Sub
if i click button 1, i get within a half second the message: Done
what's wrong with the code??
if i put the code inside backgroundworker1 just in button1 it works but goes really slow..
You can only update the UI from within the main application thread, in this case you're attempting to do it via a background thread that has been created by the background worker which will throw an exception as you've found.
What you'll need to do it run the code which adds to the ListBox on the main thread which you can do via BeginInvoke and a custom delegate which takes the item you want to add as a parameter, the delegate can then add the item to list box - there's an example of how to do this in the docs for BeginInvoke.
I would return a list or array of items to be added from the background worker and then fill the ListBox in the RunWorkerCompleted event handler.