Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 27th, 2007, 07:37 PM
Registered User
 
Join Date: Mar 2007
Location: North Highlands, Ca, USA.
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

Reply With Quote
  #2 (permalink)  
Old March 30th, 2007, 10:21 AM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
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?
Reply With Quote
  #3 (permalink)  
Old March 31st, 2007, 01:22 PM
Registered User
 
Join Date: Mar 2007
Location: North Highlands, Ca, USA.
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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:34 AM.


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