For loop not outputting properly when using arrays - vb.net

I would expect this code when run to output the first line of the array, pause, then output the second line in the array, each line being output with a delay between each character but for some reason it isn't working for me.
Dim IntroText(4) As String
IntroText(0) = "Konrad Czajkowski..."
IntroText(1) = "...Presents"
IntroText(2) = "...A text based game..."
IntroText(3) = "...The Legend of Konrad and The Quest for Skairum"
Dim IntroTextLength As Integer = Nothing
IntroTextLength = IntroText(IntroText.Length - 1)
For IntroCounter1 = 0 To IntroTextLength
For IntroCounter2 = 0 To IntroText(IntroCounter1).Length - 1
Console.Write(IntroText(IntroTextLength)(IntroCounter2))
Threading.Thread.Sleep(50)
Next
Threading.Thread.Sleep(5000)
Console.Clear()
Next
Console.Clear()
P.s I'm using a console application in VB.NET

Try this.
Dim IntroText(4) As String
IntroText(0) = "Konrad Czajkowski..."
IntroText(1) = "...Presents"
IntroText(2) = "...A text based game..."
IntroText(3) = "...The Legend of Konrad and The Quest for Skairum"
Dim IntroTextLength As Integer = Nothing
IntroTextLength = IntroText.Length - 1
For IntroCounter1 = 0 To IntroTextLength - 1
For IntroCounter2 = 0 To IntroText(IntroCounter1).Length - 1
Console.Write(IntroText(IntroCounter1)(IntroCounter2))
'Console.Write(IntroTextLength)
Threading.Thread.Sleep(50)
Next
Threading.Thread.Sleep(500)
Console.Clear()
Next
Console.Clear()

Related

trying to add a graph through txt file on visual basic

