New Line for Chatbot - vb6

If ChatBot.Caption = ("Bob" & ": " & "Hello! My name is bob. What's your name?") Then
ChatBot.Caption = vbNewLine(Text.Text & ": " & Text.Text)
This is my code so far. How do you add a new line in this case, I've been trying and searching and couldn't find a thing. With every new line from the textbox, it will add a new line to the ChatBot RichTextBox like: "[username]: blah blah".
I've found out that vbCRLF can also make a new line but honestly have no idea where to place it.

For a RichTextBox the best way is to:
'// move cursor to the end of the text
rtb.SelStart = Len(rtb.Text)
'// append the text ending with a new line
rtb.SelText = "Hello" & vbCrLf
A lesser alternative is:
rtb.Text = rtb.Text & vbCrLf & "New Line 1" & vbCrLf & "New Line 2" & vbCrLf & "New Line 3 ..."

Related

How to find string by filter in VBScript?

I have a problem here:
I have an text like this
a lot of html tags
MPI-START
Hello world!
Hello world 2!
MPI-END
a lot of html tags again
And somehow I need to get text between MPI-START and MPI-END
It can contains many lines and text so I need to get them all
I tried to search but there are nothing
Any ideas?
Also sorry for my english, i from Russia
UPD: That text what i needed contains in < p data-placeholder="Your story...">TEXT</ p>
Ok, i found answer
Not perfect but works
Dim strid, outstr
strid = "many hell tags MPI-START" & vbNewLine & "Hello World!" & vbNewLine & "Hello World 2 !" & vbNewLine & "MPI-END there too"
outstr = Split (strid, "MPI-START")(1)
outstr = Split (outstr, "MPI-END")(0)
MsgBox outstr
Here is another approch using RegEx in vbscript to extract data between two delimiters :
Option Explicit
Dim Full_String,First_Delimiter,Second_Delimiter,Extracted_Data
Full_String = "a lot of html tags" & vbNewLine &_
"< p data-placeholder=""Your story..."">" & vbNewLine &_
"Hello world!" & vbNewLine &_
"Hello world 2!" & vbNewLine &_
"</ p>" & vbNewLine &_
"a lot of html tags again"
wscript.echo Full_String
First_Delimiter = "< p data-placeholder=""Your story..."">"
Second_Delimiter = "</ p>"
Extracted_Data = ExtractData(Full_String,First_Delimiter,Second_Delimiter)
wscript.echo Extracted_Data
'------------------------------------------------------------------------------------------------
Function ExtractData(Full_String,Start_Delim,End_Delim)
Dim r,Matches,Data
Set r=new regexp
r.pattern = "(?:^|(?:\r\n))(:?"& Start_Delim &"\r\n)([\s\S]*?)(?:\r\n)(?:"& End_Delim &")"
Set Matches = r.Execute(Full_String)
If Matches.Count > 0 Then Data = Matches(0).SubMatches(1)
ExtractData = Data
End Function
'------------------------------------------------------------------------------------------------

Does VB6 InputBox support a multi-line string?

When using InputBox in Visual Basic 6 can I input a multiline string?
strSrch = InputBox("Enter word(s) or phrase(s), like " & Chr(34) & "Jesus wept" & _
Chr(34) & " to search for any word or phrase" & vbCrLf & _
"If you place & between words the verse must contain both words, loved & world" & _
vbCrLf & "or both phrases, " & Chr(34) & "keep the commandments" & Chr(34) & _
" & " & Chr(34) & "of Jesus" & Chr(34) & vbCrLf & "Put ! in front of a word or phrase to exclude it from your search, Jesus ! testimony" & _
vbCrLf & "Use( before and ) after expressions to group them together, (" & Chr(34) & _
"Come unto me" & Chr(34) & " & all)" & vbCrLf & "Use Xor between two words to include one or the other but not both, " & _
Chr(34) & "I am" & Chr(34) & " Xor that", "Word Search")
No, not really. IIRC, the InputBox should preserve any newline chars that are dropped into it via a paste or entered via ALT+###. But, they will appear as spaces in the box.
It will only ever appear on a single line. There's no real way to use an InputBox to let a user enter multiple lines.
The most feature-capable way to handle this would be to create a custom form and use it to collect user input. You can make it a modal dialog to force the user to interact with it, similar to an InputBox. There are a few ways to pass the input back to the procedure that displayed the form (such as using a global variable).

how to assign XML values to string in Vb6

