Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 27th, 2007, 07:37 PM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Combine rtf files with random access

Hi
I have a file open and save routine that is a udt containing a rtf file using random access. The udt file contains about 25 strings, longs, booleans and integers and the rtf file it is declared like this:
Public Type JobInfo
tmpLastname As String * 25
tmpFirstName As String * 20
tmpAddress As String * 45
tmpCity As String * 20
tmpState As String * 3
etc....
and the MyRTF As Long
End Type

Processed like this:
Public Sub SaveRandomData(ByVal sFilename As String, myData As udtRandomData, MyRTF As String)
Dim b() As Byte
Open sFilename For Binary As #1
Put #1, , myData
If myData.SizeRTF Then
b = MyRTF 'Cast string to Byte Array
Put #1, , b
End If
Close #1
End Sub

Public Sub LoadRandomData(ByVal sFilename As String, myData As udtRandomData, MyRTF As String)
Dim b() As Byte
Open sFilename For Binary As #1
Get #1, , myData
If myData.SizeRTF Then
ReDim b(myData.SizeRTF * 2 - 1) As Byte
Get #1, , b
MyRTF = b 'Cast byte array to string
End If
Close #1
End Sub

I got help writing the above code from EE
How can i modify these open and save subs to accept an additional RTF file?
Don't tell me to use a database
Thank you

 
Old March 30th, 2007, 10:21 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I hope you don’t mid if I make this easier to read:
Code:
Public Type JobInfo
    tmpLastname   As String * 25
    tmpFirstName  As String * 20
    tmpAddress    As String * 45
    tmpCity       As String * 20
    tmpState      As String * 3
    etc....
    and the MyRTF As Long
End Type
Processed like this:
Code:
Public Sub SaveRandomData(ByVal sFilename As String, _
                                myData As udtRandomData, _
                                MyRTF As String)
    Dim b() As Byte

    Open sFilename For Binary As #1
    Put #1, , myData

    If myData.SizeRTF Then
        b = MyRTF     ' Cast string to Byte Array
        Put #1, , b
    End If

    Close #1

End Sub

Public Sub LoadRandomData(ByVal sFilename As String, _
                                myData As udtRandomData, _
                                MyRTF As String)
    Dim b() As Byte

    Open sFilename For Binary As #1
    Get #1, , myData

    If myData.SizeRTF Then
        ReDim b(myData.SizeRTF * 2 - 1) As Byte
        Get #1, , b
        MyRTF = b      ' Cast byte array to string.
    End If
It is a bad idea to hardcode file numbers. You really should use FreeFile to obtain a known-good filenumber. reduces the potential for collisions...

I don't follow your question. Do you want to add an argument to the argument list of the sub(s)?

If that's it, you could add an optional argument (so you could add a value there sometimes, and not add it other times), and then test for the presence of a second value, and process accordingly.

Alternately, you could change the signature to
Code:
Public Sub LoadRandomData(ByVal sFilename As String, _
                                myData    As udtRandomData, _
                                MyRTF()   As String)
                                and count how many elements there are in the array, repeating the processing for each element.

What say you?
 
Old March 31st, 2007, 01:22 PM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your input, your suggestion would work
I have decided to combine my 2 rtf's and save as one
Then use rtf.find xxEndOfSectionOne






Similar Threads
Thread Thread Starter Forum Replies Last Post
restricting users to upload rtf or pdf files only sauravnimesh C# 2005 2 September 15th, 2007 04:08 AM
How to combine stuff from two XML-files? Lemminkäinen XSLT 4 June 15th, 2006 08:03 AM
Created RTF when try to open RTF, got an error not24 C# 0 March 31st, 2006 01:31 PM
display random record from access database jialin PHP Databases 1 December 2nd, 2005 09:18 PM
hyperlinks of rtf files geetabajpai VB How-To 1 October 13th, 2005 04:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.