read write rtf file

Hi all,

I hope someone can help me with this and I am about to tear my hair out.

I have a app that will have a SSTab on it. On the first tab I have some text boxes linked to a database. One of the boxes holds a number 1, 2, 3 etc. These refer to a record and all the boxes populate ok. On tab 2 I have copies of three of the boxes including the Number text box, and a Rich Text File box. What I need is help wioth the code that as the number in the text box (the numbered one) changes from say 1 to 2 the rich text box unloads 1.rtf and opens 2.rtf.

Does that make sense?

I tried adapting a read write text file and putting it in the navigation buttons of the datbase (move next etc.) but it doesn't seem to work.

Can you help? Also can I get the Rich Text box to clear and be emt=pty ready when I click add record and then write a file. Example I add record and it autonumbers on the Access Database to 3 and the rich text file 3.rtf is created too?

Thanks for any help in advance

Lensmeister.

Comments


  • :What I need is help wioth the code that as the number in the text box (the numbered one) changes from say 1 to 2 the rich text box unloads 1.rtf and opens 2.rtf.

    First, you need to detect the change in the text box, so the code will be written in Change event procedure:
    [code]
    Private Sub txtNumber_Change()
    [...]
    End Sub
    [/code]

    Then, if your files are really named "1.rtf", "2.rtf", etc, you can use this:
    [code]
    Dim mFileName
    mFileName = txtNumber.Text & ".rtf"
    [/code]

    If they have some other names:
    [code]
    Dim mFileName
    Select Case txtNumber.Text
    Case "1": mFileName = "first.rtf"
    Case "2": mFileName = "second.rtf"
    Case "3": mFilename = "third.rtf"
    [...]
    Case Else: mFileName = "*invalid name*"
    End Select
    [/code]

    Now that you know the filename, all you need to do is check if the file exists, and load it.

    Here's a sample load procedure, just in case you need it.
    [code]
    Private Sub LoadRichFile(ByVal fileName As String, RTFBox As Object)
    Dim mBuffer As String
    Dim mFile As Integer
    mFile = FreeFile
    Open fileName For Binary As #mFile
    mBuffer = String(0, Len(mFile)) ' <- !!! Check which param is for length, first or second ... ?
    Get #mFile, , mBuffer
    Close #mFile
    RTFBox.RichText = mBuffer
    End Sub
    [/code]

    Ask if there's something unclear.

    Hope I helped,
    Nikolay Semov

  • :
    : :What I need is help wioth the code that as the number in the text box (the numbered one) changes from say 1 to 2 the rich text box unloads 1.rtf and opens 2.rtf.
    :
    : First, you need to detect the change in the text box, so the code will be written in Change event procedure:
    : [code]
    : Private Sub txtNumber_Change()
    : [...]
    : End Sub
    : [/code]
    :
    : Then, if your files are really named "1.rtf", "2.rtf", etc, you can use this:
    : [code]
    : Dim mFileName
    : mFileName = txtNumber.Text & ".rtf"
    : [/code]
    :
    : If they have some other names:
    : [code]
    : Dim mFileName
    : Select Case txtNumber.Text
    : Case "1": mFileName = "first.rtf"
    : Case "2": mFileName = "second.rtf"
    : Case "3": mFilename = "third.rtf"
    : [...]
    : Case Else: mFileName = "*invalid name*"
    : End Select
    : [/code]
    :
    : Now that you know the filename, all you need to do is check if the file exists, and load it.
    :
    : Here's a sample load procedure, just in case you need it.
    : [code]
    : Private Sub LoadRichFile(ByVal fileName As String, RTFBox As Object)
    : Dim mBuffer As String
    : Dim mFile As Integer
    : mFile = FreeFile
    : Open fileName For Binary As #mFile
    : mBuffer = String(0, Len(mFile)) ' <- !!! Check which param is for length, first or second ... ?
    : Get #mFile, , mBuffer
    : Close #mFile
    : RTFBox.RichText = mBuffer
    : End Sub
    : [/code]
    :
    : Ask if there's something unclear.
    :
    : Hope I helped,
    : Nikolay Semov
    :
    :
    Thanks Nikolay ...

    I tried it in my projrct but it didn't work . The text box that contained the number is part of an array box that is fed by a database.

    any ideas ?


  • If so, you'll need to handle the correct Index.

    About the loading of an RTF file: the RTFTextbox control has a function for loading and saving RTF files! I suggest you use those, instead of a custom made load procedure!

    Greets...
    Richard


  • : About the loading of an RTF file: the RTFTextbox control has a function for loading and saving RTF files! I suggest you use those, instead of a custom made load procedure!
    :
    Richard,

    Where and how does that work please. And I have deleted the text boxes as before and I am going to redesign the form as I showed someone and they thought an alternative look was better so I will retry the code above, or this other load function.
  • :
    : : About the loading of an RTF file: the RTFTextbox control has a function for loading and saving RTF files! I suggest you use those, instead of a custom made load procedure!
    : :
    : Richard,
    :
    : Where and how does that work please. And I have deleted the text boxes as before and I am going to redesign the form as I showed someone and they thought an alternative look was better so I will retry the code above, or this other load function.
    :

    It's a highly complicated procedure that only the most experienced programmers can use!

    [code]
    RichTextBox1.LoadFile "c:My file.rtf"
    [/code]

    And for saving:
    [code]
    RichTextBox1.SaveFile "c:My new file.rtf"
    [/code]

    Greets...
    Richard

  • : :
    : : : About the loading of an RTF file: the RTFTextbox control has a function for loading and saving RTF files! I suggest you use those, instead of a custom made load procedure!
    : : :
    : : Richard,
    : :
    : : Where and how does that work please. And I have deleted the text boxes as before and I am going to redesign the form as I showed someone and they thought an alternative look was better so I will retry the code above, or this other load function.
    : :
    :
    : It's a highly complicated procedure that only the most experienced programmers can use!
    :
    : [code]
    : RichTextBox1.LoadFile "c:My file.rtf"
    : [/code]
    :
    : And for saving:
    : [code]
    : RichTextBox1.SaveFile "c:My new file.rtf"
    : [/code]
    :
    : Greets...
    : Richard
    :
    :
    Cheers Richard ... This is how I used that:

    Private Sub tstTripNo_Change()
    ' load the rtf and save the rtf if not exist.
    Select Case tstTripNo()
    Case "1"
    rtfJNarative.LoadFile "1.rtf", rtfRTF
    Case "11"
    rtfJNarative.LoadFile "11.rtf", rtfRTF
    End Select
    End Sub

    BUT it's doesn't work :(

  • : Cheers Richard ... This is how I used that:
    :
    : Private Sub tstTripNo_Change()
    : ' load the rtf and save the rtf if not exist.
    : Select Case tstTripNo()
    : Case "1"
    : rtfJNarative.LoadFile "1.rtf", rtfRTF
    : Case "11"
    : rtfJNarative.LoadFile "11.rtf", rtfRTF
    : End Select
    : End Sub
    :
    : BUT it's doesn't work :(
    :
    What's tstTripNo ?!?!?!?!?!?!
  • :
    : : Cheers Richard ... This is how I used that:
    : :
    : : Private Sub tstTripNo_Change()
    : : ' load the rtf and save the rtf if not exist.
    : : Select Case tstTripNo()
    : : Case "1"
    : : rtfJNarative.LoadFile "1.rtf", rtfRTF
    : : Case "11"
    : : rtfJNarative.LoadFile "11.rtf", rtfRTF
    : : End Select
    : : End Sub
    : :
    : : BUT it's doesn't work :(
    : :
    : What's tstTripNo ?!?!?!?!?!?!
    :tsttripno it the name of the textbox conytrol .... I typed it wrong should have been txtTripNo




  • : :
    : : : Cheers Richard ... This is how I used that:
    : : :
    : : : Private Sub tstTripNo_Change()
    : : : ' load the rtf and save the rtf if not exist.
    : : : Select Case tstTripNo()
    : : : Case "1"
    : : : rtfJNarative.LoadFile "1.rtf", rtfRTF
    : : : Case "11"
    : : : rtfJNarative.LoadFile "11.rtf", rtfRTF
    : : : End Select
    : : : End Sub
    : : :
    : : : BUT it's doesn't work :(
    : : :
    : : What's tstTripNo ?!?!?!?!?!?!
    : :tsttripno it the name of the textbox conytrol .... I typed it wrong should have been txtTripNo
    :
    :
    :
    :
    :

    Change the first line of Select Case into "Select Case txtTripNo.Text"


    Greets...
    Richard

  • : : :
    : : : : Cheers Richard ... This is how I used that:
    : : : :
    : : : : Private Sub tstTripNo_Change()
    : : : : ' load the rtf and save the rtf if not exist.
    : : : : Select Case tstTripNo()
    : : : : Case "1"
    : : : : rtfJNarative.LoadFile "1.rtf", rtfRTF
    : : : : Case "11"
    : : : : rtfJNarative.LoadFile "11.rtf", rtfRTF
    : : : : End Select
    : : : : End Sub
    : : : :
    : : : : BUT it's doesn't work :(
    : : : :
    : : : What's tstTripNo ?!?!?!?!?!?!
    : : :tsttripno it the name of the textbox conytrol .... I typed it wrong should have been txtTripNo
    : :
    : :
    : :
    : :
    : :
    :
    : Change the first line of Select Case into "Select Case txtTripNo.Text"
    :
    :
    : Greets...
    : Richard
    :
    :
    Cheers richard that worked great. Can I ask if I have nothing in the rich text boxto start with then if I add text in there and I want it to save then I use;
    rftjnarative.savefile "C://blah/blah/2.rtf" ?



  • : :
    : Cheers richard that worked great. Can I ask if I have nothing in the rich text boxto start with then if I add text in there and I want it to save then I use;
    : rftjnarative.savefile "C://blah/blah/2.rtf" ?
    :

    That would work fine, though why do you have the '/' like that?

    Why not just: "C:BlahBlah2.rtf"?

    Greets...
    Richard

  • : : :
    : : Cheers richard that worked great. Can I ask if I have nothing in the rich text boxto start with then if I add text in there and I want it to save then I use;
    : : rftjnarative.savefile "C://blah/blah/2.rtf" ?
    : :
    :
    : That would work fine, though why do you have the '/' like that?
    :
    : Why not just: "C:BlahBlah2.rtf"?
    :
    : Greets...
    : Richard
    :
    :
    I guess I am too used to testing my website pages hence the / and not the


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories