הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Wednesday, February 10, 2016 5:32 AM
Console.WriteLine does not work and I dont know why?
All replies (19)
Wednesday, February 10, 2016 10:51 PM ✅Answered
If the project is not a console application, Console.WriteLine will appear in the IDE output window for a class project or form project.
From the IDE menu
Let's say I had the following
Public Sub Method1()
Dim kernel As IKernel = New StandardKernel()
' wire up IData to TestData while next demo uses Entity Framework
kernel.Bind(Of IData)().To(Of TestData)()
' get mocked data
Dim data As IData = kernel.Get(Of IData)()
' show count for each Dictionary
Console.WriteLine($"Classifications {data.Classifications.Count} Endorsement {data.Endorsement.Count} Restrictions {data.Restrictions.Count}")
Console.WriteLine()
' Use UpperDriver rather than Driver (both implement same interface)
kernel.Bind(Of IDriver)().To(Of UpperDriver)() _
.WithConstructorArgument("License", "bm3098") _
.WithConstructorArgument("Classification", "Class C")
' get data
Dim driver As IDriver = kernel.Get(Of IDriver)()
' present data
Console.WriteLine($"Upper Driver data: [{driver.License}] [{driver.Classification}]")
End Sub
I would see
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
VB Forums - moderator
Wednesday, February 10, 2016 6:01 AM | 1 vote
Console.WriteLine does not work and I dont know why?
Hi,
since you dont show any code, we neither.
Regards,
Thorsten
Wednesday, February 10, 2016 6:20 AM
Console.WriteLine does not work
What *exactly* about it "does not work"?
Do you get a build error?
Does it build clean but displays garbage on the console?
Does it build clean but shows nothing on the console?
The more detailed and specific your posts are, the more detailed and specific will be
our replies.
- Wayne
Wednesday, February 10, 2016 7:32 AM
Just a simple guess...are you running a console application? you know one that has only the text interface or a windows form application?
Cyrille Precetti
Wednesday, February 10, 2016 1:13 PM
I don't run the console application and I don't know from where we can run the console application (I only press the right arrow).
Wednesday, February 10, 2016 1:24 PM
There you go... no Console therefore Console.writeline doesn't do anything....
That's not a bug, it's a feature.
Cyrille Precetti
Wednesday, February 10, 2016 1:46 PM
I don't know from where we can run the console application (I only press the right arrow).
You can run a console application exactly the same way. But you haven't stated clearly
yet what kind of application you're building. Which project template did you use when
you created the project?
You haven't given the details I requested. I didn't ask those questions just to exercise
my fingers. What is happening that shouldn't, or what isn't happening that should?
You should also state which version of Visual Studio or Visual Basic you're using.
- Wayne
Wednesday, February 10, 2016 2:16 PM
That is large project and contain many and many icons and menu items and the same Form and I use VB 2008.
Wednesday, February 10, 2016 3:07 PM
That is large project and contain many and many icons and menu items and the same Form and I use VB 2008.
OK. So it is a Windows Forms application then (apparently). So why exactly do you want to
use Console.WriteLine? I presume that your program hasn't attached a console or you would
have seen the output from Console.WriteLine in that console window. What do you want to
accomplish *exactly*? Where were you expecting the output from Console.WriteLine to
appear?
Just calling a method of the Console class won't automatically allocate a console. It
presupposes that a console already exists and that the standard output stream is associated
with that console.
Note that it is possible to attach a console to a WinForms program, if that's what you
really want. See for example the C# example here:
Attaching a Console to a WinForms application
http://www.codeproject.com/Tips/68979/Attaching-a-Console-to-a-WinForms-application
- Wayne
Wednesday, February 10, 2016 3:28 PM
Note that it is possible to attach a console to a WinForms program, if that's what you
really want.
Example:
'Creatss a console in a Basic WinForms app on a button click and displays a message in it
Public Class Form1
Declare Function AllocConsole Lib "kernel32" () As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
AllocConsole()
Console.WriteLine("Hello Mars!")
End Sub
End Class
- Wayne
Wednesday, February 10, 2016 3:29 PM
There is an error in the results and I want to see step by step the output. Below is some code.
Maxvalue = -1000.0
Minvalue = 1000.0
Maxvalue1 = -1000.0
Minvalue1 = 1000.0
For re = 0 To 17
For rw = 1 To 202
If PH(re, rw) <= 179.9999 Then
If re = 0 And rw > 51 Then GoTo 1234
If re = 9 And rw > 51 Then GoTo 1234
If (re > 0 And re < 9 And rw > 101) Or (re > 9 And re < 18 And rw > 101) Then GoTo 1234
If PPPP(re, rw) <= 0 Then
Maxvalue = Math.Max(PPPP(re, rw), Maxvalue)
If PPPP(re, rw) >= Maxvalue Then
MxxcorMax = Mxxx(re, rw)
MyycorMax = Myyy(re, rw)
Console.WriteLine("The value of re is " & re)
Console.WriteLine("The value of rw is " & rw)
Console.WriteLine("The value of MxxcorMax is " & MxxcorMax)
Console.WriteLine("The value of MyycorMax is " & MyycorMax)
Else
End If
Else
Minvalue = Math.Min(PPPP(re, rw), Minvalue)
If PPPP(re, rw) < Minvalue Then
MxxcorMin = Mxxx(re, rw)
MyycorMin = Myyy(re, rw)
Console.WriteLine("The value of MxxcorMin is " & MxxcorMin)
Console.WriteLine("The value of MyycorMin is " & MyycorMin)
Else
End If
End If
Else
End If
1234: 'void
Next
If re = 9 Then
Mxx0(re) = 0.0
Else
Mxx0(re) = (MxxcorMin * (((MxxcorMax * (Minvalue - Maxvalue)) / (MxxcorMin - MxxcorMax)) - Maxvalue)) / ((MxxcorMax * (Minvalue - Maxvalue) / (MxxcorMin - MxxcorMax)) - Maxvalue + Minvalue)
Console.WriteLine("The value of Mxx0(re) is " & Mxx0(re))
End If
If re = 0 Then
Myy0(re) = 0.0
Else
Myy0(re) = (MyycorMin * (((MyycorMax * (Minvalue - Maxvalue)) / (MyycorMin - MyycorMax)) - Maxvalue)) / ((MyycorMax * (Minvalue - Maxvalue) / (MyycorMin - MyycorMax)) - Maxvalue + Minvalue)
Console.WriteLine("The value of Myy0(re) is " & Myy0(re))
End If
Next
For re = 0 To 17
For rw = 1 To 202
If PH(re, rw) >= 180 Then
If re = 0 And rw < 52 Then GoTo 1237
If re = 0 And rw > 102 Then GoTo 1237
If re = 9 And rw < 52 Then GoTo 1237
If re = 9 And rw > 102 Then GoTo 1237
If (re > 0 And re < 9 And rw < 102) Or (re > 9 And re < 18 And rw < 102) Then GoTo 1237
If PPPP(re, rw) <= 0 Then
Maxvalue1 = Math.Max(PPPP(re, rw), Maxvalue1)
If PPPP(re, rw) >= Maxvalue1 Then
MxxcorMax1 = Mxxx(re, rw)
MyycorMax1 = Myyy(re, rw)
Console.WriteLine("The value of re is " & re)
Console.WriteLine("The value of rw is " & rw)
Console.WriteLine("The value of MxxcorMax1 is " & MxxcorMax1)
Console.WriteLine("The value of MyycorMax1 is " & MyycorMax1)
Else
End If
Else
Minvalue1 = Math.Min(PPPP(re, rw), Minvalue1)
If PPPP(re, rw) < Minvalue1 Then
MxxcorMin1 = Mxxx(re, rw)
MyycorMin1 = Myyy(re, rw)
Console.WriteLine("The value of MxxcorMin1 is " & MxxcorMin1)
Console.WriteLine("The value of MyycorMin1 is " & MyycorMin1)
Else
End If
End If
End If
1237: 'void
Next
If re = 9 Then
Mxx0(re + 18) = 0.0
Else
Mxx0(re + 18) = Math.Round((MxxcorMin1 * (((MxxcorMax1 * (Minvalue1 - Maxvalue1)) / (MxxcorMin1 - MxxcorMax1)) - Maxvalue1)) / ((MxxcorMax1 * (Minvalue1 - Maxvalue1) / (MxxcorMin1 - MxxcorMax1)) - Maxvalue1 + Minvalue1), 2)
Console.WriteLine("The value of Mxx0(re+18) is " & Mxx0(re + 18))
End If
If re = 0 Then
Myy0(re + 18) = 0.0
Else
Myy0(re + 18) = Math.Round((MyycorMin1 * (((MyycorMax1 * (Minvalue1 - Maxvalue1)) / (MyycorMin1 - MyycorMax1)) - Maxvalue1)) / ((MyycorMax1 * (Minvalue1 - Maxvalue1) / (MyycorMin1 - MyycorMax1)) - Maxvalue1 + Minvalue1), 2)
Console.WriteLine("The value of Myy0(re+18) is " & Myy0(re + 18))
End If
Next
Wednesday, February 10, 2016 3:59 PM
The output should appear in the VS output window.
You could also try using Debug.Print which should show in the Immediate window.
Wednesday, February 10, 2016 6:42 PM
Is it possible that the Console.WriteLine() is working, but it quickly reverts back to the form before you get a chance to see it? In that case, simply add Console.ReadLine() right after it. Then it will pause to let you see the output before pressing the Enter key to continue.
Solitaire
Wednesday, February 10, 2016 8:04 PM
There is an error in the results and I want to see step by step the output.
Don't use Console.Writeline for this sort of debugging. Insert breakpoints where you currently have the writeline, step through the code, and look at your variables in the Locals window, or add them to the Watch window.
Wednesday, February 10, 2016 10:31 PM
to Dave 299 what is the VS window which will view Console.WriteLine
Wednesday, February 10, 2016 10:45 PM
to Dave 299 what is the VS window which will view Console.WriteLine
As he said: the Output Window.
- Wayne
Wednesday, February 10, 2016 11:07 PM
That is the available window that I have (visual studio 2008) and not like your window.
Wednesday, February 10, 2016 11:12 PM
That is the available window that I have (visual studio 2008) and not like your window.
You're looking at the "Error List" window, not the "Output" window.
- Wayne
Thursday, February 11, 2016 4:36 AM
THANK YOU VERY MUCH