I need to take some code written in VisualFoxPro and rewrite it in VB. Having no experience with FoxPro I asked about a few commands used in the code and found one of particular use: scatter memvar
, which made individual variable from columns in a table. Does VB have an equivalent function, or do I need to create each variable with a Dim
statement?
Edit: I should have mentioned that I'm looking to use this to propagate datatables, very sorry. Later in the VFP program insert into memvar
matches the variables to their respective columns. I'm looking to avoid the need of a method along the lines of:
For Each row As DataRow in MyTable
row.Item(0,i) = myVar1
row.Item(1,i) = myVar2
'etc.
i += 1
Next
Sadly, the above is how I do most of my data entry.
Edit: In response to @DRapp's comment, I am using VB to read a .xin
file and form an access data table from its code. There are two "collections" in the .xin
file that are of interest to me: <NamedSymbologyCollection>
and <FeatureStylesCollection>
. Both of these collections are in the same line of the file, so I've written code to go tag-by-tag, pick out the information I want, and add it to a temporary data table.
Do Until reader.EndOfStream
content = reader.ReadLine
For Each code In content
If content.Length > 0 Then
crntTag = content.Substring(0, content.IndexOf(">") + 1)
If crntTag.Contains("/FeatureStyleCollection>") Then
Exit Do
End If
If crntTag.Contains("<NamedSymbology ItemName") Then
wholeTag = GetFullLine(content)
xinCompile.Rows.Add()
For Each entry In wholeTag
lcstring = wholeTag.Substring(0, wholeTag.IndexOf(">") + 1)
If wholeTag.Length = 0 Then
Exit For
End If
If lcstring.Contains("<NamedSymbology ") Then
SymbName = GrabCodeElement(lcstring, "ItemName=")
SymbDesc = GrabCodeElement(lcstring, "Description=")
wholeTag = wholeTag.Remove(wholeTag.IndexOf(lcstring), wholeTag.IndexOf(">") + 1)
xinCompile.Rows(i).Item("symbName") = SymbName
xinCompile.Rows(i).Item("symbDesc") = SymbDesc
ElseIf lcstring.Contains("<BasePointSymbology ") Then
CellLayer = GrabCodeElement(lcstring, "CellLayerName=")
CellName = GrabCodeElement(lcstring, "Name=")
wholeTag = wholeTag.Remove(wholeTag.IndexOf(lcstring), wholeTag.IndexOf(">") + 1)
xinCompile.Rows(i).Item("cellLayer") = CellLayer
xinCompile.Rows(i).Item("cellName") = CellName
ElseIf lcstring.Contains("<LineSymbology ") Then
LineSymb = GrabCodeElement(lcstring, "<LineSymbology LayerName=")
LineSymb = LineSymb.Substring(15, LineSymb.Length - 16)
xinCompile.Rows(i).Item("lineSymb") = LineSymb
wholeTag = wholeTag.Remove(wholeTag.IndexOf(lcstring), wholeTag.IndexOf(">") + 1)
Else
wholeTag = wholeTag.Remove(wholeTag.IndexOf(lcstring), wholeTag.IndexOf(">") + 1)
End If
Next
i += 1
ElseIf crntTag.Contains("<FeatureStyle ItemName") Then
wholeTag = GetFullLine(content)
j = 0
featStyles.Rows.Add()
For Each entry In wholeTag
lcstring = wholeTag.Substring(0, wholeTag.IndexOf(">") + 1)
If wholeTag.Length = 0 Then
Exit For
End If
If lcstring.Contains("<FeatureStyle ") Then
SymbName = GrabCodeElement(lcstring, "ItemName=")
SymbDesc = GrabCodeElement(lcstring, "Description=")
For Each item As DataRow In xinCompile.Rows
If SymbName = item.Item("symbName") Then
found = True
Exit For
End If
j += 1
Next
If found = True Then
wholeTag = wholeTag.Remove(wholeTag.IndexOf(lcstring), wholeTag.IndexOf(">") + 1)
Else
Exit For
End If
xinCompile.Rows(j).Item("symbDesc") = SymbDesc
ElseIf lcstring.Contains("<SurveyFeature ") Then
NumCode = GrabCodeElement(lcstring, "NumericCode=")
DTMexclude = GrabCodeElement(lcstring, "ExcludeFromTriangulation=")
lineToPrev = GrabCodeElement(lcstring, "LineToPrevious=")
featType = GrabCodeElement(lcstring, "FeatureType=")
wholeTag = wholeTag.Remove(wholeTag.IndexOf(lcstring), wholeTag.IndexOf(">") + 1)
xinCompile.Rows(j).Item("numCode") = NumCode
xinCompile.Rows(j).Item("DTMexclude") = DTMexclude
xinCompile.Rows(j).Item("lineToPrev") = lineToPrev
xinCompile.Rows(j).Item("featType") = featType
ElseIf lcstring.Contains("<Attribute ") Then
LineLayer = GrabCodeElement(lcstring, "Name=")
wholeTag = wholeTag.Remove(wholeTag.IndexOf(lcstring), wholeTag.IndexOf(">") + 1)
ElseIf lcstring.Contains("<AlphaCode") Then
alphacode = GrabCodeElement(lcstring, "Code=")
If IsDBNull(xinCompile.Rows(j).Item("alphaCode")) Then
fullAlpha = ""
xinCompile.Rows(j).Item("alphaCode") = alphacode
Else
fullAlpha = xinCompile.Rows(j).Item("alphaCode")
xinCompile.Rows(j).Item("alphaCode") = fullAlpha & "," & alphacode
End If
wholeTag = wholeTag.Remove(wholeTag.IndexOf(lcstring), wholeTag.IndexOf(">") + 1)
Else
wholeTag = wholeTag.Remove(wholeTag.IndexOf(lcstring), wholeTag.IndexOf(">") + 1)
End If
Next
End If
content = content.Remove(0, crntTag.Length)
Else
Exit For
End If
Next
Loop
If you have any recommendations on how to improve any of the above, please let me know.