I'm working on converting some MatLab code to VB.NET. I'm not a programmer by trade, but I've taught myself some. Unfortunately, I'm very new VB .NET. I have two questions.
1. I'm getting an error in the If statement in the For loop, specific line is noted. Here is the code:
Imports System.Text.RegularExpressions
Imports System
Imports System.IO
Module ConforMIS_Data
Public Structure Properties
Public Name As Array
Public Location As String
Public File As String
Public Prop As String
Public Column As String
Public Type As String
End Structure
Public Props As Properties
Public PropNames() As String
Sub Main()
Dim path As String = "X:\default.config"
Dim config_text() As String = File.ReadAllLines(path)
Dim p As Integer = 0
For i As Integer = 0 To config_text.Length - 1
Dim PropName_RegEx As New Regex("(?<=\[PROPS.).*(?=\])")
Dim PropName As Match = PropName_RegEx.Match(config_text(i))
If (PropName.Length <> 0) Then
PropNames(p) = PropName.ToString()
p = p + 1
Console.WriteLine(PropName.ToString())
End If
Next
Props.Name = PropNames
Console.WriteLine(Props.Name)
Console.Read()
End Sub
Error: Object reference not set to an instance of an object.
I think it has something to do with declaring PropNames AS, but not actually declaring it as a new variable.
Anyhow -- if anyone has thoughts there, I would really appreciate it.
2) In MatLab, you can dynamically name structured arrays with the string value of another variable:
A = "Home"
Welcome.(A) = "Hello World!"
Disp(Welcome.Home)
The output would be "Hello World". Unfortunately, I can't find a way to do this in VB. Anyone
know a simple way?
Thanks in advance!
Mike