Check out these differences between VB(.Net) and PureBasic

Everything else that doesn't fall into one of the other PB categories.
RobertSF
User
User
Posts: 61
Joined: Thu May 03, 2018 4:24 pm

Check out these differences between VB(.Net) and PureBasic

Post by RobertSF »

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.

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
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!
User avatar
Kiffi
Addict
Addict
Posts: 1504
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Check out these differences between VB(.Net) and PureBas

Post by Kiffi »

RobertSF wrote: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!
not really. This is my attempt using AddWithValue():

Code: Select all

Dim Query As String = "SELECT * FROM Users WHERE Login = @Login"

Using CN As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Desktop\pool.accdb")
	CN.Open()
	Using CMD As OleDbCommand = CN.CreateCommand
		CMD.CommandText = Query
		CMD.Parameters.AddWithValue("@Login", Environ("UserName"))
		Dim result As Object = CMD.ExecuteScalar
		If result Is Nothing Then
			Stop
		End If
	End Using
	CN.Close()
End Using
Greetings ... Peter
Hygge
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Check out these differences between VB(.Net) and PureBas

Post by Josh »

Did you ever test your code before publishing? I don't think so.
RobertSF wrote:

Code: Select all

; PureBasic
Dim qry.s = "SELECT * FROM Users WHERE Login = ?;"
Dim db.i = 1
Dim result.b
sorry for my bad english
RobertSF
User
User
Posts: 61
Joined: Thu May 03, 2018 4:24 pm

Re: Check out these differences between VB(.Net) and PureBas

Post by RobertSF »

Josh wrote:Did you ever test your code before publishing? I don't think so.
Oops, you caught me. I guess that makes my point wrong as well. Microsoft indeed is better than PureBasic. Yay!
RobertSF
User
User
Posts: 61
Joined: Thu May 03, 2018 4:24 pm

Re: Check out these differences between VB(.Net) and PureBas

Post by RobertSF »

Kiffi wrote:
RobertSF wrote: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!
not really. This is my attempt using AddWithValue():

Code: Select all

Dim Query As String = "SELECT * FROM Users WHERE Login = @Login"

Using CN As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Desktop\pool.accdb")
	CN.Open()
	Using CMD As OleDbCommand = CN.CreateCommand
		CMD.CommandText = Query
		CMD.Parameters.AddWithValue("@Login", Environ("UserName"))
		Dim result As Object = CMD.ExecuteScalar
		If result Is Nothing Then
			Stop
		End If
	End Using
	CN.Close()
End Using
Greetings ... Peter
Greetings. That doesn't exactly make VB more readable, though, does it?
User avatar
Kiffi
Addict
Addict
Posts: 1504
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Check out these differences between VB(.Net) and PureBas

Post by Kiffi »

RobertSF wrote:That doesn't exactly make VB more readable, though, does it?
It's a matter of taste.
Hygge
Post Reply