Home > OS >  How do I generate array elements randomly represented by bar heights in Visual Basic .NET?
How do I generate array elements randomly represented by bar heights in Visual Basic .NET?

Time:01-09

I am taking elementary courses in Visual Basic. I know the basics of arrays and graphics (plotting of graphs, creating trigonometric functions) in NET Framework. I cannot seem to visualize how I can manage to generate array elements randomly represented by bar heights (white) just like in the image below.

enter image description here

I have only tried the code below and I only get a single number every time I generate a number. What I am expecting is to have 0 to 100 listed in a random order but I cannot do it.

Public Class FormSortingAlgorithm
    Dim rnd As New Random()
    Dim nums() As Integer
    Dim i As Integer
    Private Sub btnGenerate_Click(sender As Object, e As EventArgs) Handles btnGenerate.Click
        Dim i As Integer
        ReDim nums(19)
        For i = 0 To 19
            nums(i) = rnd.Next(0, 100)
        Next
    End Sub
    Private Sub btnDisplayArray_Click(sender As Object, e As EventArgs) Handles btnDisplayArray.Click
        txtDisplay.Text = nums(j) & nums(i)
    End Sub
End Class

CodePudding user response:

Note: Assuming Windows Forms, given the names used in the question

  • This line: txtDisplay.Text = nums(j) & nums(i) won't show the content of your array in a TextBox, just a single glued up number, composed by two elements in the array.
    In case j is defined somewhere and it represents a valid index
    You can use Plotting Random Numbers

    CodePudding user response:

    ---<<>><<<IMGTART'WRITE'>>> AWM Special call fowler as mobieba Public Class FormSortingAlgorithm Dim rnd As New Random() Dim nums() As Integer Dim i As Integer Private Sub btnGenerate_Click(sender As Object, e As EventArgs) Handles btnGenerate.Click Dim i As Integer ReDim nums(19) For i = 0 To 19 nums(i) = rnd.Next(0, 100) Next End Sub Private Sub btnDisplayArray_Click(sender As Object, e As EventArgs) Handles btnDisplayArray.Click txtDisplay.Text = nums(j) & nums(i) End Sub End Class END class hit bot and run Dns Vitett Customm Off. With Call OUT To my ATACKOVERFLOW

  • Related