Beginner Code help

I need to read from a text.txt file

If "C:\standards" exists within the text file I want to replace it with "P:\standards"

else

If "P:\standards" exists within the text file replace with P:\standards

Mike



Answer this question

Beginner Code help

  • BJ Subsets

    Ok here goes.

    If P:/standards (line of text within the file) exists within an .ini file, I want a button to change, that line (P:/standards) to (C:\standards).  This button will also have to copy the standards folder from P:\standards to the C:\standards.  It will also need to look for this .ini file in a couple of locations.  %Program Files/Arris80 or Arris 81 or Arris 82 Or Arris 83.  Get the idea

    Button two will then delete the C:\standards folder and change the .ini file back to P:\standards.

    So I'm thinking that if I load this program that it would be nice for it to display the current .ini file setting.  The user would then have the option to change either to C:\ or P:\.  Our cad system needs this standards folder to work properly.  All I'm doing is copying the standards folder to my laptop to take it home during the night.  Upon return the next morning I need to set the folder back to the network shared folder.  Now do you see what I'm up too.  I'm open for suguesstions If you can think of a better way. 

    Also progress bar for the transfer of the standards folder, estimated time left would be nice too.


  • kendi

    I'm stuck on 2 errors with the code from above to read from the .ini file

    'cEOF' is not a member of 'notebook.IONOW.iosb.'

    'iosb' is a type and cannot be used as an expression.

    There is also a warning sub 'load' conflicts with event 'Load' in the base class 'Form' and should be declared 'Shadows'.

    Thanks again for your time & help.


  • carlao

    This doesn't look for text files. This replaces strings.

    "If the text.txt file resides within these folders replace text string (within that file)"P:/standards" with C:/standards. Or vice verse"

    And here is what remains ambiguous. Are you referring to text in the text file or are you referring to strings in your program



  • Philippe B

    Read the file into string called Filedata. close the file

    filedata =ReplaceString(filedata,"c:/standards", "P:/standards")

    Open a file for write and write filedata to it. That's all there is to it.



  • Sunny Chen

    Didn't mean to upset you. And I'm sorry if I came off as wanting you to do everything.

    I'm struggling my way through this, and I feel like I'm getting no where.

    Guess I'll go find some more books to read.

    I guess I'll take it form here.

    Thanks for your help.


  • S. Gottschalk

    Is it possible to make this look for the text.txt file in Program Files

    Heres what I need it to do; scan the program files for folders that begin with A. If the text.txt file resides within these folders replace text string (within that file)"P:/standards" with C:/standards. Or vice verse.

    Mike


  • Mack the knife

    Yes, text within a text file. Within the text file there is several lines of text. I'm only interested in modifying the line that reads P:/standards or C:/standards. The end result will be if I press a button it will change P:/standards to C:/standards. If I press the button again it will then replace C:/standards with P:/standards. All I'm trying to do is modify one line of text within a text file, that resides in two possible locations. %Program Files\A1 and/or %Program Files\A2. Does this help or is it still confusing
  • Emil Damian

     

    Here's a read and write class michael. It's very good and it's a little non-traditional.

    Public Class

    dim a as New IONOW

    dim iosb as New IONOW.IOSB

    Dim S as string

    Private sub Load()

    a.open("C\test")

    While iosb.Astat <> IONOW.cEOF

    iosb = a.readFile()

    s &= iosb.buf

    loop

    a.closefiles

    End sub

    End Class

     

     

    Public Class IONOW

        Public Const cEOF As Short = 42

        Public Structure iosb

            Public Status As Boolean

            Public Astat As Short

            Public ByteCount As Short

            Public Buf As String

        End Structure

     

        Dim sw As StreamWriter

        Dim sr As StreamReader

     

        Public Sub WriteData(ByVal line As String)

            Try

                sw.WriteLine(line)

            Catch e As Exception

                MsgBox("Unable to write output file", MsgBoxStyle.Critical, e.Message)

            End Try

     

        End Sub 'Log ' The using closes the stream

     

        Public Function ReadFile(Optional ByVal bSkip As Boolean = False) As iosb

     

            ReadFile = Nothing

     

            ReadFile.Status = False

            Try

                If Not sr.EndOfStream Then

                    If Not bSkip Then

                        ReadFile.Buf = sr.ReadLine()

                        ReadFile.ByteCount = ReadFile.Buf.Length

                        ReadFile.Status = True

                    Else

                        ReadFile.ByteCount = 0

                        ReadFile.Status = 0

                    End If

                Else

                    ReadFile.Astat = cEOF

                    ReadFile.Status = False

                    ReadFile.Buf = ""

                End If

            Catch e As SystemException

                MsgBox("Unable to read input file", MsgBoxStyle.Critical, e.Message)

            Finally

            End Try

     

      

     

        End Function

     

        Public Function Openread(ByVal filespec As String) As StreamReader

     

            Openread = Nothing

            Try

                Openread = New StreamReader(filespec)

            Catch e As Exception

                MsgBox("Unable to open output file: " & filespec, MsgBoxStyle.Information, "Output File Open Error")

            End Try

     

            If Openread IsNot Nothing Then sr = Openread

     

        End Function

     

        Public Function OpenWrite(ByVal Filespec As String) As StreamWriter

     

            OpenWrite = Nothing

     

            Try

                OpenWrite = New StreamWriter(Filespec)

            Catch e As Exception

                MsgBox("Unable to open output file: " & Filespec, MsgBoxStyle.Information, "Output File Open Error")

            End Try

     

            If OpenWrite IsNot Nothing Then sw = OpenWrite

     

        End Function

     

        Public Sub CloseFiles()

            sw.Dispose()

            sr.Dispose()

        End Sub

     

    End Class

    There you are.....



  • odujosh

     

    I'm very sorry you are feeling over whelmed.

    Here's my point michael.

    I don't think you're looking at how this works. yes there were a couple of simple errors there. Did you try to fix them No, you asked me to do it.

    You may have, but I don't see any sign of it. .

    Possibly one reason that you are having difficulty with the code and that I don't think you are relating to the code. I haven't heard one single comment on the code other than it works or it doesn't work. I haven't heard any questions.

    What I have heard is, "I need this and this and this."

    I want you to have what you need michael, honestly I do. The only code I've seen in your project is code that I've writtein. Very few developers would be excited about that.

    I think there's a problem and the problem is that distinction between "help" and "assistance". Help is about me doing your work and you'r not growing from it. Assistance is my committment to help you grow. I'm not here to help people, I'm here to assist them.

    I think your nice and and considerate, Michael. I just feel as if I'm doing all of the thinking here and that doesn't feel good. My reward in all of this is to see your growth. If I do the work for you, I have done neither of us a favor.



  • Earle

    When the exe file is loaded can I have it check the text file first without pressing any buttons and report back to a textbox the current setting ("C:/Standards" or "P:/standards")

     

    Of course. What is the discriminanda

    "Then I need two buttons.  One to change the text ...."

    Micheal as I read this, something jelled for me. The world doesn't need any more buttons at all.

    It needs ALGORITHMS.  That you need a button doesn't help me.

    What I need to know is:

    1.) What is your end goal

    2.) What conditions exists before the button is pushed

    3.) What will be different after the button has been pressed.

    4.)What data do you have

    5.)What are the apparent restrictions

     

    See how inconsequental these questions make a button seem when they are forefronted.

     

     

     



  • Marcela Moreno

    Let's do this.....

    You've gotten all of the basic ingredients....

    ***Sigh*** and I've written all the code.

    lets take this on step at a time....

    put the code together and read the .ini file.

    That's the first step....



  • Hardy

    This is not going to work like I had planned.

    When the exe file is loaded can I have it check the text file first without pressing any buttons and report back to a textbox the current setting ("C:/Standards" or "P:/standards") Then I need two buttons. One to change the text to C:standards the other button to change it to P:standards.

    Also how do I "read file into string." Most of the help files are not giving me a clear idea as to what to do. Could I get a few more hints, please


  • TonyAM

    Michael,

    I understand you are a beginner.

    Change IONOW.iosb to ionow.ceof

    delete iosb = readlines

    But I have concerns. These are really simple obvious errors.

    My concern is that I'm doing this and you aren't learning the basics and the fundamentals....



  • Seelam

    Public Class Form1

     

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            TextBox1.Text = ReplaceString( _

            "Now is the time for all good men to come to the aid of their country. Now is the time for all" & _

            " good men to come to the aid of their country. Now is the time for all good men to come to the aid " & _

            "of their country.", "persons", "men")

        End Sub

     

        Private Sub cbGo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbGo.Click

     

        End Sub

     

     

        Private Function ReplaceString(ByVal InString As String, ByVal ReplacementString As String, _

                                      ByVal TriggerString As String) As String

     

     

            If Not InString.Contains(TriggerString) Then

                ReplaceString = InString

                Exit Function

            Else

                ReplaceString = ""

            End If

     

     

            Dim pos As Integer

            While InString.Length > 0

                pos = InStr(InString, TriggerString)

                If pos = 0 Then

                    ReplaceString += InString

                    InString = ""

                Else

                    pos -= 1

                    ReplaceString += InString.Substring(0, pos) + ReplacementString

                    InString = InString.Substring(pos + TriggerString.Length)

                End If

            End While

     

        End Function

     

     

     

        Private Sub cbExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbExit.Click

            End

        End Sub

    End Class

     

    ******PLEASE NOTE***** This editor messes up syntax. It has here. It has introduced continuation line errors. This works and works very well when straighten out the errors the boards editor has introduced.

     



  • Beginner Code help