Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

hi,

 

i want to search a file for a specific number.

 

the number is 10 positions after the word PPI in the textfile.

when the number is found, i want to take the number and compare it to the another number.

 

can anyone give me an example???????

 

 

thx akim123

  • Leaders
Posted

   Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
       Dim sr As IO.StreamReader = New IO.StreamReader(New IO.FileStream("C:\test.txt", IO.FileMode.Open))
       Dim i As Integer, s As String, c As Char
       s = sr.ReadToEnd
       If InStr(s, "PPI", CompareMethod.Text) Then
           i = InStr(s, "PPI", CompareMethod.Text)
           c = Mid(s, i + 10) '/// get the char 10 places after PPI
           '/// do your stuff to compare numbers , eg:
           Select Case c
               Case "7"
                   MessageBox.Show("the numbers match!")
               Case Else
                   MessageBox.Show("the numbers are different!")
           End Select
       End If
       sr.Close()
   End Sub

hope this helps :)

Posted

hi,

 

first af all , thanx for your great example!!!!!!!!!

 

now i have the problems that i want to have not only position 10 after the word PPI , i want to have the numbers 10 - 15 after ppi.

 

can you help me??

 

thanx alot

 

 

akim123

  • *Experts*
Posted

Dim reader As New IO.StreamReader("pathtofile")
Dim filetext As String = reader.ReadToEnd()
Dim ppistart As Integer = filetext.IndexOf("PPI") + 3 'add 3 becuase 
'the word is 3 letter long so we get the number right after the word
Dim numbers() As Char = filetext.Substring(ppistart + 10, 5)
'start at 10 positions after "PPI" was found, and get next 5 characters
reader.Close()

The numbers() array will now contain all the 5 numbers 10-15.

You should use those methods of the string instead of the ones dynamic_sysop showed you.

Posted

thx alot for your example. it really helped me out.

 

with your example i got the value i want into numbers.

 

but it is of type char.

 

i can't say

 

dim i,s as integer

 

i = 200

 

s = i + numbers.

 

can you help me

 

thx akim

  • *Experts*
Posted

Change the declaration of numbers() to:

Dim numbers As String = filetext.Substring(ppistart + 10, 5)
'then convert the string to a number
Convert.ToInt32(numbers)

Then convert the string to a number.

Posted

Hi,

 

thx for your example.

 

ok,

 

i made it like th is:

 

dim numbers as double = filetext.Substring(ppistart + 10, 5)

 

it works.

 

but the value in my textfile is for example 23.5332

 

it should be a double value.

when i see the output of numbers it gives me 235332

it must be 23,5332. --> a double value in the end .

 

can you help me???????

 

 

thx akim

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...