Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27034

Read a text file and assign to variables in VB.net

$
0
0
Txt file looks similar to this:
[Test Configuration]
ObjectFileName=\\He2ntsd11\pe2003\ObjectMapFiles\Rel6.1\
[Datapool]
;DataPoolName=Test1
DataPoolName1=Test2

What should the below functions do:
1) Read all the contents of the txt file line by line.
2) As per above data first line will be [Test Configuration]. If its some thing with [] then it should skip
3) As per above data second line will be "ObjectFileName=\\He2ntsd11\pe2003\ObjectMapFiles\Rel6.1\".In this case the function
should read "=" and split "ObjectFileName" into one variable and "\\He2ntsd11\pe2003\ObjectMapFiles\Rel6.1\" into another variable.
4) As per above data third line will be [Datapool]. If its some thing with [] then it should skip
5) As per above data fourth line will be ";DataPoolName=Test1". If its some thing starting with ";" then it should skip
6) As per above data fifth line will be "DataPoolName1=Test2".In this case the function
should read "=" and split "DataPoolName1" into one variable and "Test2" into another variable.

Public Shared g_DatapoolName as string
Public Shared g_DatapoolName1 as string
Public Shared g_ObjectFileName as string

Public Shared Function FileToArray(ByVal sFileName As String) As Integer
Dim strFileName As String
Dim arrLines As New ArrayList()
Dim objReader As System.IO.StreamReader
Dim iRowCount As Integer = 0 ' Variable to hold the total
strFileName = g_iniFile_LocationName & "\" & sFileName
If System.IO.File.Exists( strFileName ) = True Then
' read the file's lines into an ArrayList
objReader = New System.IO.StreamReader(strFileName)
Do While objReader.Peek() <> -1
arrLines.Add(objReader.ReadLine())

Loop
objReader.Close()
Else
Console.WriteLine("'" & strFileName & "' File does not exist")
End If

Return iRowCount

End Function
'Procedure to pass the values to variables.
Public Shared Sub LoadIniFileValuetoGlobalVariabls(sGlobalVariableName As String, sKey_Value As String)
'Dim Result As String

Select Case sGlobalVariableName

Case "g_DataPoolName"
g_DataPoolName = sKey_Value
Case "g_DataPoolName1"
g_DataPoolName1 = sKey_Value
Case "g_ObjectFileName"
g_ObjectFileName = sKey_Value

End Select
End Sub

Can someone help me how to split the read txt values and assign to variables.

Viewing all articles
Browse latest Browse all 27034

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>