### Author Topic: Dim somearray() As TYPE(anothervariable)  (Read 1703 times)

#### jj2007

• Moderator
• Member
• Posts: 10442
• Assembler is fun ;-)
##### Dim somearray() As TYPE(anothervariable)
« on: May 10, 2019, 08:40:58 PM »
With FreeBasic, you can DIM an array based on the TYPE of another variable:
Code: [Select]
`Dim MyInt As integerDim MySingle As SingleDim MyDouble As DoubleDim MyIntArray(9) As TYPEOF(MyInt) Dim MySingleArray(9) As TYPEOF(MySingle) Dim MyDoubleArray(9) As TYPEOF(MyDouble)   For n as integer=0 To 9  MyIntArray(n)=n  MySingleArray(n)=n  MyDoubleArray(n)=n  Next  print "Integer=", MyIntArray(1)  print "Single=", MySingleArray(2)  print "Double=", MyDoubleArray(3)  sleep`
So I thought, "if FB can do that, Masm can do the same":
Code: [Select]
`include \masm32\MasmBasic\MasmBasic.incinclude DimAsType.inc  SetGlobals rc:RECT, words:SWORD, MyR4:REAL4, MyR8:REAL8  Init  Dim r4x() As TYPE(MyR4)  Dim r8x() As TYPE(MyR8)  Dim wordsarray() As TYPE(words)  Dim rectangles() As TYPE(rc)  For_ ecx=0 To 9 Rand(-100.0, 100.0, r4x(ecx)) Rand(-1000.0, 1000.0, r8x(ecx)) Rand(-32768, 32767, wordsarray(ecx)) Rand(0, 1366, rectangles(ecx, right))  Next  Print cfm\$("R4\tR8\tSWORDs\tRECTs")  For_ ecx=0 To 9 Print Str\$("\n%4f", r4x(ecx)) Print Str\$("\t%4f", r8x(ecx)) Print Str\$("\t%i", wordsarray(ecx)) Print Str\$("\t%i", rectangles(ecx, right))  Next  InkeyEndOfCode`
Works like a charm:
Code: [Select]
`R4      R8      SWORDs  RECTs-9.638  -726.6  10214   301-95.35  125.0   5038    34317.84   376.0   9119    1148... etc ...`
One more from the series "absolutely useless features" 8)

#### HSE

• Member
• Posts: 1342
• <AMD>< 7-32>
##### Re: Dim somearray() As TYPE(anothervariable)
« Reply #1 on: May 11, 2019, 12:00:08 AM »
Hi JJ!

Very interesting  :t.

Apparently MasmBasic don't work anymore with AsmC.

Code in Zip work with UASM32 (see picture  ).

Source code above also perfect (previously my mistake in the black part).

RichMasm open UASM64 page if I push "No" button. You dont't know how to make a dialog??
« Last Edit: May 11, 2019, 03:07:23 AM by HSE »

#### jj2007

• Moderator
• Member
• Posts: 10442
• Assembler is fun ;-)
##### Re: Dim somearray() As TYPE(anothervariable)
« Reply #2 on: May 11, 2019, 02:09:35 AM »
Apparently MasmBasic don't work anymore with AsmC.

At least with default settings, AsmC is no longer MASM-compatible. You can try to add these options at the end of the source:
Code: [Select]
`OPT_Assembler AsmCOPT_DebugA /Zne`
Quote
RichMasm open UASM64 page if I push "No" button. You dont't know how to make a dialog??

Which is very surprising, of course 8)
« Last Edit: May 11, 2019, 03:19:58 AM by jj2007 »

#### jj2007

• Moderator
• Member
• Posts: 10442
• Assembler is fun ;-)
##### Re: Dim somearray() As TYPE(anothervariable)
« Reply #3 on: May 11, 2019, 03:07:40 AM »
Re colours in RichMasm: Since about 1986, when I bought my first Atari ST, I have not used white on black any more. That is why it's not the default setting in RichMasm. But if needed, you can tweak it, see attachment.

#### HSE

• Member
• Posts: 1342
• <AMD>< 7-32>
##### Re: Dim somearray() As TYPE(anothervariable)
« Reply #4 on: May 11, 2019, 03:35:37 AM »
In theory is configurated in that way.

No easy solution. Only idea I have now  :idea: is to add a option (like OPT but for editor)  that store background and foreground colors when you save. When you open in other RichaMasm if that colors are different from colors in configuration, that colors are replaced.

#### jj2007

• Moderator
• Member
• Posts: 10442
• Assembler is fun ;-)
##### Re: Dim somearray() As TYPE(anothervariable)
« Reply #5 on: May 11, 2019, 06:23:53 AM »
Download the archive in my previous post, and you will see that the colours are saved with the file.

#### HSE

• Member
• Posts: 1342
• <AMD>< 7-32>
##### Re: Dim somearray() As TYPE(anothervariable)
« Reply #6 on: May 11, 2019, 08:48:51 AM »
Download the archive in my previous post, and you will see that the colours are saved with the file.

That's the problem: colours instead of scheme.
Correction:
In RTF there is an scheme, not colours. Of course, I still don't know how RichEdit could operate in the table of colours. Opening in a text editor is very easy.
« Last Edit: May 11, 2019, 10:32:34 AM by HSE »

#### jj2007

• Moderator
• Member
• Posts: 10442
• Assembler is fun ;-)
##### Re: Dim somearray() As TYPE(anothervariable)
« Reply #7 on: May 11, 2019, 01:57:44 PM »
In RTF there is an scheme, not colours. Of course, I still don't know how RichEdit could operate in the table of colours. Opening in a text editor is very easy.

Yes, there is a colour table in RTF files, but what you are suggesting is a pretty dirty hack.

I found another solution: The new version allows to convert any source to your preferred dark background scheme by
- typing Ctrl G, then
- udc=6
- back to the text, Ctrl A to select all
- twice Ctrl E
- to restore colour codes, Ctrl A plus twice F4

#### HSE

• Member
• Posts: 1342
• <AMD>< 7-32>
##### Re: Dim somearray() As TYPE(anothervariable)
« Reply #8 on: May 12, 2019, 01:31:47 AM »
, but what you are suggesting is a pretty dirty hack.
No. I'm not suggesting that. It's your dirty mind

I found another solution: The new version allows to convert any source to your preferred dark background scheme by
- typing Ctrl G, then
- udc=6
- back to the text, Ctrl A to select all
- twice Ctrl E
- to restore colour codes, Ctrl A plus twice F4

Fantastic! You only have to make that automatically when file open  :t.

#### jj2007

• Moderator
• Member
• Posts: 10442
• Assembler is fun ;-)
##### Re: Dim somearray() As TYPE(anothervariable)
« Reply #9 on: May 12, 2019, 03:52:47 AM »
Fantastic! You only have to make that automatically when file open  :t.

No way :P

But as written earlier, when you open one of the templates, you do that short procedure once, and the new settings get saved with the file. Next time you open the file, it will be in boring white on black