locked
sorting an array in XMAL

    Question

  • I am trying to sort the array below. This is a Windows 8 app. 
    I have tried; Array.Sort(arrayNumber)
         for x = 0 to UBound(arrayNumber(y))
    This has not worked for me, could someone help me understand
    how to sort the array for a windows 8 app?

    I am trying to teach myself how to code so any help would be greatly appreciated.

    Private Sub btnPower_Click(sender As Object, e As RoutedEventArgs) Handles btnPower.Click
            Dim arrayNumber(0 To 4) As Integer
            Dim intNumber As Integer
            Dim x, y, p As Integer

            textBox1.Text = ""
            textBox2.Text = ""
            For x = 0 To 4
    Start:
                intNumber = New Random().Next(1, 60).ToString()
                For y = 0 To 4
                    If intNumber = arrayNumber(y) Then
                        GoTo Start
                    End If
                Next y
                arrayNumber(x) = intNumber
                textBox1.Text = textBox1.Text & (arrayNumber(x)) & " , "
            Next
            p = New Random().Next(1, 36).ToString()
            textBox2.Text = textBox2.Text & (p) & ""
        End Sub

    <----------------------XMAL part--------------------->
    <Page
        x:Class="Lottery.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:Lottery"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">

        <Grid>
            <Grid.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black"/>
                    <GradientStop Color="#FF1E157C" Offset="1"/>
                </LinearGradientBrush>
            </Grid.Background>
            <Button x:Name="btnPower" Content="PowerBall" HorizontalAlignment="Left" Margin="96,87,0,0" VerticalAlignment="Top" BorderBrush="Aqua" />
            <Button x:Name="btnMega" Content="Mega Millions" HorizontalAlignment="Left" Margin="718,87,0,0" VerticalAlignment="Top" BorderBrush="Aqua" />
            <TextBox x:Name="textBox1" HorizontalAlignment="Left" Margin="202,87,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="38" Width="160"/>
            <TextBox x:Name="textBox2" HorizontalAlignment="Left" Margin="365,87,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="38" Width="37" Foreground="Red" />
            <TextBox x:Name="textBox3" HorizontalAlignment="Left" Margin="864,87,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="38" Width="160"/>
            <TextBox x:Name="textBox4" HorizontalAlignment="Left" Margin="1026,87,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="38" Width="36" Foreground="Red" />
            <Button x:Name="clrBtn" Content="Clear Boxes" HorizontalAlignment="Left" Margin="534,87,0,0" VerticalAlignment="Top" Height="38" BorderBrush="#FF09F3C9" Foreground="yellow"/>
        </Grid>
    </Page>


    ynot333

    Friday, February 14, 2014 10:53 PM

Answers

  • Hi,
    Check this solution for sorting your array

     Dim arrayNumber(0 To 4) As Integer
            Dim intNumber As Integer
            Dim x, y, p As Integer
    
            
            For x = 0 To 4
    Start:
                intNumber = New Random().Next(1, 60).ToString()
                For y = 0 To 4
                    If intNumber = arrayNumber(y) Then
                        GoTo Start
                    End If
                Next y
                arrayNumber(x) = intNumber
    
            Next
            p = New Random().Next(1, 36).ToString()
            Dim list = arrayNumber.ToList()
            list.Sort()
            Dim sorrtedArray = list.ToArray()

    Regards,


    Ibraheem Osama Mohamed | My Blog | @IbraheemOM | My Website

    (If my reply answers your question, please propose it as an answer)

    Saturday, February 15, 2014 1:14 PM