Author Topic: MasmBasic  (Read 345158 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 11549
  • Assembler is fun ;-)
    • MasmBasic
DDE interface for Excel
« Reply #45 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: 11549
  • Assembler is fun ;-)
    • MasmBasic
Excel and DDE: No undo
« Reply #46 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: 3723
  • Forgive your enemies, but never forget their names
Re: MasmBasic - a fast and easy-to-use library
« Reply #47 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: 11549
  • Assembler is fun ;-)
    • MasmBasic
Excel and DDE: help files
« Reply #48 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.

TouEnMasm

  • Member
  • *****
  • Posts: 1805
    • EditMasm
Re: MasmBasic - a fast and easy-to-use library
« Reply #49 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 #50 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? )

TouEnMasm

  • Member
  • *****
  • Posts: 1805
    • EditMasm
Re: MasmBasic - a fast and easy-to-use library
« Reply #51 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: 8829
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic - a fast and easy-to-use library
« Reply #52 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: 11549
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #53 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

TouEnMasm

  • Member
  • *****
  • Posts: 1805
    • EditMasm
Re: MasmBasic - a fast and easy-to-use library
« Reply #54 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: 11549
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #55 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...)

TouEnMasm

  • Member
  • *****
  • Posts: 1805
    • EditMasm
Re: MasmBasic - a fast and easy-to-use library
« Reply #56 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

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 11549
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #57 on: April 05, 2013, 05:53:12 AM »
Waiting for your sample code showing that "ODBC is better", Yves

japheth

  • Guest
Re: MasmBasic - a fast and easy-to-use library
« Reply #58 on: April 05, 2013, 06:48:44 AM »
Waiting for your sample code showing that "ODBC is better", Yves

I cannot see why he needs to provide "sample code" - that's an additional requirement imposed by you, troll!  :icon_mrgreen:

Actually, it is sufficient if a plausible reason is supplied that makes obvious - more or less -  that ODBC is at least in one aspect better than DDE.

One possible reason that comes into my mind is that DDE requires a window for communication, while ODBC does NOT requires this.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 11549
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #59 on: April 05, 2013, 07:31:39 AM »
One possible reason that comes into my mind is that DDE requires a window for communication, while ODBC does NOT requires this.

Thanks for this clarification, Andreas. I wonder, though, why the attached executable works - must be an invisible window then  ::)

Source is in \Masm32\RichMasm\Res\Masm2Excel.asc, the Excel sheet at \Masm32\RichMasm\Res\LifeExOECD.xls ;-)

Still waiting for demo code (or at least: arguments) why ODBC is better than DDE for grabbing data from an Excel sheet ;-)

EDIT: To complete the DDE interface, I added four new macros, ddeConnect, ddeDisconnect, ddeCommand and ddeRequest$(). This snippet shows the Firefox URL currently loaded, and if the user presses y, it opens a new page (code for MSIE attached):

include \masm32\MasmBasic\MasmBasic.inc        ; download
  Init
  ddeConnect "Firefox|WWW_GetWindowInfo"
  .if !Zero?
        PrintLine "Current URL= ", ddeRequest$("URL")
        ddeDisconnect
        Inkey "Open a new page (y)?"
        .if eax=="y"
                ddeConnect "Firefox|WWW_OpenURL"
                .if !Zero?
                        ddeCommand "http://masm32.com/board/index.php?action=unread"
                        ddeDisconnect
                .endif
        .endif
  .endif
  Inkey CrLf$, "bye"
  Exit
end start
« Last Edit: April 05, 2013, 10:00:08 AM by jj2007 »