Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 如何在VisualBasic控制台应用程序中使输出跨越终端窗口的整个宽度?_Vb.net_Console Application - Fatal编程技术网

Vb.net 如何在VisualBasic控制台应用程序中使输出跨越终端窗口的整个宽度?

Vb.net 如何在VisualBasic控制台应用程序中使输出跨越终端窗口的整个宽度?,vb.net,console-application,Vb.net,Console Application,这可能吗?它可以通过使用某种函数来实现。我所能找到的只是有关如何在visual basic windows窗体应用程序中使输出跨越文本框宽度的示例 我的代码如下 Sub Main() Dim usrnum(1), usramount, userchoice, count, result2 As Integer Dim totalstars(1), question1, userchoice2, nchrt, result1 As String Do Until ques

这可能吗?它可以通过使用某种函数来实现。我所能找到的只是有关如何在visual basic windows窗体应用程序中使输出跨越文本框宽度的示例

我的代码如下

Sub Main()
    Dim usrnum(1), usramount, userchoice, count, result2 As Integer
    Dim totalstars(1), question1, userchoice2, nchrt, result1 As String

    Do Until question1 = "y"
        userchoice = 0
        Do Until userchoice = 1 Or userchoice = 2
            'menu - text tries to be as specific as possible to prevent an incorrect input from the user




            WriteLine("-------------------   Bar chart creator!  ---------------------")
            WriteLine("                                                               ")
            WriteLine("                                                               ")

            WriteLine("===============================================================")
            WriteLine("**************************   MENU   ***************************")
            WriteLine("===============================================================")
            WriteLine("                                                               ")
            ForegroundColor = ConsoleColor.Cyan
            WriteLine("   1 - To begin                                                ")
            ForegroundColor = ConsoleColor.Yellow
            WriteLine("   2 - To exit                                                 ")
            WriteLine("                                                               ")
            WriteLine("                                                               ")
            WriteLine("                                                               ")
            WriteLine("                                                               ")


            'reads in data from the user from the menu
            Try
                userchoice = ReadLine()
                Clear()
            Catch ex As Exception
                'if this produces an error, for example a string is entered by the user then the following message will be issued to the user
                WriteLine("That value is unknown!")
                WriteLine("Please enter an Integer only")
            End Try
            If userchoice = 1 Then
                WriteLine("What would you like to name your bar chart as?")
                nchrt = ReadLine()
                Clear()
                WriteLine("Enter the amount of values you want to enter.")
                Try
                    usramount = ReadLine()
                Catch ex As Exception
                    'if this produces an error, for example a string is entered by the user then the following message will be issued to the user                   
                    WriteLine("That value is unknown!")
                    WriteLine("Please enter an Integer only: ")
                End Try
                Clear()
                WriteLine("Values for the chart " & nchrt)
                WriteLine("")
                WriteLine("Please note! Each * Is equal To 100.  Once a value reaches over 1000 the maxium amount Of * shown Is 10")
                WriteLine("")
                ReDim usrnum(usramount) 're-assign the users input as the value for the arraysize
                ReDim totalstars(usramount)
                count = 0
                'the count allows the user to see what how many values they have entered so far and what number they are currently on
                While count < usramount
                    For i As Integer = 0 To usrnum.Length - 1
                        'allows the users numbers to be recorded into the array
                        WriteLine("Please enter value " & count & "  And <press> enter")
                        Try
                            usrnum(i) = ReadLine()
                            count = count + 1
                        Catch ex As Exception
                            'if this produces an error, for example a string is entered by the user then the following message will be issued to the user
                            WriteLine("That value is unknown!")
                            WriteLine("Please enter an Integer only.")
                            ReadLine()
                        End Try
                        Clear()
                    Next i
                End While
                'Calulates how many * to display with an IF statement 
                For i As Integer = 0 To totalstars.Length - 1
                    If usrnum(i) > 1000 Then
                        totalstars(i) = (" * " & " * " & " * " & " * " & " * " & " * " & " * " & " * " & " * " & " * ")
                        'This was where my function was supposed to work but I can't get it to work the way I wanted it to
                        'These commented out if statements would have checked to see if the usrnum(i) current value was the biggest in relation to the output of the function max()
                        'If the current value of usrnum(i) was equal to the biggest value output by max() then extra spacing would be added between the stars so that they would span the width of the console window
                        'Else
                        'If usrnum(i) > 1000 And usrnum(i) = Max(usrnum(usramount)) Then
                        'totalstars(i) = ("    *  " & "    *  " & "    *  " & "    *  " & "    *  " & "    *  " & "    *  " & "    *  " & "    *  " & "    *  ")
                    Else
                        If usrnum(i) >= 900 And usrnum(i) < 1000 Then
                            totalstars(i) = (" * " & " * " & " * " & " * " & " * " & " * " & " * " & " * " & " * ")
                            'Else
                            'If usrnum(i) >= 900 And usrnum(i) < 1000 And usrnum(i) = Max(usrnum(usramount)) Then
                            'totalstars(i) = ("    *  " & "    *  " & "    *  " & "    *  " & "    *  " & "    *  " & "    *  " & "    *  " & "    *  " & "    *  ")
                        Else
                            If usrnum(i) >= 800 And usrnum(i) < 900 Then
                                totalstars(i) = (" * " & " * " & " * " & " * " & " * " & " * " & " * " & " * ")
                                'Else
                                'If usrnum(i) >= 800 And usrnum(i) < 900 And usrnum(i) = Max(usrnum(usramount)) Then
                                'totalstars(i) = ("    *  " & "    *  " & "    *  " & "    *  " & "    *  " & "    *  " & "    *  " & "    *   ")
                            Else
                                If usrnum(i) >= 700 And usrnum(i) < 800 Then
                                    totalstars(i) = (" * " & " * " & " * " & " * " & " * " & " * " & " * ")
                                    'Else
                                    'If usrnum(i) >= 700 And usrnum(i) < 800 And usrnum(i) = Max(usrnum(usramount)) Then
                                    'totalstars(i) = ("    *  " & "    *  " & "    *  " & "    *  " & "    *  " & "    *  " & "    *  ")

                                Else
                                    If usrnum(i) >= 600 And usrnum(i) < 700 Then
                                        totalstars(i) = (" * " & " * " & " * " & " * " & " * " & " * ")
                                        'Else
                                        'If usrnum(i) >= 600 And usrnum(i) < 700 And usrnum(i) = Max(usrnum(usramount)) Then
                                        'totalstars(i) = ("    *  " & "    *  " & "    *  " & "    *  " & "    *  " & "    *  ")
                                    Else
                                        If usrnum(i) >= 500 And usrnum(i) < 600 Then
                                            totalstars(i) = (" * " & " * " & " * " & " * " & " * ")
                                            'Else
                                            'If usrnum(i) >= 500 And usrnum(i) < 600 And usrnum(i) = Max(usrnum(usramount)) Then
                                            'totalstars(i) = ("    *  " & "    *  " & "    *  " & "    *  " & "    *  ")
                                        Else
                                            If usrnum(i) >= 400 And usrnum(i) < 500 Then
                                                totalstars(i) = (" * " & " * " & " * " & " * ")
                                                'Else
                                                'If usrnum(i) >= 400 And usrnum(i) < 500 And usrnum(i) = Max(usrnum(usramount)) Then
                                                'totalstars(i) = ("    *  " & "    *  " & "    *  " & "    *  ")
                                            Else
                                                If usrnum(i) >= 300 And usrnum(i) < 400 Then
                                                    totalstars(i) = (" * " & " * " & " * ")
                                                    'Else
                                                    'If usrnum(i) >= 300 And usrnum(i) < 400 And usrnum(i) = Max(usrnum(usramount)) Then
                                                    'totalstars(i) = ("    *  " & "    *  " & "    *   ")
                                                Else
                                                    If usrnum(i) >= 200 And usrnum(i) < 300 Then
                                                        totalstars(i) = (" * " & " * ")
                                                        'Else
                                                        'If usrnum(i) >= 200 And usrnum(i) < 300 And usrnum(i) = Max(usrnum(usramount)) Then
                                                        'totalstars(i) = ("    *  " & "    *  " )
                                                    Else
                                                        If usrnum(i) >= 100 And usrnum(i) < 200 Then
                                                            totalstars(i) = " * "
                                                            'Else
                                                            'If usrnum(i) >= 300 And usrnum(i) < 400 And usrnum(i) = Max(usrnum(usramount)) Then
                                                            'totalstars(i) = ("    *    ")
                                                        Else
                                                            If usrnum(i) >= 0 And usrnum(i) < 100 Then
                                                                totalstars(i) = " "
                                                            ElseIf usrnum(i) < 0 Then
                                                                totalstars(i) = " "
                                                            End If
                                                        End If
                                                    End If
                                                End If
                                            End If
                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If
                    'End If
                    ' End If
                    'End If
                    'End If
                    'End If
                    'End If
                Next i
                Clear()
                'displays results of the bar chart to the user.   
                Do Until userchoice2 = "y" Or userchoice2 = "n"
                    'gives user an extra choice for displaying the bar chart
                    WriteLine("would you like your bar chart sorted into desending order?")
                    WriteLine("Y = yes")
                    WriteLine("N = no ")
                    userchoice2 = ReadLine()
                    If userchoice2 = "y" Then
                        Clear()
                        'sorts the stars and numbers out so they display in desending order, looks neater also for the user to read
                        Array.Sort(usrnum)
                        Array.Reverse(usrnum)
                        Array.Sort(totalstars)
                        Array.Reverse(totalstars)
                        ForegroundColor = ConsoleColor.Magenta
                        WriteLine("")
                        WriteLine("Values for the chart " & nchrt & " in decending order")
                        WriteLine("")
                        For i As Integer = 0 To usrnum.Length - 1
                            BackgroundColor = ConsoleColor.DarkMagenta
                            ForegroundColor = ConsoleColor.White
                            result1 = (totalstars(i))
                            result2 = (usrnum(i))
                            result2.ToString()
                            WriteLine(result1 & result2)
                            WriteLine("")
                        Next i
                        BackgroundColor = ConsoleColor.DarkBlue
                        ForegroundColor = ConsoleColor.White
                        WriteLine("")
                        WriteLine("Please note! Each * Is equal To 100.  
    Once a value reaches over 1000 the maxium amount Of stars shown Is 10 ")
                    Else
                        'displays results as they were typed in and does not sort them in decending order
                        If userchoice2 = "n" Then
                            Clear()
                            ForegroundColor = ConsoleColor.Magenta
                            WriteLine("")
                            WriteLine("Values for the chart " & nchrt)
                            WriteLine("")

                            For i As Integer = 0 To usrnum.Length - 1
                                BackgroundColor = ConsoleColor.Cyan
                                ForegroundColor = ConsoleColor.Black
                                result1 = (totalstars(i))
                                result2 = (usrnum(i))
                                result2.ToString()
                                WriteLine(result1 & result2)
                                WriteLine("")
                            Next i
                            BackgroundColor = ConsoleColor.DarkBlue
                            ForegroundColor = ConsoleColor.White
                            WriteLine("")
                            WriteLine("Please note! Each * Is equal To 100.  
    Once a value reaches over 1000 the maxium amount Of stars shown Is 10 ")
                        Else
                            If userchoice2 <> "n" Or userchoice2 <> "y" Then
                                WriteLine("Sorry that choice is not reconised, please enter a choice of y or n.")
                            End If
                        End If
                    End If
                Loop
            Else
                Clear()
                If userchoice < 1 Or userchoice > 2 Then
                    WriteLine("That value is unknown!")
                    WriteLine("Please enter a choice of 1 or 2 only. ")
                    WriteLine("Press enter to return to the main menu.")
                    ReadLine()
                    Clear()
                Else
                    If userchoice = 2 Then
                        WriteLine("you sure you want to exit?")
                    End If
                End If
            End If
        Loop
        Do Until question1 = "y" Or question1 = "n"
            'exit or return to main menu
            ForegroundColor = ConsoleColor.Magenta
            WriteLine("                                   ")
            WriteLine("                                   ")
            WriteLine("                                   ")
            WriteLine("Would you Like To Exit the program?")
            WriteLine("")
            WriteLine("y = Exit")
            WriteLine("n = return to the main menu")
            Try
                question1 = ReadLine()
                Clear()
            Catch ex As Exception
                'if this produces an error, for example a string is entered by the user then the following message will be issued to the user
                WriteLine("That value is unknown!")
                WriteLine("Please enter a choice of y or n")
            End Try
            If question1 <> "y" Or question1 <> "n" Then
                WriteLine("That value is unknown!")
                WriteLine("Please enter a choice of y or n")
                ReadLine()
                Clear()
            End If
        Loop
    Loop
End Sub
'function that is meant to calculate the largest value in the given usrnum() array however I can't get it to work at the moment :(
Public Function Max(ByVal size As Integer) As Integer
    Dim usrnum(0) As Integer
    usrnum(0) = size
    Dim lstsize As Integer = usrnum.Length - 1 'how many items are in the list
    ReDim usrnum(lstsize)
    Dim i As Integer = 0 'counter to enable all the values within the array to be compared
    Dim maxium As Integer
    maxium = 0 'gives a value for all the values within the array to be compared to

    Do While (i <= lstsize - 1) 'do while still within the size of the array - prevents it from checking values which do not exsist
        If usrnum(i) > maxium Then
            maxium = usrnum(i) ' if the current value is bigger than the current maxium then the new bigger value replaces the maxium
        End If
        i += 1 'enables the counter to work
    Loop
    Return maxium 'returns the final value of maxium
End Function
End Module
Sub-Main()
Dim usrnum(1)、usramount、userchoice、count、结果2为整数
Dim totalstars(1)、问题1、用户选择2、nchrt、结果1作为字符串
直到问题1=“y”为止
userchoice=0
直到userchoice=1或userchoice=2为止
'菜单-文本尽量具体,以防止用户输入错误
WriteLine(“--------------条形图创建者!---------------”)
写线(“”)
写线(“”)
WriteLine(“=================================================================================================”)
WriteLine(“*******************************菜单****************************************”)
WriteLine(“=================================================================================================”)
写线(“”)
ForegroundColor=ConsoleColor.Cyan
WriteLine(“1-开始”)
ForegroundColor=控制台颜色。黄色
WriteLine(“2-退出”)
写线(“”)
写线(“”)
写线(“”)
写线(“”)
'从菜单中读取用户的数据
尝试
userchoice=ReadLine()
清除()
特例
'如果这会产生错误,例如用户输入了字符串,则将向用户发出以下消息
WriteLine(“该值未知!”)
WriteLine(“请仅输入整数”)
结束尝试
如果userchoice=1,则
WriteLine(“您想将条形图命名为什么?”)
nchrt=ReadLine()
清除()
WriteLine(“输入要输入的值的数量。”)
尝试
usramount=ReadLine()
特例
'如果这会产生错误,例如用户输入了字符串,则将向用户发出以下消息
WriteLine(“该值未知!”)
WriteLine(“请仅输入整数:”)
结束尝试
清除()
WriteLine(“图表的值”&nchrt)
写线(“”)
WriteLine(“请注意!每个*等于100。一旦值超过1000,显示的*最大值为10”)
写线(“”)
ReDim usrnum(usramount)'将用户输入重新分配为arraysize的值
ReDim totalstars(usramount)
计数=0
'计数允许用户查看到目前为止他们输入了多少值以及当前使用的数值
当计数1000,则
totalstars(i)=(“*”&“*”&“*”&“*”&“*”&“*”&“*”&“*”&“*”&“*”&“*”)
这是我的功能应该发挥作用的地方,但我无法让它按我希望的方式发挥作用
'这些注释掉的if语句将检查usrnum(i)当前值相对于函数max()的输出是否最大
'如果usrnum(i)的当前值等于max()输出的最大值,则星星之间将添加额外的间距,以便它们跨越控制台窗口的宽度
”“否则呢
'如果usrnum(i)>1000且usrnum(i)=Max(usrnum(usramount)),则
‘totalstars(i)=(“*”&“*”&“*”&“*”&“*”&“*”&“*”&“*”&“*”&“*”&“*”)
其他的
如果usrnum(i)>=900且usrnum(i)<1000,则
totalstars(i)=(“*”&“*”&“*”&“*”&“*”&“*”&“*”&“*”&“*”&“*”)
”“否则呢
'如果usrnum(i)>=900且usrnum(i)<1000且usrnum(i)=Max(usrnum(usramount)),则
'全天星(i)=(“*”