VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This code randomly generates numbers from where the user wants and sorts them useing the exchange s

by Ben Bloom (1 Submission)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 20th October 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This code randomly generates numbers from where the user wants and sorts them useing the exchange sort

Rate This code randomly generates numbers from where the user wants and sorts them useing the exchange s




bgch = InputBox("what letter do you want to start at", "open")
edch = InputBox("what letter do you want to end at", "open")
chnum = InputBox("How many letters you want", "open", "26")
chrange = Asc(edch) - Asc(bgch) + 1
For x = 1 To chnum
    arch(x) = Asc(Int(Rnd * chrange)) + Asc(bgch)
    lstunsorted.AddItem Chr(arch(x))
Next x
End Sub

Private Sub mnugenerate2_Click()
bgch = InputBox("what letter do you want to start at", "open")
edch = InputBox("what letter do you want to end at", "open")
chnum = InputBox("How many letters you want", "open", "26")
chrange = Asc(edch) - Asc(bgch) + 1
For x = 1 To chnum
    arch(x) = Asc(Int(Rnd * chrange)) + Asc(bgch)
    lstunsorted.AddItem Chr(arch(x))
Next
End Sub

Private Sub mnugenerate27_Click()
str = InputBox("what is the min number", "open", "1")
fin = InputBox("what is the max number", "open", "1000")
num = InputBox("how many numbers you want", "open", "1000")
range = fin - str + 1
For x = 1 To num
    arint(x) = Int(Rnd * range) + str
    lstunsorted.AddItem arint(x)
Next x
End Sub

Private Sub mnugenerate3_Click()

bgch = InputBox("what letter do you want to start at", "open")
edch = InputBox("what letter do you want to end at", "open")
chnum = InputBox("How many letters you want", "open", "26")
chrange = Asc(edch) - Asc(bgch) + 1
For x = 1 To chnum
    arch(x) = Asc(Int(Rnd * chrange)) + Asc(bgch)
    lstunsorted.AddItem Chr(arch(x))
Next
End Sub

Private Sub mnugenerate4_Click()

str = InputBox("what is the min number", "open", "1")
fin = InputBox("what is the max number", "open", "1000")
num = InputBox("how many numbers you want", "open", "1000")
range = fin - str + 1
For x = 1 To num
    arint(x) = Int(Rnd * range) + str
    lstunsorted.AddItem arint(x)
Next x
End Sub

Private Sub mnugenerate5_Click()

str = InputBox("what is the min number", "open", "1")
fin = InputBox("what is the max number", "open", "1000")
num = InputBox("how many numbers you want", "open", "1000")
range = fin - str + 1
For x = 1 To num
    arint(x) = Int(Rnd * range) + str
    lstunsorted.AddItem arint(x)
Next x
End Sub

Private Sub mnugenerate6_Click()

str = InputBox("what is the min number", "open", "1")
fin = InputBox("what is the max number", "open", "1000")
num = InputBox("how many numbers you want", "open", "1000")
range = fin - str + 1
For x = 1 To num
    arint(x) = Int(Rnd * range) + str
    lstunsorted.AddItem arint(x)
Next x
End Sub

Sub exchangesortint()

    For front = 1 To range - 1
        For back = front + 1 To range
            If arint(front) > arint(back) Then
                temp = arint(front)
                arint(front) = arint(back)
                arint(back) = temp
            End If
        Next back
    Next front
For x = 1 To range
    lstsorted.AddItem$ (arint(x))
Next x
End Sub

Sub combsortint()

Dim j As Integer
Const shrink = 1.3
Dim gap As Single
Dim swapped As Integer
gap = range
Do
    gap = Int(gap / shrink)
    If gap < 1 Then gap = 1
        swapped = False
    For j = 1 To range - gap
        If arint(j) > arint(j + gap) Then
            '-swap
            temp = arint(j)
            arint(j) = arint(j + gap)
            arint(j + gap) = temp
            swapped = True
        End If
    Next j
Loop Until Not swapped
For x = 1 To range
    lstsorted.AddItem (arint(x))
Next x
End Sub

Sub bublesortint()
Dim j As Integer
Dim i As Integer
Dim swapped As Integer
Do
    swapped = False
    For j = 1 To range - 1
        If arint(j) > arint(j + 1) Then
            temp = arint(j)
            arint(j) = arint(j + 1)
            arint(j + 1) = temp
            swapped = True
            End If
        Next j
    range = range - 1
Loop Until Not swapped
For x = 1 To range
    lstsorted.AddItem (arint(j))
Next x
End Sub

Private Sub mnusort_Click()
jon = InputBox("which way would you like to sort", "open", "1")
If jon = 1 Then
    combsortint
End If
If jon = 2 Then
    exchangesortint
End If
If jon = 3 Then
    bublesortint
End If
End Sub

Private Sub mnusort5_Click()

For front = 1 To chrange - 1
        For back = front + 1 To chrange
            If arint(front) > arint(back) Then
                temp = arint(front)
                arint(front) = arint(back)
                arint(back) = temp
            End If
        Next back
    Next front
For x = 1 To chrange
    lstsorted.AddItem$ Chr(arint(x))
Next x
End Sub



Download this snippet    Add to My Saved Code

This code randomly generates numbers from where the user wants and sorts them useing the exchange s Comments

No comments have been posted about This code randomly generates numbers from where the user wants and sorts them useing the exchange s. Why not be the first to post a comment about This code randomly generates numbers from where the user wants and sorts them useing the exchange s.

Post your comment

Subject:
Message:
0/1000 characters