• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

MS Visual Basic | Read first character in a text file

I have an install program that needs to perform a version comparison. The installed program has a C:\MyDirectory\readme.txt file with only the version number in it: 8.0.2.1

How can I read the first character and if the value is LESS THAN 9, do X.

Thanks!
0
blannan
Asked:
blannan
  • 2
1 Solution
 
DanielWillmottCommented:

	Dim objStreamReader as StreamReader   
	Dim line as String
	Dim version as Integer
 
	Try
		objStreamReader = File.OpenText("C:\MyDirectory\readme.txt")   
		line=sr.ReadLine()
		If Not (line Is Nothing)
			if line.Contains(".") then
				version=Integer.Parse(line.SubString(0,line.IndexOf(".")))
			else
				version=Integer.Parse(line)
			end if
		End If
		objStreamReader.Close()
		
		if version<9 then
			' do your thing here...
		end if
	Catch ex As Exception
		' exception processing here  	
	End Try

Open in new window

0
 
DanielWillmottCommented:
Ack..I think this will be better...
	Dim objStreamReader as StreamReader   
	Dim line as String
	Dim version as Integer
 
	Try
		objStreamReader = File.OpenText("C:\MyDirectory\readme.txt")   
		line=sr.ReadLine()
		If Not (line Is Nothing)
			if line.Contains(".") then
				version=Integer.Parse(line.SubString(0,line.IndexOf(".")-1))
			else
				version=Integer.Parse(line)
			end if
		End If
		objStreamReader.Close()
		
		if version<9 then
			' do your thing here...
		end if
	Catch ex As Exception
		' exception processing here  	
	End Try

Open in new window

0
 
blannanAuthor Commented:
Accepted the wrong solution ... Your second one was the winner. Thanks again!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now