You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

1

Thursday, October 22nd 2009, 10:40am

Get, Put

hi @all,

in VB6, when opening a file in binary mode, you are able to read and write variables of userdefined types with Get and Put. To write binary data in Java you normally use the interface Serializable
in Jabaco/VB6 you are not able to implement Interfaces in ud-types. But every udt has a base class: VBTypeClass.

should we implement Serializable in it?

there is only one fallback when using Serializable: the written binary data is not compatible with the data written in VB

but we could program VBGet and VBPut with reflection and make it VB-compatible:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
Public Sub VBGet(Instream As java#io#DataInputStream, udtypevar As VBTypeClass)
   
   Dim f As java#lang#reflect#Field
   Dim fs() As java#lang#reflect#Field
   fs = udtypevar.getClass.getFields
   Dim n As String
   Dim i As Integer
   
   For i = 0 To Ubound(fs)
      f = fs(i)      
      If f.getType.isPrimitive Then
         n = f.getType.getName.toLowerCase
         Select Case True
         Case n = "byte"
            f.setByte(udtypevar, Instream.readByte)
         Case n = "char"
            f.setByte(udtypevar, Instream.readByte)
         Case n = "short"
            f.setShort(udtypevar, Instream.readShort)
         Case n = "int"
            f.setInt(udtypevar, CopyB(Instream.readShort))
         Case n = "long"
            f.setLong(udtypevar, Instream.readInt) 'CopyBytes(Instream.readInt))
         Case n = "float"
            f.setFloat(udtypevar, Instream.readFloat)
         Case n = "double"
            f.setDouble(udtypevar, Instream.readDouble)
         'Case Else
            '
         End Select
      Else
         'to do: implement Get for Arrays, objects         
      End If
   Next
End Sub
Private Function CopyB(s As Short) As Integer
   If s < 0 Then CopyB = &HFFFF0000 XOr s Else CopyB = s
End Function
Public Sub VBPut(OutStream As java#io#DataOutputStream, udtypevar As VBTypeClass)
   
   Dim f As java#lang#reflect#Field
   Dim fs() As java#lang#reflect#Field
   fs = udtypevar.getClass.getFields
   Dim n As String
   Dim i As Integer
   
   For i = 0 To Ubound(fs)
      f = fs(i)
      If f.getType.isPrimitive Then
         n = f.getType.getName.toLowerCase
         Select Case True
         Case n = "byte"
            OutStream.writeByte(f.getByte(udtypevar))
         Case n = "char"
            OutStream.writeChar(f.getChar(udtypevar))
         Case n = "short"
            OutStream.writeShort(f.getShort(udtypevar))
         Case n = "int"
            OutStream.writeShort(f.getInt(udtypevar))
         Case n = "long"
            OutStream.writeInt(f.getLong(udtypevar))
         Case n = "float"
            OutStream.writeFloat(f.getFloat(udtypevar))
         Case n = "double"
            OutStream.writeDouble(f.getDouble(udtypevar))
         Case n = "string"
            Dim s As String = Cast(f.get(udtypevar), String)
            OutStream.writeChars(s)
         'Case Else
            '
         End Select
      Else
         'to do: implement Put for Arrays, objects         
      End If
   Next
End Sub




OlimilO

Rate this thread
WoltLab Burning Board