Click here to Skip to main content
Rate this: bad
good
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
            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 29-Apr-13 1:34am
Edited 29-Apr-13 3:52am
v5
Comments
Sergey Alexandrovich Kryukov at 29-Apr-13 8:43am
   
Why? why?!
—SA
Rate this: bad
good
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.
    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[^]
  Permalink  
v3
Comments
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? http://en.wikipedia.org/wiki/Variant_type
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.
—SA
Sergey Alexandrovich Kryukov at 29-Apr-13 8:43am
   
My 5.
—SA
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.
—SA
Maciej Los at 29-Apr-13 9:18am
   
+5
Rate this: bad
good
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
files.Add(dra.FullName)
  Permalink  
Comments
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 Marcin Kozub 275
1 OriginalGriff 264
2 Sergey Alexandrovich Kryukov 215
3 Praneet Nadkar 197
4 Richard MacCutchan 182
0 OriginalGriff 8,048
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 29 Apr 2013
Copyright © CodeProject, 1999-2014
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