Solved

MS Visual Basic  | Read first character in a text file

Posted on 2009-05-04
3
162 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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