Author Topic: MasmBasic  (Read 143058 times)

Gunther

  • Member
  • *****
  • Posts: 3515
  • Forgive your enemies, but never forget their names
Re: MasmBasic - a fast and easy-to-use library
« Reply #45 on: March 04, 2013, 06:45:06 PM »
Thank you, Jochen.  :t

Gunther
Get your facts first, and then you can distort them.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7546
  • Assembler is fun ;-)
    • MasmBasic
Bug warning
« Reply #46 on: March 06, 2013, 10:32:46 AM »
Version 6 March uploaded here. It fixes a nasty little bug in the ArrayRead macro (the wrong file was closed). Usage:

        Dim rc4() As REAL4   ; can be REAL4, REAL8, DWORD, ... structures
        ArrayRead rc4(), "MyReal4.dat"

To compensate for this bug :redface:, I added ArrayMean:

                        ArrayMean MyR8()                            ; all array elements are added up, then the sum is divided by the count
                        Print Str$("Resall=\t%f\n", ST(0))      ; the resulting mean is left on the FPU
                        fstp st
                        ArrayMean MyR8(XY)                        ; same as before but we assume the array consists of x,y pairs
                        Print Str$("ResY=\t%f\n", ST(0))       ; the mean of the Y elements is returned in ST(0)
                        fstp st
                        Print Str$("ResX=\t%f\n", ST(0))       ; the mean of the X elements is returned in ST(1)
                        fstp st
Rem        returns mean(s) on the FPU and total number of elements in eax

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7546
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #47 on: March 24, 2013, 11:35:40 AM »
Version 24 March uploaded (download: top of thread)

New functions are ArraySet, SetPoly3 and GetPoly3, see example below and \Masm32\MasmBasic\MbGuide.rtf

As shown in the repeat loop below, AllPts(ecx+1) is now valid syntax (same for string arrays)

include \masm32\MasmBasic\MasmBasic.inc        ; download
        Init
        Dim My3Pts(5) As DWORD                ; create an array with 3 XY pairs, i.e. 6 elements (0 .. 5)
        ArraySet My3Pts() = 1, 100, 2, 300, 4, 150        ; assign XY values (ArraySet can be handy but any other array works, too)
        SetPoly3 My3Pts()                ; create coefficients for a 3-point polynomial, i.e. Y=a0+a1*X+a2*X2
        Dim AllPts(11) As REAL4                ; create a destination array with 12 elements
        Print "N", Tb$, "X", Tb$, "Y", Tb$, "Y(ecx)"        ; the last column uses the "direct" variant GetPoly3(X)
        GetPoly3(AllPts())                ; fill starting from X=0, create coefficients for Y=a0+a1*X+a2*X2
        add eax, eax
        push eax
        xor ecx, ecx
        .Repeat                ; print N, X, Y=f(x), Y=f(2*X)
                Print Str$("\n%i\t", ecx/2), Str$("%2f\t", AllPts(ecx)), Str$("%3f\t", AllPts(ecx+1)), Str$("%3f", GetPoly3(ecx))
                fstp st                ; pop the return value from the FPU
                add ecx, 2
        .Until ecx>=stack
        pop eax
        Inkey CrLf$, "ok"
        Exit
end start

Output:
N       X       Y       Y(ecx)
0       0.0     -283.0  -283.0
1       1.0     100.0   300.0
2       2.0     300.0   150.0
3       3.0     317.0   -733.0
4       4.0     150.0   -2.35e+03
5       5.0     -200.0  -4.70e+03


jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7546
  • Assembler is fun ;-)
    • MasmBasic
DDE interface for Excel
« Reply #48 on: April 01, 2013, 11:19:22 AM »
Latest addition to MasmBasic is an interface to Excel - more in the Easter Egg thread.

Note that when you use the File, New Masm source menu in RichMasm, the interface is offered here:
Client & server                example for InterProcessCommunication (IPC)
Masm2Excel                an easy-to-use DDE interface to MS Excel
MasmBasic console app        more examples using BASIC syntax

However, the MB archive is at the 512kB limit, therefore I couldn't squeeze it in. Extract Masm2Excel.asc from post #1 of the Easter Egg thread to \Masm32\RichMasm\Res\Masm2Excel.asc to add this sample to the templates.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7546
  • Assembler is fun ;-)
    • MasmBasic
Excel and DDE: No undo
« Reply #49 on: April 04, 2013, 05:35:33 PM »
With version 5 April, the xlsHotlink macro works now just fine :biggrin:
A little warning: All macros that write to Excel, whether VBA or XLA or MasmBasic, do not preserve the previous state, i.e. there is no undo. If you really need undo, use xlsRead$("yourselection") and handle it manually.

