Solved

MS Visual Basic  | Read first character in a text file

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

773 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