help Converting VB.net to FreeBASIC

General FreeBASIC programming questions.
Post Reply
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

help Converting VB.net to FreeBASIC

Post by Gablea »

Hi everyone

Can some one help me out here I am trying to convet some VB.net code into FreeBASIC and I keep getting this complier error message

Code: Select all

C:\Program Files (x86)\FreeBASIC\fbc -g -s gui "TouchPoS.bas"
C:\Users\andy_gable\Documents\FreeBASIC Items\TouchPoS\vatsummary.bi(138) error 20: Type mismatch, found ')' in 'VAT_NetLocal = (VAT_GrossLocal / LocalVATValue)'
C:\Users\andy_gable\Documents\FreeBASIC Items\TouchPoS\vatsummary.bi(253) error 20: Type mismatch in 'VAT_NetLocal = VAT_GrossLocal / LocalVATValue'
not sure what it means this is my code

Code: Select all

	#Include Once "vbcompat.bi"	
	#Include Once "mysql\mysql.bi"
	#define NULL 0

   Dim Shared FeildLength 				As Integer
   Dim Shared FeildSpaces 				As Integer
   Dim Shared LocalVATPrint 			As String
   Dim Shared LocalVATValue 			As String
   Dim Shared LocalVATName 			As String
   Dim Shared LocalVATValuePrint 	As String
        
   Dim Shared FeildItem 				As String
   Dim Shared VAT_NetLocal 			As long
   Dim Shared VAT_VATLocal 			As Long
   Dim Shared VAT_GrossLocal 			As Long     
    
    Declare Sub CreateVATBox_New
    Declare Sub CreateVATSlip_New
    
    declare Sub CreateVATBox_Old
    Declare Sub CreateVATSlip_Old
    
    Declare Sub RepeatChrsVATRecipit(ByVal Number As Integer, ByVal Characters As String)
    Declare Sub FindVATDescription(ByVal VatCode As String)
    
Public Sub VATSummary_Recipit()
        'get the VATDATA from the database for each item

        Select Case VATSummaryStyle
            Case "New"
                CreateVATBox_New()
                CreateVATSlip_New()

            Case "Old"
                CreateVATBox_Old()
                CreateVATSlip_Old()

        End Select

        ReportData += Enter_LineFeed
        ReportData += LocalVATPrint

End Sub

Private Sub CreateVATBox_New()
        Dim Length1 As Integer = 0
        Dim Length2 As Integer = 0

        LocalVATPrint = ""
        '╔═══════════════════════════════╗
        LocalVATPrint += Printer_AlignLeft & Printer_Font_Normal & Chr(201)
        RepeatChrsVATRecipit((PrinterWidth - 2), Chr(205))
        LocalVATPrint += Printer_AlignLeft & Printer_Font_Normal & Chr(187) & Enter_LineFeed

        '║              V A T    S U M M A R Y              ║
        Length1 = (Len("V A T  S U M M A R Y ") / 2)
        Length2 = ((PrinterWidth / 2) - 2 - Length1)
        LocalVATPrint += Printer_AlignLeft & Printer_Font_Normal & Chr(186)
        LocalVATPrint += Space(Abs(Length2)) & Printer_AlignLeft & Printer_Font_BoldDoubleWidth & "VAT SUMMARY"
        LocalVATPrint += Printer_AlignLeft & Printer_Font_Normal & Space(Abs(Length2))
        LocalVATPrint += Chr(186) & Enter_LineFeed

        '║            VAT Number : GB15641231231             ║
        Length1 = Len("VAT Number : " & VATNumber)
        Length2 = (PrinterWidth - 2 - Length1)
        LocalVATPrint += Printer_AlignLeft & Printer_Font_Normal & Chr(186)
        LocalVATPrint += Space(abs(Length2 / 2)) &Printer_AlignLeft & Printer_Font_Normal & "VAT Number : " & Printer_Font_NormalBold & VATNumber
        LocalVATPrint += Printer_AlignLeft & Printer_Font_Normal & Space(Abs(Length2 / 2))
        LocalVATPrint += Chr(186) & Enter_LineFeed


        '╠══════════════════════════════════════════════════╣
        '╠═══════════════════════════════╣
        LocalVATPrint += Printer_AlignLeft & Printer_Font_Normal & Chr(204)
        RepeatChrsVATRecipit((PrinterWidth - 2), Chr(205))
        LocalVATPrint += Printer_AlignLeft & Printer_Font_Normal & Chr(185) & Enter_LineFeed

