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.
Related
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?
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
Ok this is a spin on a question I asked before, although i dont think I was clear enough in my explanation. My example strings are as follows.
06:15:34GET/a/users/23/list_messageHTTP
06:15:35PUT/a/users/231223/badge?HTTP
06:15:36POST/a/users/4454?set_action
I am trying to search for example "POST/a/users/" or "GET/a/users/" then find the next special character after the number/integers. So for the last example you can see there is ?, that is what im trying to locate to enable me to put a vbtab before it.
I can for instance find the 4th / in a line and put a vbtab before it but not find a string then find the next special character after it.
Any help is gratefully received, many thanks VBVirg
I have a spreadsheet that I have imported from one of our sites that we use for User Access. I am having trouble in the formatting of the spreadsheet in order to make it searchable and to use VLOOKUP. In the Full Name column, the first and last name look like they are separated by a space " " but it does not work that way when I try to split them into First Name and Last Name columns. It is almost like it is a fake space. I have tried many ways to make it a true space between the words but nothing has worked and none of my researching to find a solution to this problem has been found. Can anyone help me with figuring this out so I don't have to continue to delete the "fake space" and add a real space between the words?
Any help is much appreciated.
These are non-breaking spaces. I am guessing that this data is coming from an HTML source.
You can get your formulas to work by changing " " to CHAR(160), which will return the non-breaking space (ASCII code 160).
EDIT: Accepted answer points out what my issue was. I added another answer which shows an even easier way.
I have a multiline textbox from which I create a single string:
Dim wholeThing As String
Dim line as String
For Each line In txtMultiline.Lines
wholeThing = wholeThing & line & Environment.Newline
Next
What I'd like to do is write this to a DB as-is by adding wholeThing as a parameter using to SqlCommand.Parameters.AddWithValue, but all of my painstakingly-inserted newlines go away (or appear to).
I saw this and was hoping I didn't need to concern myself with CHAR(nnn) SQL stuff.
Any suggestions? Thanks!
What do you mean when you say "appears to"? A newline character can be easily stored in an nvarchar field. What tools are you using to verify the results of your actions?
It's even easier than this. As per the discussion in the accepted answer, I wasn't seeing all of the lines in my view. Putting up a messagebox showed everything.
What's more, I don't need to take things line by line:
wholeThing = txtMultiline.Text
works, too, and it keeps all of the line breaks.