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
Related
After much trial and error ,and with assistance from the community, the ability to use Unicode in a form has not been very successful. So the question is. Is there a method to have the ability to use Unicode within a form ? primarily in textbox control were a currency symbol like the Peso symbol(₱) will appear in a textbox. there are various ways to have it on a worksheet but in a form is an allusive task.
After much trial and error ,and with assistance from the community, the ability to use Unicode in a form has not been very successful.
Says who? :)
Private Sub UserForm_Initialize()
TextBox1.Text = ChrW(8369)
End Sub
And welcome to stackoverflow :)
Among other methods, you could:
copy & paste Unicode into a textbox, or,
or use ChrW to use a specific character like this:
UserForm1.TextBox1 = ChrW(8369) 'puts a ₱ in the text box.
Note that in most cases the VBA Editor (VBE) won't display Unicode (so copy/pasting the above code into your VBE will replace the ₱ with a ?).
By the way CodePoints is a handy site for finding/identifying unicode symbols. Type whatever you're looking for in the search bar, or copy & paste from a website to find out more.
Also, note that all symbols that appear on your system may or or may not render properly on others.
Today I wanted to add an option to 100 or so columns in several DataGridView collections. I figured I could manually edit the Form's Designer.vb file to copy and paste the option in, but I quickly realized that this would not be an easy task since the option contained the name of the column, so it wasn't something I could just paste in.
I opted to change the code to use With/End With, but after doing so, I got a boatload of errors in the Designer that said "The variable 'VB$t_ref$L0' is either undeclared or was never assigned (that is, from L0 to L99). I did some research and learned that this variable isn't something I'll find in my VB code, but is actually the compiled version of it.
Here's the Before code:
Me.DataMatchesHomePlayerID.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells
Me.DataMatchesHomePlayerID.HeaderText = "Home Player ID"
Me.DataMatchesHomePlayerID.Name = "DataMatchesHomePlayerID"
Me.DataMatchesHomePlayerID.Width = 144
Here's the After code:
With Me.DataMatchesHomePlayerID
.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells
.HeaderText = "Home Player ID"
.Name = "DataMatchesHomePlayerID"
.Width = 144
End With
What I don't understand is why this didn't work. Shouldn't I be able to use With/End With in Designer.vb? If it helps, the line I added was the first one (.AutoSizeMode).
Let me know if you need additional information to help me resolve this. I really just need to know if it's okay to finish converting all the code in Designer.vb to use With/End With.
Thanks!
I heeded Plutonix' advice and removed the With/End With's from the Designer.vb file.
Kudos also to Luke who provided some interesting insights as to why this is the case!
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?
Okay, I am a Javascript programmer and VBA is driving me insane - I know nothing about it and it is like pulling teeth to find simple documentation on the simplest thing.
I'm literally trying to run a little script to auto-format a document, partly based in content.
I want to grab the third line of document, or first 100 characters, I really don't care, and run the equivalent of String().indexOf('foobar') on it, to check if that part of the document contains a string.
I cannot for the life of me find how to:
a. Load text selection into a variable.
b. Run a sane semblance to indexOf.
Can someone please help? And maybe point me to a sane VBA documentation that is not Micrsoft?
a. Load text selection into a variable.
Identify a range (Word.Range) you want and get the Text property of that range.
For instance,
dim s as string
s = ThisDocument.Paragraphs(3).Range.Text
b. Run a sane semblance to indexOf.
Is InStr no good?
msgbox InStr(s, "foobar")
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.