How to keep all webclient text in one line in Skype? - vb.net

I'm having a issue with visual basic 2012 Webclients. I'm trying to gather information from a website. Then upload it to a Skype chat. On the website, the text goes in separate lines. Example:
Hello.
How Are You?
Good Thanks.
When I run the application, it displays the text in a odd way. It displays it like this:
<br>Hello<br>how are you&<br><br>good<br>
Here is the code. (This project is based around a Skype Bot, So I will need to blank out the api for this.)
ElseIf msg.StartsWith("cloudflare ") Then
c.SendMessage("SkypeBot >" + vbNewLine +
("" + New WebClient().DownloadStringTaskAsync("api" & msg.Replace("cloudflare ", ""))))
The issue is based around .DownloadStringTaskAsync I believe. Help with this issue will be highly appreciated.
EDIT: I also know about "You need to use HTML on a web page to get line breaks. For example "" will give you a line break."
but I'm unsure where to insert it and how to use it in that code.

My VB.NET knowledge is a little rusty, but can you not use something like this (C# code):
string[] arrayOfText = welcomeText.split("<br>");
Then you can do whatever you want with the text. Stick it back together, but with spaces instead of < br>
Alternatively you could use the .replace function?

Related

Unwanted Linebreak in VBA-Variable

I'm pretty much a newbie to VBA and Access and I start to get kinda frustrated.
I'm working on a program for calculating prizes and therefor I got HTML-Datas with the necessary informations which get split up as following:
strHTML = GetHTML(HTML)
List() = Split(strHTML, Chr(10))
Just to make it clear, the HTML lines I pick up for this look as following:
Motortyp=SM132
Motortypreihe=SM
MotorBG=132
MotorFE=35
MotorZusatz1=B
MotorZusatz2=
ReglerTyp=Fremdregler
So far so good.
The whole gear description (e.g. "SM200.15C") is taken at once and somehow there still is kind of a line break afterwards which leads to me not being able to use it in queries as I want to.
It seems like the line break at which I split up the HTML somehow is still present and it just don't want to get replaced by stuff like Replace([Data], Chr(10). "").
Hope the question was Kind of understandable since I got a few brain lags today.
Thanks in advance,
Dennis
On Windows a newline is obtained from the combination of a carriage return Chr(13) and linefeed Chr(10) characters. Use
List() = Split(strHTML, vbCrLf)
where vbCrLf is a VB constant representing this pair of characters.

How to use multiple textbox entries in part of a url in vb?

I'm making a visual basic program, and I'm trying to make a button go to a link, but two parts of the link need to come from text boxes. I know how to make it go to the url in the text box entry, but I need to know how to make it go to a preset url, only with two parts of the url coming from text box entries.
I tried ("example.com/test?ex="(TextBox1.Text)"?nl="(TextBox2.Text))
and that didn't work. Please help
Thanks!
Process.Start("example.com/test?ex=" & TextBox1.Text & "?nl=" & TextBox2.Text)
Or, in Visual Studio 2015 you can use Interpolated Strings:
Process.Start($"example.com/test?ex={TextBox1.Text}?nl={TextBox2.Text}")
String.Format version.
Process.Start(String.Format("example.com/test?ex={0}?nl={1}",TextBox1.Text,TextBox2.Text))

Embed console in form

TL;DR:
Is there a way to embed a console inside a form, so it becomes a part of it?
Scenario:
I am writing a chat-application with client, server and database using Windows Forms in VB.NET. The server should log all communication it has with clients in a textbox.
The Problem:
So far that would not be a problem - If there wasn't a maxlength for strings! I expect this server to almost never stop (Okay, there is always some point where it does.. but lets ignore that). So if i go for Textbox1.Text &= vbnewline & "Something" it will some day reach this length and run into an exception each time something is about to be logged. I also don't want to just remove the first characters of the string.
My Idea for a solution:
My idea for a work around: Use a console instead of a simple textbox and embed it into the form, so it becomes a part of it. Is there a simple way to do that? By simple I mean that I should have to write thousands of lines of code to achieve that goal.
I am open minded for different ideas and ways to do so as well.
Why not just log your chat to file (you could create a file per day)?
Dim filename = String.Format("C:\Temp\{0:yyyy-MM-dd}-log.txt", DateTime.Now)
My.Computer.FileSystem.WriteAllText(filename, "line of text", True)
Then to display it - use a ListBox and append each new line to the end of the listbox? Each time you append, you could check how many items are in the listbox and remove the first 100 if you are over 1000 as an example.

Force text onto next line

I have a text file with data pieced together needs to be separated onto separate lines. Not sure how to go about doing it, still new to vb.
I'm thinking about something along the lines of:
If sLine.EndsWith(", ") Then
"Do Something"
End If
So for anyone wondering if they come across this post, I'm new to vb.net so I'm still discovering all sorts of tricks to the language. One such "trick" resolved this issue, and that is that you can use the carriage return from VB6 (vbCr). This separated all of the criteria I needed set to the next line, thus, resolving the issue for me.
So this line of code:
subchild = subchild.Replace(", '", vbCr)
Would turn this:
ABCDEFG, HIJKLMN, OPQRSTU
Into this:
ABCDEFG
HIJKLMN
OPQRSTU

VB.NET IDE: Refresh code lines

I am using the Find & Replace function frequently, and I don't care about the case.
So I am replacing e. g.
"Dim s As String = SomeFunc(SomeArg)"
with
"dim s as string = somenewfunc(somearg)"
The IDE replaces it fine, but it uses my lower case typing.
Only when I change something in that line (for example by adding a space at the end of the line)
"dim s as string = somenewfunc(somearg)"
, it becomes
"Dim s As String = SomeNewFunc(SomeArg)"
as it should be.
Does anybody know some magic way to refresh all my lines of code?
Clean and Rebuild did not help me.
Thank you!
A few options:
When you do your replace use the proper case.
You could also do Format Document. Edit --> Advanced --> Format Document or Ctrl E, D But this will only do the current document. Not sure if this will fix your case in the document. Maybe there is a way to do this to all documents, I am not sure. I imagine resharper can do this with code cleanup.
You might want to look at the advice from this link:
How to format all files in Visual Studio 2012?
See Jay Bazuzi's answer.
You will want to tweak his code to use .vb instead of .cs