Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Tue Sep 19, 2017 5:37 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Conversion from VB6
PostPosted: Sat Sep 29, 2012 4:11 pm 
Offline

Joined: Sat Sep 29, 2012 3:49 pm
Posts: 3
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Conversion from VB6
PostPosted: Sat Sep 29, 2012 4:49 pm 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
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....)

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Conversion from VB6
PostPosted: Sat Sep 29, 2012 6:27 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Conversion from VB6
PostPosted: Sat Sep 29, 2012 7:52 pm 
Offline

Joined: Sat Sep 29, 2012 3:49 pm
Posts: 3
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Conversion from VB6
PostPosted: Sun Sep 30, 2012 1:39 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Conversion from VB6
PostPosted: Mon Oct 01, 2012 2:06 pm 
Offline

Joined: Sat Oct 01, 2005 9:55 am
Posts: 527
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).


Top
 Profile  
Reply with quote  
 Post subject: Re: Conversion from VB6
PostPosted: Tue Oct 09, 2012 3:08 pm 
Offline

Joined: Sat Sep 29, 2012 3:49 pm
Posts: 3
Thank you Tim and Silverpie


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group