Click here to Skip to main content
11,930,069 members (50,520 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB 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 1:34am
Edited 29-Apr-13 3:52am
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 29-Apr-13 7:55am
i have to convert
string array to variant array in VB.Nt
ThePhantomUpvoter 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?
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.
My 5.
Kenneth Haugland 29-Apr-13 8:53am
Thanks, althouygh I dont see it ;-)
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 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 29-Apr-13 9:54am
Jupp, %'ed. That would be my take as well.
Maciej Los 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151126.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