Click here to Skip to main content
11,797,355 members (77,970 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim a() As VariantType
            Dim di As New DirectoryInfo(TextBox1.Text)
            Dim diar1 As FileInfo() = di.GetFiles()
            Dim dra As FileInfo
            Dim i As Integer
            i = 0
            For Each dra In diar1
                a(i) = dra.FullName.ToString
                i = i + 1
     End Sub
Convert strings to variant above code i have declare "a" as VariantType.
How to store array of string in variant array?
Posted 29-Apr-13 0:34am
Edited 29-Apr-13 2:52am
Sergey Alexandrovich Kryukov at 29-Apr-13 8:43am
Why? why?!
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I dont understand why you want to do this, however this is how:
Module Module1
    Sub Main()
    ' Integer.
    Dim value As Integer = 5
    ' Get VarType.
    Dim type As VariantType = VarType(value)
    ' Write string representation.
    ' Show GetType method.
    ' You can check the VariantType against constants.
    If type = VariantType.Integer Then
        Console.WriteLine("It's an integer!")
    End If
    End Sub
End Module[^]
NikhildPawar at 29-Apr-13 7:55am
i have to convert
string array to variant array in VB.Nt
ThePhantomUpvoter at 29-Apr-13 8:03am
Why? What possible reason would you have to convert a string to a variant at all, assuming that VB.NET supported the variant data type at all?
Sergey Alexandrovich Kryukov at 29-Apr-13 8:45am
Agree. And I think variant types was one of those big stupidities with haunted the whole industry. Variants are evil, it's the best to avoid them, even with COM.
Sergey Alexandrovich Kryukov at 29-Apr-13 8:43am
My 5.
Kenneth Haugland at 29-Apr-13 8:53am
Thanks, althouygh I dont see it ;-)
Sergey Alexandrovich Kryukov at 29-Apr-13 9:29am
I forgot it, voted now; sorry for the inconvenience. Thank you for the note; please don't hesitate to remind, as such things happen.
Maciej Los at 29-Apr-13 9:18am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Rather than string array use List(of T)[^] generic class, which represents a strongly typed list of objects that can be accessed by index; provides methods to search, sort, and manipulate lists.

Dim files As New List(Of String)
'inside loop
Kenneth Haugland at 29-Apr-13 9:54am
Jupp, %'ed. That would be my take as well.
Maciej Los at 29-Apr-13 10:47am
Thank you ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CPallini 475
1 OriginalGriff 375
2 Maciej Los 370
3 Abhinav S 359
4 KrunalRohit 291
0 OriginalGriff 2,092
1 Maciej Los 1,760
2 KrunalRohit 1,436
3 CPallini 1,245
4 ppolymorphe 893

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 29 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100