Hi there. There are a couple of reasons.
You can't put a SUB in between main code like that. Move the SUB to the end of main code. AI chatbots often make this mistake when making QB64 code, even after telling it not to do it.
Next thing, the SUB won't recognize the Dim variables you made in the main code unless they are DIM Shared, or if the are DIMmed inside the SUB instead.
I moved the DIMs to inside the SUB below and it works, you could DIM them as shared in the main code instead if you need to use them in other SUB's.
- Dav
You can't put a SUB in between main code like that. Move the SUB to the end of main code. AI chatbots often make this mistake when making QB64 code, even after telling it not to do it.
Next thing, the SUB won't recognize the Dim variables you made in the main code unless they are DIM Shared, or if the are DIMmed inside the SUB instead.
I moved the DIMs to inside the SUB below and it works, you could DIM them as shared in the main code instead if you need to use them in other SUB's.
- Dav
Code: (Select All)
' Seed the random number generator
Randomize Timer
' Call the subroutine to generate and display the numbers
GenerateUniqueNumbers
Sub GenerateUniqueNumbers
Dim numbers(5) As Integer
Dim count As Integer
Dim i As Integer
Dim newNumber As Integer
Dim isDuplicate As Integer
count = 0
Do
' Generate a random number between -1 and 71
newNumber = Int(Rnd * 73) - 1
isDuplicate = 0
' Check if the number is already in the array
For i = 1 To count
If numbers(i) = newNumber Then
isDuplicate = 1
Exit For
End If
Next i
' If it's not a duplicate, add it to the array
If isDuplicate = 0 Then
count = count + 1
numbers(count) = newNumber
End If
Loop Until count = 5
' Print the selected numbers
Print "The 5 unique numbers are:"
For i = 1 To 5
Print numbers(i)
Next i
End Sub