Solved

MS Visual Basic  | Read first character in a text file

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

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

691 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