how to read the last numeric number on the line?

D

dav

HI,

I am new to vb.net and i want to open a batch file to read the last
numeric number of each line and use that number (1/0) to determine if a
particular item of drop down box should be visible.

Can anyone help me with this?



Tahnks in advance.
 
D

dav

Managed to get what to display in a pretty bad manner... Look for a
better way to code it..
===================================
'Need to add 2 lines below if using streamreader!
'Please look at Mybase.load for more detail.
'line before Private Sub Fullbkup_Load are omitted
Imports System
Imports System.IO


Public Class Fullbkup
Inherits System.Windows.Forms.Form

'Basically just need to add lines below under mybase.load
Private Sub Fullbkup_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim sr As StreamReader = New StreamReader("C:\Documents and
Settings\davidfeng\Desktop\WSH\bat\dump_flag.bat")
Dim mystr As String
Do While sr.Peek() >= 0
mystr = sr.ReadLine
mystr = mystr.TrimEnd(" ")

If mystr = "SET /A HD1_archive=1" Then
mystr = "[HD1] requires file dump"
Me.ListBox1.Items.Add(mystr)
End If

If mystr = "SET /A HD2_archive=1" Then
mystr = "[HD2] requires file dump"
Me.ListBox1.Items.Add(mystr)
End If
If mystr = "SET /A HD3_archive=1" Then
mystr = "[HD3] requires file dump"
Me.ListBox1.Items.Add(mystr)
End If

Loop
End Sub
End Class
 
J

Jim Underwood

Why not just use the substring method after you read the line into a string
variable?

mystr.Substring(mystr.Length - 1, 1) should get you the last character in
the line (after you have trimmed the trailling spaces of course).

then just check the value to see whether it is a 1 or a 2.

You can use the same method to get the other pieces of the line.

mystr = "SET /A HD1_archive=1"
mystr.Substring(0, 3) = "SET"
mystr.Substring(4, 2) = "/A"
mystr.Substring(7, 3) = "HD1"

Of course, if you can have variable lengths for the values above (maybe
"/A/B"place of "/A") then substring would only work if you based your
starting and ending points around the next space or =, etc. Fixed length or
delimited files make this easier, and XML really is the way to go if you
have the option, as you dont have to deal with subtrings at all. I suspect
that you are inheriting some interface file and that you are stuck with the
format, so substring is probably what you want to use.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top