'
        '║      DESCRIPTION        NET       VAT      GROSS  ║
        Length1 = (Len("DESCRIPTION") + Len("NET") + Len("VAT") + Len("GROSS"))
        Length2 = (PrinterWidth - 2 - Length1)
        Dim Length3 As Integer = Length2 / 3

        LocalVATPrint += Printer_AlignLeft & Printer_Font_Normal & Chr(186)
        LocalVATPrint += "DESCRIPTION" & Space(abs(Length3))
        LocalVATPrint += "NET" & Space(Abs(Length3))
        LocalVATPrint += "VAT" & Space(Abs(Length3))
        LocalVATPrint += "GROSS"
        LocalVATPrint += Chr(186) & Enter_LineFeed

    End Sub

Private Sub CreateVATSlip_New()
   Dim DatabaseConnStock		As MYSQL PTR
   Dim MySQLOutStock				As MYSQL_RES PTR
    
   Dim TotalColStock				As Integer
   Dim TotalRowStock				As Integer
   
   Dim CiRStock					As Integer
   Dim CiCStock					As Integer
   
	Dim SQLCommandLOCAL 			As String
		
 	

    SQLCommandLOCAL = vbNullString
	SQLCommandLOCAL += "select "
   SQLCommandLOCAL += "vatcode, "														'0
   SQLCommandLOCAL += "SUM(Cast(linetotal as numeric)) As vattotal "			'1
   SQLCommandLOCAL += "from currentsale_vat "
   SQLCommandLOCAL += "GROUP BY vatcode"

   DatabaseConnStock = mysql_init(NULL)

   If (DatabaseConnStock = 0) then Print "Error connecting to database"
   If mysql_real_connect(DatabaseConnStock, "127.0.0.1", LocalUser, LocalPassword, LocalDataBase, Val(LocalPortNumber), NULL, 0) = NULL then Print "Error - mysql_real_connect (Local Database - SAVE Data)"
   If mysql_query(DatabaseConnStock, SQLCommandLOCAL) then Print "Error - mysql_query"

   MySQLOutStock = mysql_store_result(DatabaseConnStock)

   If MySQLOutStock = 0 then Print "Error"
    
   TotalColStock = mysql_num_fields(MySQLOutStock)
   TotalRowStock = mysql_num_rows(MySQLOutStock)
    
	If TotalRowStock > 0 Then
  		For CiRStock = 0 to TotalRowStock -1 step 1
   		Row = mysql_fetch_row(MySQLOutStock)
         ' loop through the vat data and print the information at the bottom of the page
         	FindVATDescription(*Row[0])

            VAT_GrossLocal = *Row[1]

            VAT_NetLocal = (VAT_GrossLocal / LocalVATValue)
            VAT_VATLocal = (VAT_GrossLocal - VAT_NetLocal)

            ' Creates the data to print
            FeildItem = LocalVATValuePrint & "%"
            FeildLength = Len(FeildItem)
            FeildSpaces = (9 - FeildLength)
            VAT_Description = " " & *Row[0] & Space(FeildSpaces) & FeildItem


            'NET VAT (Exc VAT)
            FeildItem = Format((VAT_NetLocal / 100), "£#####0.00")
            FeildLength = Len(FeildItem)
            FeildSpaces = (9 - FeildLength)
            VAT_NET = Space(FeildSpaces) & strReplace(FeildItem, "£", TenderIconPrint)


            'VAT Amount
            FeildItem = Format((VAT_VATLocal / 100), "£#####0.00")
            FeildLength = Len(FeildItem)
            FeildSpaces = (9 - FeildLength)
            VAT_VAT = Space(FeildSpaces) & strReplace(FeildItem, "£", TenderIconPrint)


            'Gross VAT (Inc VAT)
            FeildItem = Format((VAT_GrossLocal / 100), "£#####0.00")
            FeildLength = Len(FeildItem)
            FeildSpaces = (11 - FeildLength)
            VAT_GROSS = Space(FeildSpaces) & strReplace(FeildItem, "£", TenderIconPrint)

            LocalVATPrint += Printer_AlignLeft & Printer_Font_Normal & Chr(186)
            LocalVATPrint += Printer_AlignLeft & Printer_Font_Normal & VAT_Description & VAT_NET & VAT_VAT & VAT_GROSS
            LocalVATPrint += Printer_AlignLeft & Printer_Font_Normal & Chr(186) & Enter_LineFeed

  		Next CirStock
	   mysql_free_result(MySQLOutStock)
	   mysql_close(DatabaseConnStock)	
	End If	

        LocalVATPrint += Printer_AlignLeft & Printer_Font_Normal & Chr(200)
        RepeatChrsVATRecipit((PrinterWidth - 2), Chr(205))
        LocalVATPrint += Printer_AlignLeft & Printer_Font_Normal & Chr(188) & Enter_LineFeed
    End Sub