include \masm32\MasmBasic\MasmBasic.inc        ; download
  Init
  xlsConnect                ; no args=Excel, System
  .if !Zero?                  ; non-zero means success
        xlsOpen "\Masm32\RichMasm\Res\LifeExOecd.xls"                ; we open a sample spreadsheet
        .if !Zero?                ; non-zero signals success
                ; xlsCommand "[app.activate()]"                  ; optional: activate Excel
                xlsConnect "LE Males at birth"                ; tell Excel to which sheet you want to talk
                .if !Zero?                ; non-zero signals success
                        .if rv(GetConsoleWindow)                ; you may print to the console...
                                ConsoleColor cBlack, cYellow        ; make the spaces visible that Excel exports
                                Print "Current selection=[", xlsRead$(), "]", CrLf$        ; no args means current selection
                        .else
                                ifdef hEdit                ; this section would be typical for a GUI application
                                    SetWin$ hEdit='R1C1:R9C5=['+xlsRead$("R1C1:R9C5")+']'+CrLf$                ; ... or set window content
                                    AddWin$ hEdit="Extract #2=["+xlsRead$('R9C1:R12C5')+"]"+CrLf$                ; and add bits & pieces
                                    xlsHotlink "R5C1:R38C2", hEdit        ; see how user modifies a selected area
                                endif
                        .endif
                        ; writing is possible but attention, there is no undo (as for all modifications done by Excel macros)
                        xlsWrite "R1C1", Cat$("This sheet was modified on "+Date$+", "+Time$)
                .endif
                xlsClose 0                ; close the file without saving (0=don't save, 1=save, no arg: ask)
        .endif
        xlsDisconnect                ; say bye to Excel
  .endif
  Inkey "ok"
  Exit
end start

Gunther

  • Member
  • *****
  • Posts: 3515
  • Forgive your enemies, but never forget their names
Re: MasmBasic - a fast and easy-to-use library
« Reply #50 on: April 04, 2013, 08:52:07 PM »
Jochen,

looks like a rock solid work.  :t

Gunther
Get your facts first, and then you can distort them.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7546
  • Assembler is fun ;-)
    • MasmBasic
Excel and DDE: help files
« Reply #51 on: April 04, 2013, 09:44:42 PM »
Danke, Gunther :icon14:

Although DDE is an old technology, there are some arguments for using it - it's fast, lightweight, and there is no "version hell" as (reportedly) with the alternative COM technology. What I really needed was pulling tables programmatically out of an Excel file - sounds simple but if you don't want the user to install add-ins (with all the nice warnings about untrusted software etc), then DDE is probably the only option.

One problem is the documentation; DDE uses the old Excel 4.0 macro language, the only official source is "MacroFun.hlp" from Microsoft Support.

ToutEnMasm

  • Member
  • *****
  • Posts: 1189
    • EditMasm
Re: MasmBasic - a fast and easy-to-use library
« Reply #52 on: April 05, 2013, 12:11:21 AM »
Quote
What I really needed was pulling tables programmatically out of an Excel file

If it is just for that,ODBC is better (same language since ....)
Fa is a musical note to play with CL

japheth

  • Guest
Re: MasmBasic - a fast and easy-to-use library
« Reply #53 on: April 05, 2013, 12:19:18 AM »
If it is just for that,ODBC is better (same language since ....)

What is better with ODBC?

- DDE  = dinosaur technology
- COM/OLE = pleistocene
- ODBC = ??? (  perhaps eocene? )

ToutEnMasm

  • Member
  • *****
  • Posts: 1189
    • EditMasm
Re: MasmBasic - a fast and easy-to-use library
« Reply #54 on: April 05, 2013, 12:57:11 AM »
Quote
What is better with ODBC?
The Use of sql with it , simplify the work.
Simple to use,you don't need to know all the langage.
Access can generate SQL for you.

http://msdn.microsoft.com/en-us/library/bb545450.aspx
2012 isn't so old.



Fa is a musical note to play with CL

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic - a fast and easy-to-use library
« Reply #55 on: April 05, 2013, 01:12:29 AM »
i mentioned in the other thread that i had to have Excel for a business client
what i did at the time was - Save Special (without the cell formulas) - Save As CSV
then, i wrote a csv2bin program in 16-bit code   :P

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7546
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #56 on: April 05, 2013, 02:06:37 AM »
Quote
What I really needed was pulling tables programmatically out of an Excel file

If it is just for that,ODBC is better (same language since ....)

Hi Yves,

Please show me. Write a little example  - just extracting a table by RnCn:RmCm coordinates.
The testfile is at \Masm32\RichMasm\Res\LifeExOECD.xls

 :t

ToutEnMasm

  • Member
  • *****
  • Posts: 1189
    • EditMasm
Re: MasmBasic - a fast and easy-to-use library
« Reply #57 on: April 05, 2013, 03:13:47 AM »

The file is not a database.
A database had columns titles on the first line.
Do it and no more problems.
Fa is a musical note to play with CL

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7546
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #58 on: April 05, 2013, 04:32:41 AM »
If it is just for that,ODBC is better (same language since ....)

There is an old German proverb: Wer gackert muss auch legen. Free translation "He who cackles must lay an egg".

Waiting for your sample code showing that "ODBC is better", Yves :biggrin:

(the requirement is very simple, "get data out of Excel without the user having to install an add-in or a macro; establish a hotlink so that Excel sends data to your proggie every time the Excel user has changed a cell". It would also nice to preserve the formatting as shown in the attached example - source in \Masm32\RichMasm\Res\XlsViewer.asc. If you change the ending to .edm, you can even view it in EditMasm, as it's RTF...)

ToutEnMasm

  • Member
  • *****
  • Posts: 1189
    • EditMasm
Re: MasmBasic - a fast and easy-to-use library
« Reply #59 on: April 05, 2013, 05:45:48 AM »

Quote
What I really needed was pulling tables programmatically out of an Excel file
For That,not for all thing you want to do.

Fa is a musical note to play with CL