Check out these differences between VB(.Net) and PureBasic
Posted: Wed Jan 09, 2019 4:10 am
Let's say you want to know if a database query returns something or not. You have a table of users, and you want to know if the person logged into Windows has an entry in this table of users. If yes, the person is an existing user, and if no, then the person is new user. This is a common scenario, I'm sure you will agree.
There is actually not a big difference in the number of lines, but it's clear that the PureBasic code is more readable.
(Can you simplify the VB code? What I'm posting is the best of my efforts.)
But just look, to set a parameter. In PureBasic, you choose whether it's string or numeric and use the appropriate function -- SetDatabase[String/Long](internal database number, ordinal number of the parameter within the collection of parameters, parameter value). That's it.
In VB, you have to create an object of type Parameter, set the value of the parameter, and then add the parameter to the collection of parameters!
Code: Select all
' Visual Basic
Dim qry As String = "SELECT * FROM Users WHERE Login = ?;"
Dim connection As OleDbConnection = New OleDbConnection
connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Desktop\pool.accdb"
Dim cmd As OleDbCommand = New OleDbCommand(qry, connection)
cmd.Connection.Open()
Dim par As New OleDbParameter
par.Value = Environ("UserName")
cmd.Parameters.Add(par)
Dim result As Object = cmd.ExecuteScalar
cmd.Connection.Close()
If result Is Nothing Then
Stop
End If
Code: Select all
; PureBasic
Dim qry.s = "SELECT * FROM Users WHERE Login = ?;"
Dim db.i = 1
Dim result.b
UseODBC()
OpenDatabase(db, "dbPool")
SetDatabaseString(db, 0, UserName())
QueryDatabase(db, qry)
result = NextDatabaseRow(db)
CloseDatabase(db)
If result = 0
CallDebugger
EndIf
(Can you simplify the VB code? What I'm posting is the best of my efforts.)
But just look, to set a parameter. In PureBasic, you choose whether it's string or numeric and use the appropriate function -- SetDatabase[String/Long](internal database number, ordinal number of the parameter within the collection of parameters, parameter value). That's it.
In VB, you have to create an object of type Parameter, set the value of the parameter, and then add the parameter to the collection of parameters!