Link to home
Start Free TrialLog in
Avatar of blannan
blannanFlag for United States of America

asked on

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!
ASKER CERTIFIED SOLUTION
Avatar of DanielWillmott
DanielWillmott
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of blannan

ASKER

Accepted the wrong solution ... Your second one was the winner. Thanks again!