Private Sub CreateVATBox_Old()
        Dim Length1 As Integer = 0
        Dim Length2 As Integer = 0

        LocalVATPrint = vbNullString

        '==================================================
        RepeatChrsVATRecipit(PrinterWidth, "-")
        LocalVATPrint += Enter_LineFeed

        '|              V A T    S U M M A R Y              |
        LocalVATPrint += ESC & "|cA" & ESC & "|2C" & "VAT SUMMARY" & Enter_LineFeed
        '|            VAT Number : GB15641231231            |
        LocalVATPrint += ESC & "|cA" & ESC & "|1C" & "VAT Number : " & ESC & "|bC" & VATNumber & Enter_LineFeed

        '|      DESCRIPTION        NET       VAT      GROSS |
        Length1 = (Len("DESCRIPTION") + Len("NET") + Len("VAT") + Len("GROSS"))
        Length2 = (PrinterWidth - Length1)
        Dim Length3 As Integer = Length2 / 3

        LocalVATPrint += ESC & "|cA" & ESC & "|1C" & "DESCRIPTION" & Space(Abs(Length3))
        LocalVATPrint += "NET" & Space(Abs(Length3))
        LocalVATPrint += "VAT" & Space(abs(Length3 - 1))
        LocalVATPrint += "GROSS" & Enter_LineFeed
    End Sub

Private Sub CreateVATSlip_Old()
   Dim DatabaseConnStock		As MYSQL PTR
   Dim MySQLOutStock				As MYSQL_RES PTR
    
   Dim TotalColStock				As Integer
   Dim TotalRowStock				As Integer
   
   Dim CiRStock					As Integer
   Dim CiCStock					As Integer
   
	Dim SQLCommandLOCAL 			As String
		
   Dim FeildItem 					As String = ""
   Dim VAT_NetLocal 				As Long
   Dim VAT_VATLocal 				As Long
   Dim VAT_GrossLocal 			As Long 
   
    SQLCommandLOCAL = vbNullString
	SQLCommandLOCAL += "select "
   SQLCommandLOCAL += "vatcode, "														'0
   SQLCommandLOCAL += "SUM(Cast(linetotal as numeric)) As vattotal "			'1
   SQLCommandLOCAL += "from currentsale_vat "
   SQLCommandLOCAL += "GROUP BY vatcode"

   DatabaseConnStock = mysql_init(NULL)

   If (DatabaseConnStock = 0) then Print "Error connecting to database"
   If mysql_real_connect(DatabaseConnStock, "127.0.0.1", LocalUser, LocalPassword, LocalDataBase, Val(LocalPortNumber), NULL, 0) = NULL then Print "Error - mysql_real_connect (Local Database - SAVE Data)"
   If mysql_query(DatabaseConnStock, SQLCommandLOCAL) then Print "Error - mysql_query"

   MySQLOutStock = mysql_store_result(DatabaseConnStock)

   If MySQLOutStock = 0 then Print "Error"
    
   TotalColStock = mysql_num_fields(MySQLOutStock)
   TotalRowStock = mysql_num_rows(MySQLOutStock)
    
	If TotalRowStock > 0 Then
  		For CiRStock = 0 to TotalRowStock -1 step 1
   		Row = mysql_fetch_row(MySQLOutStock)
         ' loop through the vat data and print the information at the bottom of the page
         	FindVATDescription(*Row[0])

            VAT_GrossLocal = *Row[1]

            VAT_NetLocal = VAT_GrossLocal / LocalVATValue
            VAT_VATLocal = VAT_GrossLocal - VAT_NetLocal

            ' Creates the data to print
            FeildItem = LocalVATValuePrint & "%"
            FeildLength = Len(FeildItem)
            FeildSpaces = (9 - FeildLength)
            VAT_Description = " " & *Row[0] & Space(FeildSpaces) & FeildItem


            'NET VAT (Exc VAT)
            FeildItem = Format((VAT_NetLocal / 100), "£#####0.00")
            FeildLength = Len(FeildItem)
            FeildSpaces = (9 - FeildLength)
            VAT_NET = Space(FeildSpaces) & strReplace(FeildItem, "£", TenderIconPrint)


            'VAT Amount
            FeildItem = Format((VAT_VATLocal / 100), "£#####0.00")
            FeildLength = Len(FeildItem)
            FeildSpaces = (9 - FeildLength)
            VAT_VAT = Space(FeildSpaces) & strReplace(FeildItem, "£", TenderIconPrint)


            'Gross VAT (Inc VAT)
            FeildItem = Format((VAT_GrossLocal / 100), "£#####0.00")
            FeildLength = Len(FeildItem)
            FeildSpaces = (11 - FeildLength)
            VAT_GROSS = Space(FeildSpaces) & strReplace(FeildItem, "£", TenderIconPrint)

            LocalVATPrint += Printer_AlignLeft & Printer_Font_Normal & "|"
            LocalVATPrint += Printer_AlignLeft & Printer_Font_Normal & VAT_Description & VAT_NET & VAT_VAT & VAT_GROSS
            LocalVATPrint += Printer_AlignLeft & Printer_Font_Normal & "|" & Enter_LineFeed

  		Next CirStock
	   mysql_free_result(MySQLOutStock)
	   mysql_close(DatabaseConnStock)	
	End If	

        LocalVATPrint += Printer_AlignLeft & Printer_Font_Normal & Chr(200)
        RepeatChrsVATRecipit((PrinterWidth - 2), Chr(205))
        LocalVATPrint += Printer_AlignLeft & Printer_Font_Normal & Chr(188) & Enter_LineFeed
