QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: DeltaOscarSierra on August 29, 2021, 10:49:12 pm

Title: Enhancement Request - With Statement
Post by: DeltaOscarSierra on August 29, 2021, 10:49:12 pm
I used to be a big Visual Basic fan and occasionally still use the language. One statement that saved me a lot of repetetive typing is the "With" statement.

Using:
Code: QB64: [Select]
  1. Type myType
  2.    X as Integer
  3.    Y as Integer
  4. Dim myArray(9) as myType
  5.  

Code in QB64 currently looks like this:
Code: QB64: [Select]
  1. For X = 0 to Ubound(myArray)
  2.    myArray(X).X = 0
  3.    myArray(X).Y = 0
  4.  

But using a "With" statement the code would be simplified to:
Code: QB64: [Select]
  1. For X = 0 to Ubound(myArray)
  2.    With myArray(X)
  3.       .X = 0
  4.       .Y = 0
  5.    End With
  6.  

Here is a link to MS documentation concerning VB's With Statement: https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/with-end-with-statement

So this is an enhancement request to add such a feature to QB64, thank you!
Title: Re: Enhancement Request - With Statement
Post by: FellippeHeitor on August 29, 2021, 11:46:06 pm
Welcome aboard, @DeltaOscarSierra - thanks for the suggestion.
Title: Re: Enhancement Request - With Statement
Post by: Cobalt on August 30, 2021, 10:24:34 am
Now how is adding more code "simplified"?
Title: Re: Enhancement Request - With Statement
Post by: bplus on August 30, 2021, 10:41:44 am
Now how is adding more code "simplified"?

He is not looking for "simplified", he is looking to save on repetitive typing.

I myself Copy the text in question and use Paste. You can save on typing dots.
Title: Re: Enhancement Request - With Statement
Post by: doppler on August 30, 2021, 11:27:10 am
I see enrichment by using some of the visual basic structures and commands.  We have almost boxed ourselves into a corner (enhancement wise).  So let's steal a few good ideas from visual basic.  Why not!  Let's not take it all, just the ones people will use and make sense.

 
Title: Re: Enhancement Request - With Statement
Post by: SMcNeill on August 30, 2021, 11:29:17 am
He is not looking for "simplified", he is looking to save on repetitive typing.

I myself Copy the text in question and use Paste. You can save on typing dots.

Where it can really help is with large custom data types, and descriptive variable names:

With CustomerDatabase(CurrentDatabase)
    .Name = “Steve”
    .Age = 50
    .Sex = “Not Often Enough”
    .Phone = “None”
End With

Instead of typing CustomerDatabase(CurrentDatabase) multiple times, and possibly generating a typo (like your terrain demo the other day), you just With it once and it automatically associates everything to the End With as starting with whatever you told it to.



Often, if I’m working with a long program, I set up my keyboard to shortcut these things for me, already.  It’s Fn + C, for example, to insert CustomerDatabase(, and Fn + D to insert CurrentDatabase, so I’d just type Fn + C, Fn + D to insert CustomerDatabase(CurrentDatabase into my code — though I could easily see where WITH would be easier to remember and use in the long run.  I’m always forgetting what the heck the shortcut keys were for past projects…