I want to assign below mentioned xml values to a string like this
Dim test As String
test = ... ?
Where the XML should contain:
<RptVer>1</RptVer>
<RptTyp>1</RptTyp>
</RptInfo>
</InstRptRoot>
How can I do this and also preserve the formatting (ie linebreaks, spacing, etc.)?
Mark answered your question, I'll answer your second question:
Dim test As String
test = "<RptInfo>" & vbCrLf & vbCrLf & _
vbTab & "<RptVer>1</RptVer>" & vbCrLf & vbCrLf & _
vbTab & "<RptTyp>1</RptTyp> & vbCrLf & vbCrLf & _
"</RptInfo>"
Assuming you want it double-spaced and indented. You had also missed the leading tag, but MarkL caught that as well.

Formatting just one line vb6 word 2007 bar code

I am automating a word document with a single table, using vb6. I have the following:
strCellContents = "s " & CStr(oRec("sphBase")) & " c " & CStr(oRec("cylAdd")) & vbCrLf
strCellContents = strCellContents & oRec("Description") & vbCrLf
strCellContents = strCellContents & "1010" & CStr(oRec("RightOPC")) & vbCrLf
strCellContents = strCellContents & "1010" & CStr(oRec("RightOPC")) & vbCrLf
oDoc.Tables(1).Range.ParagraphFormat.SpaceBefore = 6
oDoc.Tables(1).Range.ParagraphFormat.SpaceAfter = 0
oDoc.Tables(1).Range.ParagraphFormat.LineSpacing = InchesToPoints(0.11)
oDoc.Tables(1).Cell(row, col).Range.Text = strCellContents
If Not oRec.EOF Then
oRec.MoveNext
End If
You will note I repeat one of the lines twice, giving me four lines of text in each of 30 cells (3 cols 10 rows). I want the first instance of the repeated line to have a bar code font. How would I go about formatting just that line? I have the bar code font and it is installed.
I found the answer
iNumWords = oDoc.Tables(1).Range.Words.Count
''modify font of bar code (3rd line) - underline for now
For q = 1 To iNumWords
If CStr(oDoc.Tables(1).Range.Words(q)) = strSKU Then
oDoc.Tables(1).Range.Words(q).Font.Underline = wdUnderlineSingle
Exit For
End If
Next

How to use \n new line in VB msgbox() ...?

What is the alternative to \n (for new line) in a MsgBox()?
for VB: vbCrLf or vbNewLine
for VB.NET: Environment.NewLine or vbCrLf or Constants.vbCrLf
Info on VB.NET new line: http://msdn.microsoft.com/en-us/library/system.environment.newline.aspx
The info for Environment.NewLine came from Cody Gray and J Vermeire
Try using vbcrlf for a newline
msgbox "This is how" & vbcrlf & "to get a new line"
These are the character sequences to create a new line:
vbCr is the carriage return (return to line beginning),
vbLf is the line feed (go to next line)
vbCrLf is the carriage return / line feed (similar to pressing Enter)
I prefer vbNewLine as it is system independent (vbCrLf may not be a true new line on some systems)
Use the Environment.NewLine property
Add a vbNewLine as:
"text1" & vbNewLine & "text2"
An alternative to Environment.NewLine is to use :
Regex.Unescape("\n\tHello World\n")
from System.Text.RegularExpressions
This allows you to escape Text without Concatenating strings as you can in C#, C, java
The correct format is :
"text1" + vbNewLine + "text2"
Use the command "vbNewLine"
Example
Hello & vbNewLine & "World"
will show up as
Hello on one line and World on another
You can use Environment.NewLine OR vbCrLF OR vbNewLine
MsgBox($"Hi!{Environment.NewLine}I'M HERE")
You can use carriage return character (Chr(13)), a linefeed character (Chr(10)) also like
MsgBox "Message Name: " & objSymbol1.Name & Chr(13) & "Value of BIT-1: " & (myMessage1.Data(1)) & Chr(13) & "MessageCount: " & ReceiveMessages.Count
Module MyHelpers
<Extension()>
Public Function UnEscape(ByVal aString As String) As String
Return Regex.Unescape(aString)
End Function
End Module
Usage:
console.writeline("Ciao!\n".unEscape)
On my side I created a sub MyMsgBox replacing \n in the prompt by ControlChars.NewLine
A lot of the stuff above didn't work for me.
What did end up working is
Chr(13)
do not forget to set the Multiline property to true in textbox
msgbox("your text here" & Environment.NewLine & "more text") is the easist way. no point in making your code harder or more ocmplicated than you need it to be...
This work for me:
MessageBox.Show("YourString" & vbcrlf & "YourNewLineString")
The message box must end with a text and not with a variable

Resources