Author Topic: Initializing Variables  (Read 190 times)

Robert

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
Initializing Variables
« on: May 25, 2021, 02:40:03 PM »
Does anyone know the user defined initialization rules for variables in a declaration?

Code: [Select]
Dim As Integer IsGood = 10
translates correctly

Code: [Select]
Dim IsNoGood As Integer = 10
does not translate correctly.

I haven't tried other data types yet.
« Last Edit: May 25, 2021, 03:19:33 PM by Robert »

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 959
    • View Profile
Re: Initializing Variables
« Reply #1 on: May 25, 2021, 03:32:17 PM »
Robert,

The following works for locals and globals:

DIM  IsAlsoGood  = 10 AS Integer




Robert

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
Re: Initializing Variables
« Reply #2 on: May 25, 2021, 03:41:51 PM »
Robert,

The following works for locals and globals:

DIM  IsAlsoGood  = 10 AS Integer

Good.

With two examples, the logic is more obvious. VariableName = Value.


MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 959
    • View Profile
Re: Initializing Variables
« Reply #3 on: May 25, 2021, 04:25:03 PM »
I'm assuming one of the other BCX maintainers modeled the "DIM AS ..." after FreeBasic,
as that's the only other place I've seen that syntax used.

Robert

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
Re: Initializing Variables
« Reply #4 on: July 16, 2021, 04:28:47 PM »
I'm assuming one of the other BCX maintainers modeled the "DIM AS ..." after FreeBasic,
as that's the only other place I've seen that syntax used.

Suppose that there is a C declaration that is to be converted to BCX

       HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE), hOutput = GetStdHandle(STD_OUTPUT_HANDLE);

Wayne Halsdorf's 2011/01/07 implementation in BCX 6.5.0 Alpha RC1, of what he called "forward propagation of variable type", allows BCX to do this

DIM AS HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE), hOutput = GetStdHandle(STD_OUTPUT_HANDLE)

simply add DIM AS and remove the semicolon in the C code, instead of coding this

DIM hInput AS HANDLE
hInput = GetStdHandle(STD_INPUT_HANDLE)
DIM hOutput AS HANDLE
hOutput = GetStdHandle(STD_OUTPUT_HANDLE)

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 959
    • View Profile
Re: Initializing Variables
« Reply #5 on: July 16, 2021, 04:57:53 PM »
Hi Robert,

I was aware of most of that and I am a fan of the forward propagation implementation. 

I've just been coding it the traditional way for too long to break out of the habit.

Lucky for us, BCX lets us have our cake and eat it too.

« Last Edit: July 16, 2021, 05:31:03 PM by MrBcx »