News:

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

Main Menu

Bug in MbSnippets

Started by jj2007, November 02, 2023, 08:51:50 PM

Previous topic - Next topic

jj2007

There is a glitch in \Masm32\MasmBasic\Res\MbSnippets.asc, line 624:
include \masm32\MasmBasic\MasmBasic.inc
; to run this demo, download the Excel package and extract the files to \Masm32\MasmBasic\Res\*
; click here to see a much more detailed demo, including writing formatted text to Excel
  Init ; ## get data from a spreadsheet ##
  xlsConnect ; no args=Excel, System
  .if !Zero?  ; non-zero means success
xlsOpen "\Masm32\MasmBasic\Res\LifeExOecd.xls" ; we open a sample spreadsheet
...

When selecting Init and hitting F6, lots of errors appear. To resolve the problem, move the include line after the two comments:

; to run this demo, download the Excel package and extract the files to \Masm32\MasmBasic\Res\*
; click here to see a much more detailed demo, including writing formatted text to Excel
include \masm32\MasmBasic\MasmBasic.inc
  Init ; ## get data from a spreadsheet ##
...

The reason for this problem is that RichMasm, if Init is selected, searches backwards a hundred chars or so until it finds an include line. The two comments were a bit longer ;-)

Corrected version attached.

NoCforMe

Aha, the old "SpecialCases" glitch ... I've programmed a few of those in my time ...
Assembly language programming should be fun. That's why I do it.

HSE

Quote from: jj2007 on November 02, 2023, 08:51:50 PMsearches backwards a hundred chars or so until it finds an include line.

:biggrin: Why don't begin from beginning?
Equations in Assembly: SmplMath

jj2007

Quote from: HSE on November 03, 2023, 07:29:53 AMWhy don't begin from beginning?

That is the standard build case when you hit F6 and Init is not selected.

The "select Init and build a snippet" feature allows to test snippets, i.e. short complete examples (usually 5-20 lines), by selecting Init and building what starts with the include line before Init and ends with end start or EndOfCode. The MbSnippets.asc source has over 100 of such snippets for quick testing of language elements. Here are four of them:

include \masm32\MasmBasic\MasmBasic.inc
  Init            ; ## simple loop ##
  Cls 9
  mov ebx, "A"
  Print "The alphabet from a loop: ", CrLf$
  .Repeat
    Let esi=esi+Chr$(ebx+32, " ")    ; +32: make a lowercase alphabet
    inc ebx
  .Until ebx>"Z"
  Print esi, CrLf$, Ltrim$(Mirror$(esi))    ; we need to trim it because the original ends with a space
  Exit
end start            ; exit process, then end of code - the usual way to quit Masm code

