Computing.Net > Forums > Programming > GWBasic to VB number conversion

GWBasic to VB number conversion

Reply to Message Icon

Original Message
Name: Graham Eady
Date: October 20, 2005 at 02:18:04 Pacific
Subject: GWBasic to VB number conversion
OS: XP
CPU/Ram: Pentium4 256mb
Comment:

Have a number of GWbasic (BASCICA) programs using single precision number stored in 4 bytes in random files. Am now converting to VB but wish to retain backward compatibility with the old DOS programs. GW stored integers work OK in VB but not the single precision. Does anybody know how to do the conversion or at least how the numbers are stored in GW so I can do my own conversion.



Report Offensive Message For Removal

Response Number 1
Name: wizard-fred
Date: October 20, 2005 at 08:11:51 Pacific
Subject: GWBasic to VB number conversion
Reply: (edit)

I think you are looking for the CVx and MKx$ functions for converting MBF variables.


Report Offensive Follow Up For Removal

Response Number 2
Name: Graham Eady
Date: October 21, 2005 at 07:11:01 Pacific
Subject: GWBasic to VB number conversion
Reply: (edit)

Thanks for the reply I know that MKS$ and CVS handle single precision to and from string format in GWBasic but how do you convert a single precision number stored in a file by GWB using VB to retreive it.

Perhaps the code below will illustrate. Take this bit of GW code

10 OPEN PATH$+"CHEMICAL"FOR RANDOM ACCESS READ WRITE SHARED AS 2 LEN=1200
20 FIELD 2,4 AS ANUMBER$
30 LSET ANUMBER$=MKS$(200)
31 PUT 2,1
32 GET 2,1
33 PRINT CVS(ANUMBER$)
40 END

The number I get back is naturally 200. The following VB code however gives me -6.018531E-34 when addressing the same file

Private Type Chemicals
ANumber As Single
X As String * 1196
End Type
Private Chemicals As Chemicals

Private Sub Command1_Click()
Open Path & "A:CHEMICAL" For Random As 1 Len = 1200
Get 1, 1, Chemicals
Print Chemicals.ANumber
End Sub


That is the problem


Report Offensive Follow Up For Removal

Response Number 3
Name: wizard-fred
Date: October 21, 2005 at 11:57:22 Pacific
Subject: GWBasic to VB number conversion
Reply: (edit)

You have to the same conversion in VB also MKx$ before writing and CVx after reading.
Also you probably can't define A as NUMBER, it has to be a string that is to be converted.


Report Offensive Follow Up For Removal

Response Number 4
Name: wizard-fred
Date: October 21, 2005 at 15:14:29 Pacific
Subject: GWBasic to VB number conversion
Reply: (edit)

mks$ and mksmbf$ use different number formats. As does their complements cvs and cvsmbf. It is best to use the manual for examples and make sample programs to test. My response 2 refers to the wrong ones. I haven't programmed in GWBASIC since the compilers were produced. I have just used a little more space and stored all numbers as strings. (easier to visually read the data files, too many versions of BASIC's)


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: GWBasic to VB number conversion

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software