End Sub

Private Sub RepeatChrsVATRecipit(ByVal Number As Integer, ByVal Characters As String)
  	Dim Counter As Integer
  	Dim Local_String As String = vbNullString

  	For Counter = 1 To Number
  		Local_String += Characters
  	Next
   	LocalVATPrint += Local_String
End Sub

Private Sub FindVATDescription(ByVal VatCode As String)
   Dim DatabaseConnStock		As MYSQL PTR
   Dim MySQLOutVAT				As MYSQL_RES PTR
    
   Dim TotalColStock				As Integer
   Dim TotalRowStock				As Integer
   
   Dim CiRStock					As Integer
   Dim CiCStock					As Integer
   
	Dim SQLCommandLOCAL 			As String
		
   Dim ValueOne 					As Long = 0
   Dim ValueTwo 					As long = 0


	SQLCommandLOCAL = ""
   SQLCommandLOCAL += "Select "
   SQLCommandLOCAL += "vatcode, "							'0
   SQLCommandLOCAL += "vatname, "							'1
   SQLCommandLOCAL += "VATValue "							'2
   SQLCommandLOCAL += "from vatdata "
   SQLCommandLOCAL += "Where vatcode='" & VatCode & "';"

   DatabaseConnStock = mysql_init(NULL)

   If (DatabaseConnStock = 0) then Print "Error connecting to database"
   If mysql_real_connect(DatabaseConnStock, "127.0.0.1", LocalUser, LocalPassword, LocalDataBase, Val(LocalPortNumber), NULL, 0) = NULL then Print "Error - mysql_real_connect (Local Database - SAVE Data)"
   If mysql_query(DatabaseConnStock, SQLCommandLOCAL) then Print "Error - mysql_query"

   MySQLOutVAT = mysql_store_result(DatabaseConnStock)

   If MySQLOutVAT = 0 then Print "Error"
    
   TotalColStock = mysql_num_fields(MySQLOutVAT)
   TotalRowStock = mysql_num_rows(MySQLOutVAT)
    
	Row = mysql_fetch_row(MySQLOutVAT)
			
	LocalVATName = *Row[1]
   LocalVATValuePrint = *Row[2]
	ValueOne = (Val(*Row[2]) / 100)
   ValueTwo = ValueOne + 1
   LocalVATValue = Format(ValueTwo, "####0.00")

	mysql_free_result(MySQLOutVAT)
	mysql_close(DatabaseConnStock)	

End Sub
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: help Converting VB.net to FreeBASIC

Post by Tourist Trap »

You need just some rest. Type mismatch means here that an operator cant find right arguments types. Indeed, you can't divide by a string for instance in the second error.
I suppose the first error has the same root. It's not a question of vb.net I think unless the operator has been overloaded to accept strings.
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: help Converting VB.net to FreeBASIC

Post by Gablea »

so I need to change the type

