Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8152327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:40:47+00:00 2026-06-06T15:40:47+00:00

I use the following coding which edits my text file based on the value

  • 0

I use the following coding which edits my text file based on the value in column being smaller than the value in a textbox.

Dim intValue As Integer
        Dim intMaxValue As Integer = Integer.Parse(textbox1.Text)

        Dim strSourceFile As String = IO.Path.Combine("G:\test.txt")
        Dim OutPutFile As String = IO.Path.Combine("G:\test2.txt")

        Dim strLines() As String = IO.File.ReadAllLines(strSourceFile)
        Dim strFiltered As New System.Text.StringBuilder
        Dim strTemp() As String

        For Each strLine In strLines
            If strLine.Trim.Length <> 0 Then
                strTemp = strLine.Split(" "c)
                If Trim(strTemp(0)) = "USER" AndAlso Trim(strTemp(2)) = "1" Then
                    strLine = strTemp(8).Trim & " " & strTemp(16).Trim
                    If Integer.TryParse(strLine.Split(" "c)(1), intValue) Then
                        If intValue <= intMaxValue Then
                            strFiltered.Append(strLine & Environment.NewLine)
                        End If
                    End If
                End If
            End If

        Next

        IO.File.WriteAllText(OutPutFile, strFiltered.ToString)

Now the above coding works perfectly, the output looks like the following:-

String1 100
String1 256
String1 500
String2 100
String2 256
String3 876
String3 345
String3 643
String3 102
String4 100
String4 084
String5 492
String5 178
String6 873
String6 156
String6 786

What I was hoping for was to add additional coding so i only want the String with the highest number showing so the above would look like

String1 500
String2 256
String3 876
String4 100
String5 492
String6 873

Would it be possible to add the final bit of coding?

UPDATE

Rather than checking the highest number and deleting the other fields, I wish to check each matching field in column 1 and check the highest number and if its greater than the field in textbox1 then remove all rows for that matching fields in column 1. If the highest number is lower than the field in textbox1, then keep that row but remove the other column 1 matching fields. So for example

String1 100
String1 256
String1 500
String2 100
String2 256
String3 876
String3 345
String3 643
String3 102
String4 100
String4 084
String5 492
String5 178
String6 873
String6 156
String6 786

So if textbox1 was to have 550 then you should have

String1 500
String2 256
String4 100
String5 492

Update 2

The value in textbox1 is

1341273599

When I only filter the columns to show column 1 and column 2 I get the following.

S00048 1428142557
S00048 1428141809
S00048 1338805621
S00048 1310295931
S00048 1309086124
S00048 1432203954
S00048 1431686625
S00048 1428142556
S00048 1431686626
S00048 1334743408
S00042 1324204635
S00040 1313659927
S00037 1308388943
S00033 1303118141
S00032 1391422317
S00032 1391422304
S00032 1298024019
S00032 1391422303
S00032 1391422316

So when I run the actual coding I get the following

S00048 1338805621
S00042 1324204635
S00040 1313659927
S00037 1308388943
S00033 1303118141
S00032 1298024019

You might be able to see that the end result is incorrect?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:40:49+00:00Added an answer on June 6, 2026 at 3:40 pm

    You could use a Dictionary to hold the values:

        Dim FilteredDictionary as new Dictionary(string, integer)
    
        Dim intValue As Integer
        Dim intMaxValue As Integer = Integer.Parse(textbox1.Text)
    
        Dim strSourceFile As String = IO.Path.Combine("G:\test.txt")
        Dim OutPutFile As String = IO.Path.Combine("G:\test2.txt")
    
        Dim strLines() As String = IO.File.ReadAllLines(strSourceFile)
        Dim strFiltered As New System.Text.StringBuilder
        Dim strTemp() As String
    
        Dim lastIntValue as integer = 0
        For Each strLine In strLines
            If strLine.Trim.Length <> 0 Then
                strTemp = strLine.Split(" "c)
                If Trim(strTemp(0)) = "USER" AndAlso Trim(strTemp(2)) = "1" Then
                    strLine = strTemp(8).Trim & " " & strTemp(16).Trim
                    If Integer.TryParse(strLine.Split(" "c)(1), intValue) Then
                          If intValue = 0 Then
                            intValue=lastIntValue
                          Else
                            lastIntValue=intValue
                          End If
                          If FilteredDictionary.ContainsKey(strTemp(8).Trim) then
                            If intValue > FilteredDictionary(strTemp(8).Trim) then
                              FilteredDictionary(strTemp(8).Trim) = intValue
                            End If
                          Else
                            FilteredDictionary.Add(strTemp(8).Trim, intValue)
                          End If
                            'strFiltered.Append(strLine & Environment.NewLine)
    
                    End If
                End If
            End If
        Next
    
        'Modifed stringbuilder to only add those items that are less than or equal to
        'a given value in Textbox1.  Note that if Textbox1 is not an integer,
        'it will throw an error.  You could use Integer.TryParse instead.
        For Each item As String in FilteredDictionary.Keys.ToList
           If FilteredDictionary(item) <= Convert.ToInt32(Textbox1.Text)
             strFiltered.AppendLine(item & " " & FilteredDictionary(item))
           EndIf
        Next
        IO.File.WriteAllText(OutPutFile, strFiltered.ToString)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am creating simple call filter application which restrict unwanted calls. i use following
In a multi-threaded application, I use the following ASSERT macro to catch coding and
I use following code: Create a retry policy, when error, retry after 1 second,
for example i use following command to find a record SELECT `users`.`mail` FROM `users`
I would like to use following sql to avoid constructing sql dynamically: SELECT CommentID,
I use VS2010, C# to develop Silverlight 4 app, I use following code in
Hello Sir i want send list of data to php server i use following
I have an array of objects, and i use following code to get in
I am working on a PHP project. There, I often use following syntax to
I use the following code try to create an array of string vectors, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.