include \masm32\MasmBasic\MasmBasic.inc
  Init            ; ## Unicode file I/O ##
  Let esi=wCL$()
  .if wExist(esi)
    wOpen "I", #1, esi
    wLet edi=Input$(#1, Lof(#1))
    Close
    wMsgBox 0, edi, wCat$("Contents of "+LastFileName$+":"), MB_OK
  .else
    wMsgBox 0, esi, "No such file:", MB_OK
  .endif
EndOfCode    ; quit MasmBasic code (you may still use Exit to create space for other code below)

include \masm32\MasmBasic\MasmBasic.inc
  Init            ; ## nested For ... Next loops ##
  m2m eax, 5
  For_ ebx=0 To eax-1    ; using eax is allowed here
    For_ ecx=1 To ebx+ebx    ; the first iteration is 1 to 0 and will be rejected (2*ebx=0, 2, 4, ...)
        call MyTest
    Next
    Print
  Next
  Print "ok"
  Exit
MyTest proc
LOCAL ct
  For_ ct=0 To 9
    Print "*"
  Next  ct
  Print Str$("\tebx=%i, ", ebx), Str$("ecx=%i\n", ecx)
  ret
MyTest endp
EndOfCode

include \masm32\MasmBasic\MasmBasic.inc
  Init            ; ## COM demo: open Internet Explorer ##
  invoke OleInitialize, NULL
  .if eax==S_OK
    push Chr$("ru.wikipedia.org/wiki/Заглавная_страница")    ; Russian Wikipedia
    call MyBrowser
  .endif
  invoke OleUninitialize
  Exit
CLSID_IExplorer        GuidFromString("0002DF01-0000-0000-C000-000000000046")        ; either use quoted text syntax or...
IID_IWebBrowser2      GuidFromString({D30C1661-CDAF-11D0-8A3E-00C04FC9E26E})    ; ... paste copied registry key name
...

To identify the snippet, RichMasm goes back a few lines until it finds an include line that contains the string \MasmBasic\; then it searches forward until it hits end start or EndOfCode, and sends the snippet to TmpFile.asm to build it.

Many examples are also in the MasmBasic help file (in the Files menu) - here is a four-liner showing a GUID:

    include \masm32\MasmBasic\MasmBasic.inc
    Init        ; << select Init and hit F6 to test this snippet
    MsgBox 0, Cat$("A Guid: ["+Guid$()+"]"), "Hi", MB_OK
EndOfCode

Rem    returns a pointer to the string, plus a pointer to the GUID itself in edx

HSE

Quote from: jj2007 on November 03, 2023, 08:24:22 AMuntil it finds an include line that contains the string \MasmBasic\

Just sound more logic to select that line. 
Equations in Assembly: SmplMath

jj2007

Quote from: HSE on November 03, 2023, 08:51:45 AM
Quote from: jj2007 on November 03, 2023, 08:24:22 AMuntil it finds an include line that contains the string \MasmBasic\

Just sound more logic to select that line. 

Perhaps you are right. However, many of my projects have the string \MasmBasic\ in the path of files e.g. when using Recall or FileRead$ or a simple Open. If by accident a line with Open "I", #1, "\Masm32\MasmBasic\MbGuide.rc" is selected, RichMasm would mistakenly assume it was the include line; unlikely but not impossible. In contrast, the string Init (case-sensitive, full word) is pretty unique.

HSE

To search "MasmBasic.inc" is more complex than the reverse thing?
Equations in Assembly: SmplMath

jj2007

It's probably the same. Anyway, I double-click on Init and hit F6, and it works. Too late to change that feature - call it organically grown code, OGC ;-)

NoCforMe

But doesn't it make you a tiny bit embarassed to have to write up a bug report in your documentation? "Er, if you use Init with a snippet and have more than xxx bytes of comment text before it ...".

However, I can relate to your feeling of not wanting to go back and fix it. I hate stuff like that in my own code. The inertia to be overcome to sit down and fix it is considerable ...

Own the code, own the bugs.
Assembly language programming should be fun. That's why I do it.

jj2007

Quote from: NoCforMe on November 03, 2023, 11:23:49 AMBut doesn't it make you a tiny bit embarassed to have to write up a bug report

Embarassed? Not at all. It's a rarely used feature in an almost bug-free editor with a 24k lines source - and it works fine unless you do strange things. Wanna talk about SDK bugs? Or, worse, Micros*t MASM bugs?

Btw the "downloaded 0 times" under the top post tells me you are here just to make a fuss. You've lost interest in coding? Poor boy.

HSE

Equations in Assembly: SmplMath

NoCforMe

Quote from: jj2007 on November 03, 2023, 12:06:21 PM
Quote from: NoCforMe on November 03, 2023, 11:23:49 AMBut doesn't it make you a tiny bit embarassed to have to write up a bug report

Embarassed? Not at all. It's a rarely used feature in an almost bug-free editor with a 24k lines source - and it works fine unless you do strange things. Wanna talk about SDK bugs? Or, worse, Micros*t MASM bugs?

Btw the "downloaded 0 times" under the top post tells me you are here just to make a fuss. You've lost interest in coding? Poor boy.

Do I detect a bit of testiness in your reply? No need; as I've said before, I'm impressed with your IDE, a great addition to the arsenal of programming tools. It's just that MasmBasic isn't my cup of tea. Not that I consider my ways of working superior by any means, just more to my liking.

Hey, I just like making comments from the peanut gallery, like a lot of the other hue-mons here.

And don't worry, I do plenty of coding. I see you haven't commented on my toolbar BMP creator. No problemo, maybe it isn't your cup of tea. But I did have fun writing it.
Assembly language programming should be fun. That's why I do it.

jj2007

Quote from: NoCforMe on November 03, 2023, 02:49:00 PMI just like making comments from the peanut gallery, like a lot of the other hue-mons here.

Are you the one on the left? Then the right guy must be Héctor :biggrin:

QuoteI see you haven't commented on my toolbar BMP creator. No problemo, maybe it isn't your cup of tea. But I did have fun writing it.

Guess what? I even downloaded and tested it!

HSE

Quote from: jj2007 on November 03, 2023, 07:42:51 PM

 :biggrin:  You have mustache now JJ !!

I think you can't post selfies with a friend.  :eusa_naughty: 
Equations in Assembly: SmplMath

jj2007

Somebody said COM was complicated: 17 lines of code for opening Internet Explorer :cool:

include \masm32\MasmBasic\MasmBasic.inc
.code
CLSID_IExplorer      GuidFromString("0002DF01-0000-0000-C000-000000000046")   ; either use quoted text syntax or...
IID_IWebBrowser2     GuidFromString({D30C1661-CDAF-11D0-8A3E-00C04FC9E26E})   ; ... paste copied registry key name

MyBrowser proc url
LOCAL WebInterface
  .if rv(CoCreateInstance, addr CLSID_IExplorer, NULL, CLSCTX_LOCAL_SERVER, addr IID_IWebBrowser2, addr WebInterface)==S_OK
           CoInvoke WebInterface, IWebBrowserVtbl.put_StatusBar, VARIANT_TRUE   ; configure the browser
           CoInvoke WebInterface, IWebBrowserVtbl.put_Visible, VARIANT_TRUE
           CoInvoke WebInterface, IWebBrowserVtbl.Navigate, Ole$(url), 0, 0, 0, 0
  .endif
  ret
MyBrowser endp
  Init         ; ## COM demo: open Internet Explorer ##
  If_ rv(OleInitialize, NULL)==S_OK Then invoke MyBrowser, Chr$("ru.wikipedia.org/wiki/Заглавная_страница")   ; Russian Wikipedia
  invoke OleUninitialize
EndOfCode