Ken H.
asked on
Pull Data From Rectangular Array
I have a prepopulated array(,) with version numbers and build numbers. I need to create code that looks up the build number (this is the value in smVersion) in the array and returns the version number.
Dim Table1 As DataTable
Table1 = New DataTable("SME")
Dim Version As DataColumn = New DataColumn("Version")
Version.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(Version)
Dim Build As DataColumn = New DataColumn("Build")
Build.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(Build)
Dim Converter1 = Encoding.Convert(Encoding.Unicode, Encoding.Unicode, IO.File.ReadAllBytes(txtPath.Text & "\SMEInfo\SM_Exchange_Version_Info.log"))
Dim ConvertedFile1 = System.Text.Encoding.Unicode.GetString(CType(Converter1, Byte())).Split(vbCrLf)
Dim smVerInfo = (From j In ConvertedFile1 Where Not String.IsNullOrEmpty(j.Trim) Select j.Replace(" ", String.Empty).Trim).ToList
Dim smVersion = From p In smVerInfo Where p.Contains("SnapManager®forMicrosoftExchange-") Select p.Replace("SnapManager®forMicrosoftExchange-", String.Empty).Trim
Dim smBuild As String = ""
Dim smBuilds As String(,) = {{"6.0.2", "6.0.2.853"}, {"6.0P2", "6.0.1.750"}, {"6.0P1", "6.0.1.732"}, {"6.0D1", "6.0.0.708"}, {"6.0", "6.0.0.706"}, {"5.0P2", "5.0.0.208"}, {"5.0P1", "5.0.0.205"}, {"5.0", "5.0.0.186"}, {"4.0P4", "4.0.0.1307"}}
Dim Row1 As DataRow
Try
Row1 = Table1.NewRow()
Row1.Item(Version) = smVersion(0)
Row1.Item(Build) = smBuild
Table1.Rows.Add(Row1)
Catch ex As Exception
End Try
gridSnapManager.DataSource = Table1
gridSnapManager.DataBind()
ASKER
Ok i'll give that a try. I think i'll have to reverse it. Basically I need to go from the long version name and look up the short name.
ASKER
Dim smBuild = From p In smVerInfo Where p.Contains("SnapManager®forMicrosoftExchange-") Select p.Replace("SnapManager®forMicrosoftExchange-", String.Empty).Trim
Dim smBuilds As New Dictionary(Of String, String) From {{"6.0.2", "6.0.2.853"}, {"6.0P2", "6.0.1.750"}, {"6.0P1", "6.0.1.732"}, {"6.0D1", "6.0.0.708"}, {"6.0", "6.0.0.706"}, {"5.0P2", "5.0.0.208"}, {"5.0P1", "5.0.0.205"}, {"5.0", "5.0.0.186"}, {"4.0P4", "4.0.0.1307"}}
Dim MyValue As String = If(smBuilds.ContainsKey(smBuild.ToString), smBuilds.Item(smBuild.ToString), Nothing)
txtOut.Text = MyValue
i'm getting Nothing from the If statement. In the example run i'm doing the smBuild value is 5.0.0.186 which should return 5.0 to MyValue but i'm not getting anything.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Dim smBuild = (From p In smVerInfo Where p.Contains("SnapManager®forMicrosoftExchange-") Select p.Replace("SnapManager®forMicrosoftExchange-", String.Empty).Trim).First
The above returns the same value my original code did.I think it's a dictionary issue. I'm passing the value 5.0.0.186 in smBuild but MyValue is returning nothing as though it doesn't recognize the value passed to it.
ASKER
Got it! Needed to switch back to my original query without the .first and switch the dictionary numbers around.
Thanks for your awesome help as usual!
Thanks for your awesome help as usual!
Open in new window
The you can query it byOpen in new window