Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question on data typing

Status
Not open for further replies.

Gafling

Programmer
Nov 7, 2000
44
US
Problem: Write a file of 100 byte records either as binary or text. Use the 'CrLfFlag' flag to determine the output format.

Code:
Type RecordVType
  Data As String * 100
  Cr As Byte
  Lf As Byte
End Type
Dim RecordVRecd As RecordVType

Type RecordFType
  Data As String * 100
End Type
Dim RecordFRecd As RecordFType

   
Type Record1Type
  Data As String * 50
  Data As String * 50
End Type
Dim Record1Recd As Record1Type
   
Type Record2Type
  Data As String * 25
  Data As String * 35
  Data As String * 15
  Data As String * 25
End Type
Dim Record2Recd As Record2Type

Type Record3Type
  Data As String * 16
  Data As String * 34
  Data As String * 38
  Data As String * 12
End Type
Dim Record3Recd As Record3Type

...
'
' OPEN code ...
    If CrLfFlag Then
       Open "TestFile" For Output As #1 Len = Len(RecordVRecd)
    Else
       Open "TestFile" For Binary As #1 Len = Len(RecordFRecd)
    End If
'
' WRITE code
    If CrLfFlag Then
       Put #1, , RecordVRecd
    Else
       Put #1, , RecordFRecd
    End If

WIP: Using the above data definitions:
1. transfer data from 'Record1Recd', or 'Record2Recd', or 'Record3Recd'
to either 'RecordVRecd' or 'RecordFRecd'

2. write to "TestFile" from either 'RecordVRecd' or 'RecordFRecd'

The question: how can I accomplish item number 1 above?

This does not work:
Code:
    If CrLfFlag Then
       RecordVRecd = Record1Recd
       RecordVRecd.Cr = Asc("13")
       RecordVRecd.Cr = Asc("10")
    Else
       RecordFRecd = Record1Recd
    End If
'
' Now do the WRITE ...

This type of data transfer is a no-brainer in 'c' or COBOL. Why is it a problem in VBA? I'm sure I have misunderstood something, but what ...?

Thanks in advance, all.
 
Some homework ?
Anyway, replace this:
RecordVRecd.Cr = Asc("13")
RecordVRecd.Cr = Asc("10")
By this:
RecordVRecd.Cr = Chr(13) ' or vbCr
RecordVRecd.Lf = Chr(10) ' or vbLf


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV - not sure what you mean by 'homework' ... anyway thanks for the correction on 'vbCr' etc.

I see now that I was not clear; that was not the issue ... the line
Code:
       RecordVRecd = Record1Recd
is the problem. I am getting a mismatched type error, 13 I believe. VB will not let me transfer the contents of 'Record1Recd' to 'RecordVRecd' or 'RecordFRecd'. I was looking for a way to copy the contents of a particular type to the storage area of another type. VB does not have type casting as in 'c'; I could use a 'memcpy'. In COBOL, a simple MOVE would do it. So the real question is, how does one do this in VBA?

BTW, it is a rhetorical question now ... I used a different solution. Time is money, don'cha know ...
 
Gafling,
Check out the RSet command. Not the part about right justifying, but the part about moving data into a random file buffer. It seems like that may be what you're lacking.
Tranman
 
Tranman ... 'RSet' is not allowed on user defined data types. However, thanks to your hint, I noticed that 'LSet' does allow mixed typing. Actually that makes sense.

If I need this again, I'll use 'LSet'.

Thanks!
 
Yeah, LSet. What I meant, not what I said...:).

Tranman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top