What i want to do was use Decimal but FreeBASIC does not have that one :(

What I need is this

Code: Select all

Dim ValueOne 					As Decimal = 0
Dim ValueTwo 					As Decimal = 0
but I am using

Code: Select all

Dim ValueOne 					As Long = 0
Dim ValueTwo 					As long = 0
Would that make any difference?
Last edited by Gablea on Jun 06, 2016 20:52, edited 1 time in total.
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: help Converting VB.net to FreeBASIC

Post by Tourist Trap »

Gablea wrote:so I need to change the type

What i want to do was use Decimal but FreeBASIC does not have that one :(
Srvaldez has showed a lib, gmp I think, that deals with advanced math. If I'm wrong here, there are libraries around here that provide that. Maybe you can ask for this. No need to make another topic, just edit your 1st post title. You need a kind of financial math lib, or math.

srvaldez has published the .bi files for this: https://gmplib.org/.
srvaldez
Posts: 3603
Joined: Sep 25, 2005 21:54

Re: help Converting VB.net to FreeBASIC

Post by srvaldez »

in windows you can use decimal, here's small example

Code: Select all

#include once "win/wtypes.bi"
#include once "win/unknwn.bi"
#include once "win/oleauto.bi"
'
Function StringToBSTR( cnv_string As ZString ) As BSTR
    Dim As BSTR sb
    Dim As integer length
    length = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, @cnv_string, -1, NULL, 0)
    sb=SysAllocStringLen(sb,length)
    MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, @cnv_string, -1, sb, length)
    Function = sb
    SysFreeString(sb)
End Function


function ReadBstr(Strng as bstr ptr) as string' By Fr34k
  dim as string result
  dim as integer length
  dim as zstring ptr buffer
  Result = "" 
  
  If Strng then
    length = WideCharToMultiByte(CP_ACP, 0, *Strng, -1, NULL, 0, NULL, NULL) 
    Buffer = Allocate(length) 
    
    If Buffer then
      WideCharToMultiByte(CP_ACP, 0, *Strng, -1, Buffer, length, NULL, NULL) 
      Result = *Buffer 
      deallocate(Buffer) 
    EndIf 
  EndIf 
  
  Return Result 
End function

dim as decimal x, y, z
dim as LCID lcid
dim as bstr st
dim as integer i
dim as double a=0.5,d=0.1

st=SysAllocStringLen(st,70)         'allocate memory for Bstr string
VarDecFromI4( 12345, @x )           'convert integer to decimal in x
x.scale=3                           'x=12.345
VarDecAdd( @x, @x, @y ) 'y=x+x
VarBstrFromDec( @y, lcid, 0, @st )  'convert decimal to Bstr string

print "integer value 12345 is scaled to 3 decimal places and then added to itself"
print "12.345 + 12.345 = ";ReadBstr(@st)'convert Bstr string to standard string and print
st=StringToBStr ("3.14159265358979323846264338328")
VarDecFromStr( st, lcid, 0, @x)     'convert the string st to decimal
VarDecAdd( @x, @x, @y )             'y=x+x
VarBstrFromDec( @y, lcid, 0, @st )  'convert y to Bstr string

print "Pi + Pi = ";ReadBstr(@st)                 'convert Bstr string to standard string and print

VarDecFromI4( 1, @x ) 
VarDecFromI4( 10, @z )
VarDecDiv( @x, @z, @z )
VarDecFromI4( 5, @x )
x.scale=1
print
print "accumulate decimal 0.5 to 1.1 step 0.1"
for i=5 to 10
    VarDecAdd( @x, @z, @x )         'x=x+z
    VarBstrFromDec( @x, lcid, 0, @st )
    print ReadBstr(@st)
next
print "accumulate double 0.5 to 1.1 step 0.1"
for i=5 to 10
    a=a+d
    print a
next
SysFreeString(st)                   'free the memory taken by st

print __fb_version__, __fb_build_date__
print "press RETURN to end "
sleep
you could overload the decimal functions to make it's use easier.
Last edited by srvaldez on Jun 16, 2016 12:58, edited 2 times in total.
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: help Converting VB.net to FreeBASIC

Post by Tourist Trap »

srvaldez wrote: you could overload the decimal functions to make it's use easier
Hi, rarely seen a forum so much responsive!
Nice tip here above. But as far as I know tbe software Gablea is working at is intended to reach linux platforms. I'm quite intrigated by gmp right now since the website mentions functions dedicated to empower decimal precision beyond C Doubles.
srvaldez
Posts: 3603
Joined: Sep 25, 2005 21:54

Re: help Converting VB.net to FreeBASIC

Post by srvaldez »

for monetary programs like what Gablea is writing I would recommend mpdecimal http://www.bytereef.org/mpdecimal/
it wouldn't be too hard to overload the math functions and it's cross platform.
Post Reply