I've been trying to find a way to render \r\n as actual newlines in the immediate and command window in my VB.NET 4.5.1 application. I came across this question which teaches about the nq specifier, but it appears to apply only to C#. In VB.NET, nq doesn't even appear to work because I get Expression expected printed back out at me.
Is there a different way to make newlines actually show as separate lines in the immediate or command window in VB.NET?
An easier way in visual studio 2015 is to do this in the debug window:
?string,nq
You can also do the debug version in earlier versions of VS
?System.Diagnostics.Debug.Print(string,nq)
I've discovered that the solution is to use System.Diagnostics.Debug.Print(). To reproduce the original issue, entering this into the Immediate window...
? "a" & vbCrLf & "a"
...just returns this:
"a a"
However, using this...
System.Diagnostics.Debug.Print("a" & vbCrLf & "a")
...actually shows the newline:
a
a
Related
I have some visual basic code where i have a for loop and for company syntax reason, we need to include a _ at the en of the from in line. However, whenever I unfocus from the code, the " _ " gets deleted
I tried messing around in the option under Tools > Options > Text Editor > Basic > advance and unchecking everything but that did not help.
this is the code i want to produce:
Dim burger = (From p In db.PreviousDeclarations _
Where p.burgerID = CompanyID.Value And Object.Equals(p.Year, Year)
This is the code visual studio keep "Correcting" for me:
Dim burger = (From p In db.PreviousDeclarations
Where p.burgerID = CompanyID.Value And Object.Equals(p.Year, Year)
Uncheck Pretty listing (reformatting) of code, located in Options->Text Editor->Basic-> Advanced->Editor Help
Recent versions of Visual Studio will delete the line continuation characters when they're not necessary, typically when the first line alone would not compile on its own but the line below makes it syntactically valid. I know from experience that it's annoying when switching to a new VS that does this, as a small change can easily look like a huge refactoring when doing a diff.
I don't believe there's any way to disable the functionality. If you need them for a company style guideline I suggest you update the guidelines
This is new territory for me, VB and visual studio 2010.. I just need to make one change to a piece of code to improve functionality.
If UCase(dvPlaceDisplayList.Item(i)("PlaceName")) >= UCase(ToolStripTxtFind.Text) Then
The issue I am having is that several place names are prefixed with 'The' ..
I need to change the code to Contains or similar using wildcards
As VB is new to me and googling has not provided any answers...here I am
Thanks
The solution is to use:
If UCase(dvPlaceDisplayList.Item(i)("PlaceName")) LIKE "*" & UCase(ToolStripTxtFind.Text) & "*" Then
I am new in vb 2012 and when I tried to apply VB6 source of the two differ, I've been searching in google how to use this source vb 2012 but I do not find it, anyone there who can help me how to use this source in vb 2012, the following source code is
Dim FileTeks As String
FileTeks = App.Path & "\conn.ini"
UserName = Trim(txtUserName.Text)
Pass = Trim(txtPassword.Text)
Server = Trim(txtServer.Text)
Open FileTeks For Output As #1
Print #1, Enkrip(Server, 4)
Print #1, Enkrip(UserName, 4)
Print #1, Enkrip(Pass, 4)
Close #1
thanks for the help
Here is one way to write to file in .NET
Using sw As New System.IO.StreamWriter("FileTeks.ini", False)
sw.WriteLine(Enkrip(Server,4))
sw.WriteLine(Enkrip(UserName,4))
sr.WriteLine(Enkrip(Pass,4))
sw.Flush()
sw.Close()
End Using
This assumes the output from Enkrip is string. Alternatively (since it is an ini):
sw.WriteLine("{0} = {1}", "Server", Enkrip(Server,4))
' or
sw.WriteLine("{0} {1}", "Server =", Enkrip(Server,4))
You probably need the 'keys' in the clear so you can read them back again rather than encrypting the entire line. Also you probably want to put it all in a Try/Catch so that of the filename is bad or there is an issue with permissions you can trap it.
Another alternative may be to use PInvoke to use the old Win32 Read/WritePrivateProfileString.
HTH
Using the VisualBasic package from .net you should be able to find the most of the VB6 own commands. In any case, vb.net is not a merely upgrade of vb6, it is a quite different language.
If your code base is not too big, I will recommend you to try to refactor your code. We made once one automatic conversion from vb6 to vb.net and now we regret it.
I have a VB.NET application that I run in debug mode.
I have 3 lines
Dim sValue$
sValue = "test"
Debug.Print sValue
When I am not running, I set a breakpoint on the lines sValue = "test", and on the line Debug.Print sValue.
Now when I start debugging, the breakpoint on the line Debug.Print sValue disappears, and the Debug.Print is not performed.
However, the breakpoint on the line sValue = "test" stays there.
Does anybody know what might go wrong here?
Switching from x86 to AnyCPU helped.
Strange.
Community,
Here is another solution for those who are using Visual Studio 2012 (Express) for Desktop. Basically, you will need to import the system diagnostics and include a specific line of code. See below:
Imports System.Diagnostics
'Write Your Code Here
Trace.Listeners.Add(New TextWriterTraceListener(Console.Out))
Debug.Print(Today) 'This will print the date in "Short" form | Carriage Return
Debug.Write(Today) 'This will print the date in "Long" form
Trace.Write(Today) 'This will print the date in "Long" form
That's it. That very first line of code is necessary so that Visual Studio will recognize the Debug & Trace classes. The 2nd line of code is needed so that the window will actually display what you need. The final three lines of code do the exact same thing, essentially.
One more thing, make sure that you are in the Output Window's "Debug" page in order to see the printout!
One last thing, if you are a rookie [like me] please make sure that you hit F5 instead of CTRL+F5 if you want Visual Studio to display "Debug.Print" in your output window.
PS. There was a way to get the output to appear in the Immediate Window; but I changed my settings and now it won't appear. So, if you'd like it there you can tinker around with the options and you'll eventually get it.
When clicking in a specific subroutine in Visual Basic 2010, the application crashes giving only the error message "Microsoft Visual Basic 2010 [Express] has encountered a problem and needs to close."
Nothing appears in the log and safe mode doesn't help.
When I had this problem, I found it was due to a line continuation over 400 lines.
For example:
Dim someString As String
someString = "some text and then a line continuation " & _
"and then some more text for 400 lines " & _
... & _
"and then finish the string"
To fix it, I just had to make my code a little sloppier by combining multiple "lines" on one line.
Hope this helps someone else!
It sounds like you are clicking on a module or a .vb file in the solution space. Try right clicking, then "edit code" if at all possible. If there is an Interop object, perhaps a control (.OCX) that not's registered ion Windows, then VS will crash -- promise!