0

Is it possible to rewrite the following VB.NET code in VB6?

Dim Names(,) As String = New String(,) {{"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}, {"UserName", "RealName"}}
3
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by leverin4
0

Yes, I would think something like -

Dim Names As String, UserName As String, RealName As String

For Names = 0 to YourValue 'From above it seems like 27
   UserName = txtUserName.Text 'Or whereever you want the result
   RealName = txtRealName.Text
   'Deal with the username and realname here code
Next Names
0

Yes it is possible, but not quite as easy.

If you know how many dimensions there are to begin with, you can do it like so...

Dim MyArray(1 To 25, 1 To 2) As String 'or could be 0 to 24, 0 to 1

MyArray(1, 0) = "UserName1"
MyArray(1, 1) = "RealName1"
'...
MyArray(25, 0) = "UserName25"
MyArray(25, 1) = "RealName25"

Or you could create your own UDT (User Defined Type)...

Option Explicit

Private Type MyUserType
  UserName As String
  RealName As String
End Type

Dim MyUser(1 To 25) As MyUserType

Private Sub Form_Load()
MyUser(1).UserName = "UserName1"
MyUser(1).RealName = "RealName1"
'...
MyUser(25).UserName = "UserName25"
MyUser(25).RealName = "RealName25"

End Sub

Good Luck

Edited by vb5prgrmr: Fixed Code Tags

0

There's over 150 total. I use a macro in excel to generate the array declaration for me. I deleted most of them to avoid clutter. Ugh. I'll try to later the macro to do this instead. Fun. Thanks for your help guys.

0

Sorry for the double post, but I botched my last one and can't edit anymore. There's over 150 total, I only showed 27 in this thread to avoid clutter.

The full array declaration is generated by a macro I wrote in an excel sheet; I was hoping I just had the formatting wrong for VB6, but apparently not. It does appear that I'll be able to alter the macro to fill the array line by line. It'll just make my code look messy. I guess I'll create a function called FillArray at the bottom or something to make things cleaner.

Again, thanks for all your help!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.