Real Software Forums
http://forums.realsoftware.com/

Conversion from VB6
http://forums.realsoftware.com/viewtopic.php?f=13&t=45475
Page 1 of 1

Author:  Paulnz [ Sat Sep 29, 2012 4:11 pm ]
Post subject:  Conversion from VB6

The following are codes are from VB6, we want to rewrite our project in VBR
Please help with how to convert the following vb6 code, please.

Please help

thanks





Rem WORK TYPE DETAILS details the fields of each record

Type WTDETSRECTYPE
WTN As String * 25 ' Type description
WTLF As Integer
WTUT As Double
End Type

Global WTDETSREC As WTDETSRECTYPE
Global SEVEN As Integer
Global FWT As Integer

Sub MainProg()
Rem Open the file
FWT = 7
WTDETS$ = "C:\llwtdet.ran"
Open WTDETS$ For Random Access Read Write Shared As FWT Len = 35

Rem Read the 5th record
SEVEN = 5
Get FWT, SEVEN, WTDETSREC

Rem Assign new values to the fields and write modified record back to file
WTDETSREC.WTN = "New Name"
WTDETSREC.WTLF = 33
WTDETSREC.WTUT = 120.50
Put FWT, SEVEN, WTDETSREC
Close FWT

End Sub

Author:  DaveS [ Sat Sep 29, 2012 4:49 pm ]
Post subject:  Re: Conversion from VB6

your VB code creates a structure (UDT) called WTDETSRECTYPE

You have two choices with RS (actually you had the same two choices with VB)

One create a similar structure ...and the rest of your code works pretty much as is

Or (preferred) is create a CLASS instead


If you DIM all your "global" items in a module they will be PUBLIC to the application


Your "OPEN" statement needs to be replaced with code using a FOLDERITEM and TEXTINPUTSTREAM (which by the way is also how you would have to do it if you converted this from VB6 to VB.NET .... well "almost" the same....)

Author:  timhare [ Sat Sep 29, 2012 6:27 pm ]
Post subject:  Re: Conversion from VB6

Since the file is block-structured, I would recommend using an RB Structure to read/write the file. Use a FolderItem and BinaryStream for file I/O. You will have to calculate the byte offset instead of using a record number.

dim f as FolderItem = GetFolderItem("C:\llwtdet.ran")
dim b as BinaryStream = BinaryStream.Open(f, True)

// Read the 5th Record
b.Position = (5-1) * 35
WTDETSREC.StringValue(b.LittleEndian) = b.Read(35)

If you aren't doing anything complex with the data in your program, you can leave the data in the structure - it will be more familiar to you that way. As your program becomes more complex, a Class will be much more flexible. Read the data via the structure and load it into a class object. Or better, give your class a read method that you pass the binarystream and a record number.

HTH,
Tim

Author:  Paulnz [ Sat Sep 29, 2012 7:52 pm ]
Post subject:  Re: Conversion from VB6

Thank you Dave and Tim

We now understand alot more and we will most likely use the Folderitem and BinaryStream for our file I/O.

However we still do not know how to declare the equivalent RB Structure for WTDETSREC. Noting specifically that the structure contain a string of 25 character and the next 2 bytes is an integer and the last 8 bytes equal to a number.

I have tried the help and language reference with no success

Please help

Much Appreciated

Author:  timhare [ Sun Sep 30, 2012 1:39 am ]
Post subject:  Re: Conversion from VB6

Add a Module to your project (if you don't already have one). Open the module in the code editor (double click it in the Project tab) and add a Structure to the module. Change the name to WTDETSRECTYPE. Add fields to the structure using the + button.

WTN as String*25
WTLF as Integer
WTUT as Double

Then add a property to the module, WTDETSREC as WTDETSRECTYPE

Tim

Author:  silverpie [ Mon Oct 01, 2012 2:06 pm ]
Post subject:  Re: Conversion from VB6

Correction--integers default to four bytes, not two, in RB. To force a two-byte integer, declare it as an Int16 (or UInt16, if it's meant to be unsigned).

Author:  Paulnz [ Tue Oct 09, 2012 3:08 pm ]
Post subject:  Re: Conversion from VB6

Thank you Tim and Silverpie

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/