News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Dim somearray() As TYPE(anothervariable)

Started by jj2007, May 10, 2019, 08:40:58 PM

Previous topic - Next topic

jj2007

With FreeBasic, you can DIM an array based on the TYPE of another variable:
Dim MyInt As integer
Dim MySingle As Single
Dim MyDouble As Double

Dim 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":
include \masm32\MasmBasic\MasmBasic.inc
include 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
  Inkey
EndOfCode


Works like a charm:
R4      R8      SWORDs  RECTs
-9.638  -726.6  10214   301
-95.35  125.0   5038    343
17.84   376.0   9119    1148
... etc ...


One more from the series "absolutely useless features" 8)

HSE

#1
Hi JJ!

  Very interesting  :t.

Apparently MasmBasic don't work anymore with AsmC.

Code in Zip work with UASM32 (see picture  :biggrin:).

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??
Equations in Assembly: SmplMath

jj2007

#2
Quote from: HSE on May 11, 2019, 12:00:08 AMApparently 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:
OPT_Assembler AsmC
OPT_DebugA /Zne


QuoteRichMasm open UASM64 page if I push "No" button. You dont't know how to make a dialog??

Which is very surprising, of course 8)

jj2007

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

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.
Equations in Assembly: SmplMath

jj2007

Download the archive in my previous post, and you will see that the colours are saved with the file.

HSE

#6
Quote from: jj2007 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.

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.
Equations in Assembly: SmplMath

jj2007

Quote from: HSE on May 11, 2019, 08:48:51 AMIn 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

Quote from: jj2007 on May 11, 2019, 01:57:44 PM
, but what you are suggesting is a pretty dirty hack.
No. I'm not suggesting that. It's your dirty mind :biggrin:

Quote from: jj2007 on May 11, 2019, 01:57:44 PM
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.
Equations in Assembly: SmplMath

jj2007

Quote from: HSE on May 12, 2019, 01:31:47 AMFantastic! 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 :bgrin: