Click here to Skip to main content
15,883,558 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
VB
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
            Next
     End Sub

Convert strings to variant array.in above code i have declare "a" as VariantType.
How to store array of string in variant array?
Posted
Updated 29-Apr-13 2:52am
v5
Comments
Sergey Alexandrovich Kryukov 29-Apr-13 8:43am    
Why? why?!
—SA

I dont understand why you want to do this, however this is how:
VB
Module Module1
    Sub Main()
    ' Integer.
    Dim value As Integer = 5

    ' Get VarType.
    Dim type As VariantType = VarType(value)

    ' Write string representation.
    Console.WriteLine(type.ToString())

    ' Show GetType method.
    Console.WriteLine(value.GetType().ToString())

    ' You can check the VariantType against constants.
    If type = VariantType.Integer Then
        Console.WriteLine("It's an integer!")
    End If
    End Sub
End Module

http://www.dotnetperls.com/vartype[^]
 
Share this answer
 
v3
Comments
[no name] 29-Apr-13 7:55am    
i have to convert
string array to variant array in VB.Nt
[no name] 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? http://en.wikipedia.org/wiki/Variant_type
Sergey Alexandrovich Kryukov 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.
—SA
Sergey Alexandrovich Kryukov 29-Apr-13 8:43am    
My 5.
—SA
Kenneth Haugland 29-Apr-13 8:53am    
Thanks, althouygh I dont see it ;-)
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.

VB
Dim files As New List(Of String)

'inside loop
files.Add(dra.FullName)
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900