?
Solved

MS Visual Basic  | Read first character in a text file

Posted on 2009-05-04
3
Medium Priority
?
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
DanielWillmott earned 2000 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

Stack Overflow Podcast - Developer Story

Welcome to the Stack Overflow podcast recorded Thursday July 20 at Stack Overflow Headquearters in NYC. Your hosts today are podcast regulars Jay Hanlon, David Fullerton, and Ilana Yitzhaki, plus the quite irregular Matt Sherman (Stack Overflow Engineering Manager extraordinaire)

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

777 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