:dispirited:I m a student and new to VB
I m triyng to pass an array as parrameters
And the compiler says I havent declared the array my coding is as below
Please help me
[XCODE]Sub Main()
'Fill array
Dim MyArray(0 To 9) As String
For lLoop As Integer = 1 To UBound(MyArray)
Console.Write("Enter First Name " & lLoop & ": ")
MyArray(lLoop) = Console.ReadLine()
Next lLoop
SortNames(MyArray)
Console.ReadLine()
End Sub
Public Function SortNames(ByVal ParamArray Arg() As String) As String
Dim lLoop As Long
Dim str1 As String
Dim str2 As String
'Sort array
For lLoop = 0 To UBound(MyArray) ' When I call This Array here I get a declaration error
For lLoop2 = lLoop To UBound(MyArray)
If UCase(MyArray(lLoop2)) < UCase(MyArray(lLoop)) Then
str1 = MyArray(lLoop)
str2 = MyArray(lLoop2)
MyArray(lLoop) = str2
MyArray(lLoop2) = str1
End If
Next lLoop2
Next lLoop
'Output sorted array
For i As Integer = LBound(MyArray) To UBound(MyArray)
Console.WriteLine(MyArray(i))
Next
SortNames = lLoop
End Function
[/XCODE]
I m triyng to pass an array as parrameters
And the compiler says I havent declared the array my coding is as below
Please help me
[XCODE]Sub Main()
'Fill array
Dim MyArray(0 To 9) As String
For lLoop As Integer = 1 To UBound(MyArray)
Console.Write("Enter First Name " & lLoop & ": ")
MyArray(lLoop) = Console.ReadLine()
Next lLoop
SortNames(MyArray)
Console.ReadLine()
End Sub
Public Function SortNames(ByVal ParamArray Arg() As String) As String
Dim lLoop As Long
Dim str1 As String
Dim str2 As String
'Sort array
For lLoop = 0 To UBound(MyArray) ' When I call This Array here I get a declaration error
For lLoop2 = lLoop To UBound(MyArray)
If UCase(MyArray(lLoop2)) < UCase(MyArray(lLoop)) Then
str1 = MyArray(lLoop)
str2 = MyArray(lLoop2)
MyArray(lLoop) = str2
MyArray(lLoop2) = str1
End If
Next lLoop2
Next lLoop
'Output sorted array
For i As Integer = LBound(MyArray) To UBound(MyArray)
Console.WriteLine(MyArray(i))
Next
SortNames = lLoop
End Function
[/XCODE]