I am creating a for each loop to take the words from a string and place them each into a text box. The program allows for up to "9" variables What I am trying to attempt is.
Foreach word in Words
i = i +1
Varible & i = word
txtCritical1.Text = variable & i
any ideas on a way to make this work?
Have a look through the MSDN article on For Each. It includes a sample using strings.
https://msdn.microsoft.com/en-us/library/5ebk1751.aspx
So i went with a simple if statement this does the trick. Each text box is filled in.
Dim details As String = EditEvent.EditDbTable.Rows(0).Item(13).ToString()
Dim words As String() = details.Split(New Char() {"«"})
Dim word As String
For Each word In words
i = i + 1
v = word
If i = 1 Then
txtCritical1.Text = v
ElseIf i = 2 Then
txtCritical2.Text = v
ElseIf ....
ElseIf i = 9 then
txtCritical2.text = v
Else
....
End If
Next
Related
I have a user form with multiline textbox. EnterKeyBehavior = True. I run the macro, the form opens, I type a few lines of text, pressing Enter after each line. The value from that textbox is put in a variable which is later put in the word document via Find/replace of placeholder text <>.
The text is put in the document and the first line in the multiline textbox entry looks OK, but every other line starts with a little empty box (some Ascii/unicode character I don't know). See pic.
I've tried to replace that little white box by doing a replace on vbCr, vbLf, vbCrLf, Char(10), Char(11), Char(13), from other posts I've found with those solutions, but none of them work for me. What's the fix?
This is what I have in the form right now and from where I'm trying to clean up the contents of that textbox before passing on the value to the variable that I then put in the word document.
Private Sub cmdCompInfoOK_Click()
txtCompanyInfo.Text = Replace(txtCompanyInfo.Text, Chr(11), "")
slkCompanyInfo = frmLtrAddress.txtCompanyInfo
Me.Hide
End Sub
The multiline field is called txtCompanyInfo.
slkCompanyInfo is the variable where I want to put the value from the textbox, and I'm declaring it as Public in the main module, which calls the userform.
Put the following code into a regular module, it will create a string with information about all characters in the input string.
Function DumpString(s As String, Optional specialCharsOnly As Boolean = False) As String
' Write all chars of String as ASCII-Value, concatenated as string
Dim i As Long
For i = 1 To Len(s)
Dim x As String
Dim a As Long, dumpMe As Boolean, c As String
a = AscW(Mid(s, i, 1))
dumpMe = Not specialCharsOnly Or a < 32 Or a > 128
If a = 13 Then
c = "<CR>"
ElseIf a = 10 Then
c = "<LF>"
ElseIf a = 9 Then
c = "<TAB>"
ElseIf a = 0 Then
c = "<NUL>"
Else
c = Mid(s, i, 1)
End If
x = a & "(" & c & ")"
If dumpMe Then
DumpString = DumpString & IIf(DumpString = "", "", ",") & x
End If
Next i
End Function
In your Event-Routine, put a statement like
Debug.Print DumpString(slkCompanyInfo)
If your input string is to long, you can set the 2nd parameter to True, in that case all regular characters are skipped.
Private Async Function cmdList() As Task
Dim m = Context.Message
Dim u = Context.User
Dim g = Context.Guild
Dim c = Context.Client
Dim words As String = ""
Dim embed As New EmbedBuilder With {
.Title = $"Wallpaper keyword list",
.ImageUrl = "https://i.imgur.com/vc241Ku.jpeg",
.Description = "The full list of keywords in our random wallpaper list",
.Color = New Color(masterClass.randomEmbedColor),
.ThumbnailUrl = g.IconUrl,
.Timestamp = Context.Message.Timestamp,
.Footer = New EmbedFooterBuilder With {
.Text = "Keyword Data",
.IconUrl = g.IconUrl
}
}
For Each keyword As String In wall.keywords
words = words + keyword + " **|** "
Next
embed.AddField("Full list", words)
Await m.Channel.SendMessageAsync("", False, embed.Build())
End Function
This is my command to get every word from an array and put it on a field. What I want to know is how do I make it so once the field gets full it'll automatically add a new one and continue with the list. This might be a little far-fetched but just don't know how to go about this. Sorry if I can't understand any of the answers. I'm still a little new to coding on Discord.net and well vb in general.
This is a modification of you hastebin code
Dim row As Integer = 0
Dim words As String = String.Empty
For Each keyword As String In wall.keywords
'If appending the keyword to the list of words exceeds 256
'don't append, but instead add the existing words to a field.
If words.Length + keyword.length + 7 > 256 Then
row += 1
embed.AddField($"List #{row}", words) 'Add words to field
'reset words
words = String.Empty
End If
words = words + keyword + " **|** "
Next
'The add condition within the for loop is only entered when we are
'about to exceed to field length. Anything string under the max
'length would exit the loop without being added. Add it here
embed.AddField($"List #{row + 1}", words)
Await m.Channel.SendMessageAsync("", False, embed.Build())
While it does not change any of the logic, you could consider using a StringBuilder
I'm working on extracting twitter/facebook style mentions from a textbox.
So far, here's my code:
Dim a As String = TextBox1.Text + " "
Dim b As Char() = a.ToCharArray
Dim c As String
Dim l As Integer = TextBox1.Text.Length
Dim temp As Integer = 0
Dim nex As Integer = a.IndexOf(" ")
For i = 0 To l - 1
If b(i) = "#" Then
temp = 1
ElseIf temp = 1 Then
temp = 2
End If
If temp = 2 Then
c = a.Substring(i, nex).Trim() 'nex needs be replaced with next space on 2nd or nth loop
MsgBox(c)
temp = 0
nex = a.IndexOf(" ") + nex
End If
Next
Now this works great if the entered text is- #one #twwo #three. (If
the next strings are greater in length.) But doesn't work elsewhere.
Also, there is probably going to be content between two #mentions so I'm not willing to change the b(i).
I'm sure there's a much more efficient way to do this.
Thanks!!
This is a job for regex. The pattern #\w+ should do nicely.
For Each m As Match In Regex.Matches("#testing this is a #test", "#\w+")
Console.WriteLine(m.Value)
Next
Will print out #testing and #test.
This pattern basically means "Find everything that starts with an '#' followed by one or more 'word characters'."
Regex is a very powerful tool for searching strings, you can read more about it on MSDN.
i have "dictionary.txt" file in which it contains all dictionary words i am trying to syntax highlighting in richtextbox (vb.net) of misspelled word
is there any way to check misspelled words in richtextbox by using dictionary.txt file
i am using for loop and checking each word but its taking too much time
Dim p As Integer = 0
For i = 0 To aryTextFile.Length - 1
aryTextFile(i) = aryTextFile(i).Replace(",", "").Replace(".", "")
If wordslistD.Contains(LCase(aryTextFile(i))) Then
Else
MisSpelledList.Add(aryTextFile(i))
End If
ProgressBar1.Value = p
p = p + 1
Next
did you try Except method? something like:
dim output = aryTextFile.Select(Function(x) x.Replace(",", "").Replace(".", "").ToUpper()).Except(wordsListD)
Ok, so im trying to make this program and i need this:
"Melternet Hello Melternet#gmail.com 5/7/2013" to be in different textbox's like this
"Textbox1 = Melternet"
"Textbox2 = Hello"
"Textbox3 = Melternet#gmail.com"
"Textbox4 = 5/7/2013"
So pretty much every space is a cut off line to add that text to a textbox and then it does the rest like the first one
How would i do something like that, thanks in advance.
Please Answer Back If Anyone Can Figure This Out Or Help Me, NEED THIS QUICK...
BTW: i'm using Visual Basic 2008.
Without more info...something like:
Dim data As String = "Melternet Hello Melternet#gmail.com 5/7/2013"
Dim values() As String = data.Split(" ")
If values.Length >= 4 Then
TextBox1.Text = values(0)
TextBox2.Text = values(1)
TextBox3.Text = values(2)
TextBox4.Text = values(3)
End If
It looks like you are simply splitting the entire input text string: "Melternet Hello Melternet#gmail.com 5/7/2013" wherever a space occurs, yes(?)
If your string has a variable number of words, then fill up textboxes programmatically, like, e.g.:
Dim mystr as String
mystr = "hello world I want to paste this to multiple textboxes"
Dim Buff() as String
Buff = Split(mystr," ")
For i As Integer = 0 to UBound(Buff)
Dim tb As New TextBox
str = Buff(i)
tb.Name = str
tb.Text = str
tb.Left = 50
tb.Top = 50 + 25 * i
tb.Width = 50
tb.TextAlign = HorizontalAlignment.Right
Me.Controls.Add(tb)
Next
In the above fashion, no matter what the value of mystr, or how many words are in the string (mystr), you can write them all to new textboxes that are created/placed dynamically on Form1, i.e. "Me".