Solved

MS Visual Basic  | Read first character in a text file

Posted on 2009-05-04
3
165 Views
Last Modified: 2013-11-26
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
Comment
Question by:blannan
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
DanielWillmott earned 500 total points
ID: 24295728

	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
 
LVL 6

Expert Comment

by:DanielWillmott
ID: 24295760
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
 

Author Comment

by:blannan
ID: 24296031
Accepted the wrong solution ... Your second one was the winner. Thanks again!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now