as of now I have been able to get the data to come in and the graph portion set up. The issue is trying to use 2 separate array variables. I am using stream reader. I can not get my command in the loop where it will put all my plots in together. The values in my text file are comma separated and are as follows:
220,92,83,74,65,56,47,38,29,102
dim line (9) as string
for I as Integer = 0 To 9
using reader as StreamReader = New StreamReader("c:\New Folders\graph\small Graph.txt")
line = reader.ReadLine.Split(",")
end using
console.WriteLine(line)
console.Read()
Chart1.Titles.Add("Spectrum")
Chart1.chartAreas.Add("Default")
with chart1.chartareas("Default")
.AxisX.Title = "Channel"
.AxisY.Title = "Counts"
.AxisX. MajorGrid.LineColor = Color.AliceBlue
.AxisY. MajorGrid.LineColor = Color.AliceBlue
end with
chart1.Series.Clear()
chart1.Series.Add("file")
chart1.Series("file").color = Color.Red
chart1.Series("file").ChartType = DataVisualization.Charting.SeriesChartType.Line
Dim n As Integer
n = 10
Dim y as single
Continue For x = 0 To n Step 1
y = line(i)
Chart1.Series("file").Points.AddXY(x, y)
next
`

How to remove vb.net Richtextbox lines that not contains specific words

Hi there im trying to get specific words from a html web page and im trying to do this by loading the html sourcecode into a textbox and then filter it out.
Im now using this wich is stupid i know but how can i fuse both together that it will check both words in 1 loop?
Dim Filter1 = "filterword1"
Dim Filter2 = "filterword2"
TextBox1.Text = WebBrowser1.DocumentText
TextBox2.Text = WebBrowser1.DocumentText
Dim lines As New List(Of String)
lines = TextBox1.Lines.ToList
For i As Integer = lines.Count - 1 To 0 Step -1
If Not Regex.IsMatch(lines(i), Filter1) Then
lines.RemoveAt(i)
End If
Next
TextBox1.Lines = lines.ToArray
Dim lines1 As New List(Of String)
lines1 = TextBox3.Lines.ToList
For i As Integer = lines1.Count - 1 To 0 Step -1
If Not Regex.IsMatch(lines1(i), Filter2) Then
lines1.RemoveAt(i)
End If
Next
TextBox1.Lines = lines1.ToArray
I got it working :
Const filter = "(Filterword1)|(Filterword2)|(Filterword3)|(Filterword4)"
Dim lines As New List(Of String)
lines = TextBox2.Lines.ToList
For i As Integer = lines.Count - 1 To 0 Step -1
If Not Regex.IsMatch(lines(i), filter) Then
lines.RemoveAt(i)
End If
Next

how to execute for loop for items checked in 3 checkedlistbox

i made a report for taking output of employees in a company.i made a code for that.but it only show the first items checked.how to impliment for loop in this.
Dim i As Integer
Dim j As Integer
Dim k As Integer
For i = 0 To Employee_Bank_dtl.CheckedListBox1.Items.Count - 1 Step i + 1
If Employee_Bank_dtl.CheckedListBox1.GetItemCheckState(i) = CheckState.Checked Then
Dim xx As String = (CType(Employee_Bank_dtl.CheckedListBox1.Items(i), DataRowView))("VC_BRNAME")
For j = 0 To Employee_Bank_dtl.CheckedListBox2.Items.Count - 1 Step j + 1
If Employee_Bank_dtl.CheckedListBox2.GetItemCheckState(j) = CheckState.Checked Then
Dim yy As String = (CType(Employee_Bank_dtl.CheckedListBox2.Items(j), DataRowView))("vc_empstatus")
For k = 0 To Employee_Bank_dtl.CheckedListBox3.Items.Count - 1 Step k + 1
If Employee_Bank_dtl.CheckedListBox3.GetItemCheckState(k) = CheckState.Checked Then
Dim zz As String = (CType(Employee_Bank_dtl.CheckedListBox3.Items(k), DataRowView))("vc_value")
Dim str = "xxxxxxxxxxxxxx"
conobj.readdata(str)
conobj._adpt.Fill(Me.DataSet10.BRANCH_MAST)
Me.ReportViewer1.RefreshReport()
End If
Next
End If
Next
End If
Next i
You should increment through the collection of items like this not the way you are doing it. You should be able to find the properties you are looking for. Set a break point within the inner loop and right click on quickwatch on the item and you will see all the properties of that item which will contain what your looking for.
For Each item In CheckedListBox1.Items
'set the item property to the right property that holds "VC_BRNAME"
If item.property = "VC_BRNAME" Then
End If
If item.checkstate.checked = True Then
End If
Next
Its my mistake replacing k + 1 to +1 in the 3rd loop will got the right answer

random number in multi threading not working

please examine my code below :
Public Class tier1
Dim rnd As New System.Random()
Function build1(ByVal dt As DataTable) As String
Try
For i = 0 To 4
For ix As Integer = 0 To till Step 4
lstrn.Add(rnd.Next(ix, ix + 4))
Next
Dim cntx As Integer = 0
For Each x As Integer In lstrn
If (i = 0) Then
If (article(x).Split(ChrW(10)).Length > 2) Then
If (article(x).Split(ChrW(10))(0).Length > 300) Then
first.Add(article(x).Split(ChrW(10))(0))
cntx = cntx + 1
If (cntx = 25) Then
Exit For
End If
End If
End If
End If
lstrn.Clear()
Next
Dim fi as String = "{"
For dx As Integer = 0 To first.Count - 2
fi = fi & w.spinl(first(dx), "light") & "|"
Next
fi = fi & "}"
Return fi
Catch ex As Exception
End Try
End Function
End Class
Now see my calling code :
Dim w As WaitCallback = New WaitCallback(AddressOf beginscn)
For var As Integer = 1 To NumericUpDown1.Value
Dim param(1) As Object
param(0) = lst
param(1) = var
ThreadPool.QueueUserWorkItem(w, param)
Next
sub
sub beginscn()
Dim scntxt As String = t1.buildtier1(dt)
end sub
Now understand what i give and what i want. Suppose i pass a datatable like this :
1,abcd,34,5
2,adfg,34,5
3,fhjrt,34,5
4,rtitk,34,5
What i want is {abcd|adfg|fhjrt|rtitk} and this sequence should be random everytime. Since i pass like 50-100 values and exit loop at 25 each output should have a different sequence of 25 strings in {|} format but it does not work like that. Everytime i get same sequence.
Can anyone explain why does it do like that and any possible solution for this problem?
Note : I have already tried shuffling datatable just before queuing it but still it does not work.
The random object is not thread safe. You could work around this by creating separate instances of the random object in each thread and use the thread ID to generate the
seed.
http://msdn.microsoft.com/en-us/library/ms683183%28VS.85%29.aspx

Error on inserting new line on gridview

I am trying to add a new row into a gridview but for some reason i'm having a problem in the for loop.
Directly goes to dtCurrentTable.Rows.Add(drCurrentRow) and of course, have an error "'row' argument cannot be null.Parameter name: row", because the dtcurrentTable.NewRow was not executed.
Why is this happening?
Private Sub AddNewRowToGrid()
Dim rowIndex As Integer = 0
If Not IsNothing(ViewState("CurrentTable")) Then
Dim dtCurrentTable As DataTable = CType(ViewState("CurrentTable"), DataTable)
Dim drCurrentRow As DataRow = Nothing
If dtCurrentTable.Rows.Count > 0 Then
For i as Integer = 1 To i <= dtCurrentTable.Rows.Count
' Extraem-se os valores das Textbox
Dim box1 As TextBox = Dados.Rows(rowIndex).Cells(0).FindControl("Artigo")
Dim box2 As TextBox = Dados.Rows(rowIndex).Cells(1).FindControl("Descricao")
Dim box3 As TextBox = Dados.Rows(rowIndex).Cells(2).FindControl("IVA")
Dim box4 As TextBox = Dados.Rows(rowIndex).Cells(3).FindControl("PU")
Dim box5 As TextBox = Dados.Rows(rowIndex).Cells(4).FindControl("Desconto")
Dim box6 As TextBox = Dados.Rows(rowIndex).Cells(5).FindControl("UN")
Dim box7 As TextBox = Dados.Rows(rowIndex).Cells(6).FindControl("Quantidade")
Dim box8 As TextBox = Dados.Rows(rowIndex).Cells(7).FindControl("TotalLiquido")
drCurrentRow = dtCurrentTable.NewRow
dtCurrentTable.Rows(i - 1)("Artigo") = box1.Text
dtCurrentTable.Rows(i - 1)("Descricao") = box2.Text
dtCurrentTable.Rows(i - 1)("IVA") = box3.Text
dtCurrentTable.Rows(i - 1)("PU") = box4.Text
dtCurrentTable.Rows(i - 1)("Desconto") = box5.Text
dtCurrentTable.Rows(i - 1)("UN") = box6.Text
dtCurrentTable.Rows(i - 1)("Quantidade") = box7.Text
dtCurrentTable.Rows(i - 1)("TotalLiquido") = box8.Text
rowIndex += 1
Next i
dtCurrentTable.Rows.Add(drCurrentRow)
ViewState("CurrentTable") = dtCurrentTable
Dados.DataSource = dtCurrentTable
Dados.DataBind()
End If
Else
Response.Write("ViewState null")
End If
SetPreviousData()
End Sub
Your For loop is defined wrong, thats why you're getting an error:
For i as Integer = 1 To i <= dtCurrentTable.Rows.Count
evaluates to
For i as Integer = 1 To True
(because i is always <= Rows.Count)
which VB translates as
For i as Integer = 1 To -1
which means your loop never runs.
It
should be
For i as Integer = 1 To dtCurrentTable.Rows.Count
Also, there's something odd about the way you use drCurrentRow = dtCurrentTable.NewRow. Why is that inside the loop when you don't do anything with it in the loop? It gets executed multiple times and then dtCurrentTable.Rows.Add(drCurrentRow) only gets called once.
Its hard for me to correct because I can't figure out what you're trying to do, but that bit looks dodgy to me.