Author Topic: Enhancement Request - With Statement  (Read 3565 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline DeltaOscarSierra

  • Newbie
  • Posts: 4
    • View Profile
    • Castor Studios
Enhancement Request - With Statement
« 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!

FellippeHeitor

  • Guest
Re: Enhancement Request - With Statement
« Reply #1 on: August 29, 2021, 11:46:06 pm »
Welcome aboard, @DeltaOscarSierra - thanks for the suggestion.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Enhancement Request - With Statement
« Reply #2 on: August 30, 2021, 10:24:34 am »
Now how is adding more code "simplified"?
Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Enhancement Request - With Statement
« Reply #3 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.
« Last Edit: August 30, 2021, 10:44:18 am by bplus »

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: Enhancement Request - With Statement
« Reply #4 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.

 

Marked as best answer by DeltaOscarSierra on September 09, 2021, 06:16:31 pm

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Enhancement Request - With Statement
« Reply #5 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…
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!