I would like to generate a wordlist based on custom chars. right now what I have only display one. how can I make it display all unique combinations?
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim num_letters As Integer = 5
Dim num_words As Integer = 1
Dim letters() As Char = "aeiouykzrsdjlxvn".ToCharArray()
Dim rand As New Random()
For i As Integer = 1 To num_words
Dim word As String = ""
For j As Integer = 1 To num_letters
Dim letter_num As Integer = rand.Next(0,
letters.Length - 1)
word &= letters(letter_num)
Next j
Debug.Print(word)
Next i
End Sub
I created this function to switch between consonants and vowels, never repeat them ... Try it.
Function getName() As String
Dim num_letters As Integer = 5
Dim num_words As Integer = 1
Dim vowel() As Char = "aeiou".ToCharArray()
Dim consonants() As Char = "ykzrsdjlxvn".ToCharArray()
Dim rand As New Random()
Dim word As String = ""
For i As Integer = 1 To num_words
For j As Integer = 1 To num_letters
If j Mod 2 = 0 Then
'CONSONANTS
Dim letter_num As Integer
Do
letter_num = rand.Next(0, consonants.Length - 1)
Loop Until (word.IndexOf(consonants(letter_num)) = -1)
word &= consonants(letter_num)
Else
'VOWEL
Dim letter_num As Integer
Do
letter_num = rand.Next(0, vowel.Length - 1)
Loop Until (word.IndexOf(vowel(letter_num)) = -1)
word &= vowel(letter_num)
End If
Next j
Next i
Return word
End Function
Example of results: esira / edila / oyire / eradi / elijo / olexi / odeka / ovezi / etc...
Related
I want to remove all string except string startwith EVOPB-
how can I make it happen ?
Private Sub StringResult()
Try
Dim web As New HtmlDocument()
web.Load(WebBrowser1.DocumentStream)
'' Extracting All Links
Dim redeem As HtmlNode = web.DocumentNode.SelectSingleNode("//div[#class='_58b7']")
If (redeem.InnerText.Contains("")) Then
Dim r As String = redeem.InnerText.ToString.Replace(vbNewLine, "")
TextBox1.Text = r
End If
Catch
Return
End Try
End Sub
Assuming what you are trying to match always starts with the same prefix and runs until the next space, something like this would work:
Public Shared Function ExtractStartsWith(ByVal Output As String, Optional StartsWith As String = "EVOPB") As List(Of String)
Dim pos As Integer = 0
Dim nextSpace As Integer
Dim results As New List(Of String)
Dim result As String
Do While pos >= 0 AndAlso pos < Output.Length
pos = Output.IndexOf(StartsWith, pos)
If pos >= 0 Then
nextSpace = Output.IndexOf(" ", pos)
If nextSpace > 0 Then
result = Output.Substring(pos, nextSpace - pos)
pos = nextSpace + 1
Else
result = Output.Substring(pos)
pos = Output.Length
End If
results.Add(result)
End If
Loop
Return results
End Function
I have TxtGamblerImput.Text = 2 4 6 8 10 how should that work that code? how can use that code in that textbox?
TextBox4.Text = String.Join(" ", myFirstComb)
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
'This your First Combination, maximal widht = element
Dim Content As String = TxtGamblerImput.Text
'This Your Element
Dim Element As Integer = 5
Dim myFirstComb = (From mVal In Content.ToString.Split() Select Convert.ToInt32(mVal)).ToArray
'This Your Result List
Dim MyList As New List(Of String)
Dim myM As Integer = myFirstComb.Length
Dim myPost = myM
For myCnt = myM To 1 Step -1
Dim LastStr = ""
For mycnt3 = 1 To Element
For myCnt2 = myCnt To myM
'If myCnt2 = myM Then MsgBox("T")
Dim myVal = myFirstComb(myCnt2 - 1)
If myVal > Element Then myVal = 1
If Element - myM + myCnt2 = myVal Then
myFirstComb(myCnt2 - 1) = myVal
Else
If (myVal + 1) > Element Then myVal = 0
myFirstComb(myCnt2 - 1) = myVal + 1
End If
Next
Dim Hsl = String.Join(" ", myFirstComb)
If LastStr <> Hsl Then
MyList.Add(Hsl)
End If
LastStr = Hsl
Next
Next
myFirstComb = (From mVal In Content.ToString.Split() Select Convert.ToInt32(mVal))
TextBox4.Text = String.Join(" ", myFirstComb)
End Sub
In that Output: Show 2 4 6 8 10
I dind't work? How can use that code for worked?
So this morning I ran into a wall:
Using this Code I randomly get another row to show up when i paste my data.
It is meant to receive values ranging from 1 to 99999
So when i copy this:
And paste it into the Program this happens:
Private Sub DataGridView101_KeyDown(sender As Object, e As KeyEventArgs) Handles DataGridView101.KeyDown
If e.Control And
e.KeyCode = Keys.V Then
IsCopyPaste = True
Dim _ClipboardRows As String() = System.Windows.Forms.Clipboard.GetText().Split({System.Environment.NewLine}, StringSplitOptions.None)
Me.DataGridView101.BeginEdit(True)
For Each _ClipboardRow As String In _ClipboardRows
If _ClipboardRow <> "" Then
Dim _CellL As String = ""
Dim _CellR As String = ""
For Each _ClipboardColumn As String In _ClipboardRow.Split(System.Convert.ToChar(vbTab))
If _CellL = "" Then
_CellL = _ClipboardColumn
Else
If _CellR = "" Then
_CellR = _ClipboardColumn
End If
End If
Next
Dim _DataRow As System.Data.DataRow = (CType(Me.DataGridView101.DataSource, System.Data.DataTable)).NewRow()
_DataRow("1") = _CellL
_DataRow("2") = _CellR
CType(Me.DataGridView101.DataSource, System.Data.DataTable).Rows.Add(_DataRow)
End If
Next
Me.DataGridView101.EndEdit()
CType(Me.DataGridView101.DataSource, System.Data.DataTable).AcceptChanges()
IsCopyPaste = False
End If
End Sub
Below is my solution for that. You must call the functions from your event. In my application I need to decide allow pasting or not in the PasteUnboundRecords sub, which is controlled by the Allowed boolen
Public Sub CopyRows(MyDataGridView As DataGridView)
Dim d As DataObject = MyDataGridview.GetClipboardContent()
Try
Clipboard.SetDataObject(d)
Catch
MessageBox.Show("Text not copied, null value")
End Try
End Sub
Sub PasteUnboundRecords(MyDataGridView As DataGridView)
Dim Allowed As Boolean
Dim OriginLines As String() = Clipboard.GetText(TextDataFormat.Text).Split(New String(0) {vbCr & vbLf}, StringSplitOptions.None)
Dim Xo As Integer = SelectedAreaMinColumn(MyDataGridview)
Dim Yo As Integer = SelectedAreaMinRow(MyDataGridview)
Dim X As Integer
Dim Y As Integer
Dim i As Integer
Dim j As Integer
Dim ii As Integer
Dim jj As Integer = 0
Dim m1 As Integer
Dim n1 As Integer = OriginLines.Length
Dim m2 As Integer = SelectedAreaColumns(MyDataGridView)
Dim n2 As Integer = SelectedAreaRows(MyDataGridview)
Dim m2Max As Integer = MyDataGridview.Columns.Count
Dim n2Max As Integer = MyDataGridview.Rows.Count
For j = 0 To Math.Max(n1-1, n2-1)
Y = Yo + j
If Y = n2Max Then Exit For
If j-jj*n1 = n1 Then jj = jj+1
Dim OriginValue As String() = OriginLines(j-jj*n1).Split(New String(0) {vbTab}, StringSplitOptions.None)
m1 = OriginValue.Length
ii = 0
For i = 0 To Math.Max(m1-1, m2-1)
X = Xo + i
If X = m2Max Then Exit For
If i-ii*m1 = m1 Then ii = ii+1
If X > 0 Then 'Avoid pasting in first column containing codes
If Y = 0 Then 'Avoid first line
Allowed = True
Else 'Check DataValidatios
If DataValidations(OriginValue(i-ii*m1), X) = "OK" Then
Allowed = True
Else
Allowed = False
End If
End If
'Avoid pasting in Readonly columns
If MyDataGridview.Rows(Y).Cells(X).ReadOnly Then
Allowed = False
End If
If Allowed Then
MyDataGridview.Rows(Y).Cells(X).Value = OriginValue(i-ii*m1)
End If
End If
End If
Next i
Next j
End Sub
Private Function SelectedAreaMinRow(MyDataGridView As DataGridView) As Integer
Dim minRowIndex As Integer
For i As Integer = 0 To MyDataGridView.SelectedCells.Count - 1
If i = 0 Then
minRowIndex = MyDataGridView.SelectedCells.Item(i).RowIndex
End If
minRowIndex = Math.Min(MyDataGridView.SelectedCells.Item(i).RowIndex, minRowIndex)
Next i
Return minRowIndex
End Function
Private Function SelectedAreaMinColumn(MyDataGridView As DataGridView) As Integer
Dim minColumnIndex As Integer
For i As Integer = 0 To MyDataGridView.SelectedCells.Count - 1
If i = 0 Then
minColumnIndex = MyDataGridView.SelectedCells.Item(i).ColumnIndex
End If
minColumnIndex = Math.Min(MyDataGridView.SelectedCells.Item(i).ColumnIndex, minColumnIndex)
Next i
Return minColumnIndex
End Function
Private Function SelectedAreaRows(MyDataGridView As DataGridView) As Integer
Dim minRowIndex As Integer
Dim MaxRowIndex As Integer
For i As Integer = 0 To MyDataGridView.SelectedCells.Count - 1
If i = 0 Then
minRowIndex = MyDataGridView.SelectedCells.Item(i).RowIndex
MaxRowIndex = MyDataGridView.SelectedCells.Item(i).RowIndex
End If
minRowIndex = Math.Min(MyDataGridView.SelectedCells.Item(i).RowIndex, minRowIndex)
MaxRowIndex = Math.Max(MyDataGridView.SelectedCells.Item(i).RowIndex, MaxRowIndex)
Next i
Return MaxRowIndex-minRowIndex+1
End Function
Private Function SelectedAreaColumns(MyDataGridView As DataGridView) As Integer
Dim minColumnIndex As Integer
Dim MaxColumnIndex As Integer
For i As Integer = 0 To MyDataGridView.SelectedCells.Count - 1
If i = 0 Then
minColumnIndex = MyDataGridView.SelectedCells.Item(i).ColumnIndex
MaxColumnIndex = MyDataGridView.SelectedCells.Item(i).ColumnIndex
End If
minColumnIndex = Math.Min(MyDataGridView.SelectedCells.Item(i).ColumnIndex, minColumnIndex)
MaxColumnIndex = Math.Max(MyDataGridView.SelectedCells.Item(i).ColumnIndex, MaxColumnIndex)
Next i
Return MaxColumnIndex-minColumnIndex+1
End Function
I need to randomize ALL the lines inside a text file and then save the unsorted lines by replacing the same text file.
How I can do all that?
Dim filepath as String = "text_path"
Dim arr() As String = File.ReadAlllines(filepath)
Dim a As Random
Dim b(str.Length) As Integer
Dim result=1, c As Integer
File.Delete(filepath)
Dim f As StreamWriter = File.AppendText(filepath)
For i = 0 To str.Length
while(result)
result = 0
c = a.Next(0, str.Length)
For j = 0 To b.Length
If b(j) = c Then result = 1
Next
end while
f.WriteLine(arr(c))
Next
f.Close()
Another take on it:
Imports System.IO
Module Module1
Sub CreateFile(destFile As String)
Using sw = New StreamWriter(destFile)
For i = 1 To 200
sw.WriteLine("Line " & i.ToString)
Next
End Using
End Sub
Function RandomList(nNumbers As Integer) As List(Of Integer)
' generate a List of numbers from 0..nNumbers-1 in a random order.
Dim ns As New List(Of Integer)
Dim rnd As New Random
For i = 0 To nNumbers - 1
ns.Insert(rnd.Next(0, i + 1), i)
Next
Return ns
End Function
Sub RandomiseFile(srcFile As String)
Dim lines = File.ReadAllLines(srcFile)
Dim nLines = lines.Count
Dim randomNumbers = RandomList(nLines)
' use a temporary file in case something goes wrong so that
' the original file is still there.
Dim tmpFile = Path.GetTempFileName()
' output the lines in a random order.
Using sw = New StreamWriter(tmpFile)
For i = 0 To nLines - 1
sw.WriteLine(lines(randomNumbers(i)))
Next
End Using
File.Delete(srcFile)
File.Move(tmpFile, srcFile)
End Sub
Sub Main()
Dim fileToUse As String = "C:\temp\makerandom.txt"
CreateFile(fileToUse)
RandomiseFile(fileToUse)
End Sub
End Module
Here is my take on it:
Dim linesList As New List(Of String)(IO.File.ReadAllLines("filepath"))
Dim newLinesList As New List(Of String)
Randomize()
While linesList.Count > 0
Dim randomIndex As Integer = Math.Floor(Rnd() * linesList.Count)
newLinesList.Add(linesList(randomIndex))
linesList.RemoveAt(randomIndex)
End While
IO.File.WriteAllLines("filepath", newLinesList.ToArray)
I'm still a student without much experience using vb.net and I am having some trouble splitting a string within an array into 2 values. For example in my textbox I have several lines of measurements that are Length x Width: 20x14, 10x8, 16x13. Each measurement is on its own line. I'm trying to split all Width values that are greater than 12 into 2 separate measurements, so with that last example, I would have 5 measurements (LxW): 20x12, 20x2, 10x8, 16x12, 16x1, then I would like to add these measurements to a new textbox with each measurement on its own line.
Here is the code I have so far. Again, I am very new to programming and this is the first serious project for me since "Hello World", so what I have might be way off. Thanks in advance.
Dim room As String = RoomsTextBox.Text
If room.EndsWith(vbCrLf) Then room = room.Substring(0, room.Length - vbCrLf.Length)
Dim roomarray() As String = room.Split(vbCrLf)
Dim Cuts(roomarray.Length - 1, 0) As String
RoomsTextBox.Select(0, 0)
Dim CutLength As Integer
Dim CutWidth As Integer
Dim i As Integer
Dim j As Integer
CutsTextBox.Select()
Cuts(i, j) = (Val(roomarray(i).Split("x")(0))) & Val(roomarray(j).Split("x")(1))
For i = 0 To Cuts.GetUpperBound(0)
For j = 0 To Cuts.GetUpperBound(1)
Cuts(i, j) = 0
Next
If Val(roomarray(i)) > 12 Then
CutWidth = Val(roomarray(i)) - 12
CutLength = Val(roomarray(j))
Else
CutWidth = Val(roomarray(i))
CutLength = Val(roomarray(j))
End If
Dim inserttext = CutsTextBox.Text
Dim insertposition As Integer = CutsTextBox.SelectionStart
CutsTextBox.Text = CutsTextBox.Text.Insert(0, CutLength.ToString & "x" & _
CutWidth.ToString)
CutsTextBox.SelectionStart = insertposition + inserttext.Length
Next i
I even tried it with inserting the measurements into a ListBox. Here is the code for that:
Dim room As String = RoomsTextBox.Text
Dim roomarray() As String = room.Split(vbCrLf)
Dim Cuts(roomarray.Length - 1, 0) As String
Dim CutLength As Integer
Dim CutWidth As Integer
Dim i As Integer
Dim j As Integer
CutsTextBox.Select()
Cuts(i, j) = (Val(roomarray(i).Split("x")(0))) & Val(roomarray(j).Split("x")(1))
For i = 0 To Cuts.GetUpperBound(0)
For j = 0 To Cuts.GetUpperBound(1)
Cuts(i, j) = 0
Next
If Val(roomarray(i)) > 12 Then
CutWidth = Val(roomarray(i)) - 12
CutLength = Val(roomarray(j))
Else
CutWidth = Val(roomarray(i))
CutLength = Val(roomarray(j))
End If
ListBox1.Items.Add(CutLength.ToString & "x" & CutWidth.ToString)
Next i
Try this out.
Dim dimensions As String() = txtInput.Text.Split(vbCrLf)
Dim final As New List(Of String)
For Each item In dimensions
Dim lw As String() = item.Split("x")
Dim length As String = lw(0)
Dim width As Integer = CInt(lw(1))
If width > 12 Then
Dim new1 As String
Dim new2 As String
new1 = length & "x" & (width - 12).ToString
new2 = length & "x12"
final.Add(new1)
final.Add(new2)
Else
final.Add(item)
End If
Next
For Each item In final
txtOutPut.Text += item & vbCrLf
Next