Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - jj2007

Pages: [1] 2 3 ... 12
1
Code and examples / Dynamic arrays
« on: 18. July 2019, 00:40:00 »
This example reads a text file that has the format Country   Series    Value1  Value 2 into a numeric matrix, i.e. a two-dimensional numeric array - useful for working with spreadsheets and tables. Project attached, MasmBasic of 16 July 2019 or later is required.

include \masm32\MasmBasic\MasmBasic.inc
  Init                                ; *** read values from a text file into a numeric array ***
  Recall "UnderFiveMortalityRate.tab", L$(), tab        ; tab-delimited text -> two-dimensional string array
  Clr ecx, edi                                          ; we need two counters
  Print "Under 5 mortality rate", CrLf$, L$(0, 0)       ; Country
  Print At(22) "  ", L$(0, 2), Tb$, L$(0, 3)            ; 1990, 2013
  QSort L$(), 0, 2003h                ; sort string array numerically by column 3
  Delete L$(0)                        ; we don't want the captions
  Dim Under5() As double              ; create a dynamic numeric array
  Dim StringIndex() As DWORD          ; and another one to keep track of the names
  .Repeat
        xor esi, esi                  ; column counter
        .Repeat
                MovVal <Under5(edi, esi)>, L$(ecx, esi+2)    ; assign values to the numeric array
                inc esi
        .Until edx==-127 || esi>=99     ; MovVal returns -127 in edx if no valid number was found
        .if esi>2
                mov StringIndex(edi), ecx       ; remember the country
                inc edi         ; advance numeric array row index only if at least two values found
        .endif
        inc ecx
  .Until ecx>=L$(?)             ; loop until strings are finished
  For_ ct=0 To Under5(?rows)-1
                Print Str$("\n%i\t", ct), L$(StringIndex(ct), 0)
                Print At(22) " "
                For_ ecx=0 To Under5(?cols)-1
                                Print Tb$, Str$("%4f", Under5(ct, ecx))
                Next
  Next
  PrintLine CrLf$
  deb 4, "total strings", L$(?)
  deb 4, "total numbers", Under5(?)
  deb 4, "valid rows", Under5(?rows)
  deb 4, "valid columns", Under5(?cols)
  Inkey "--- hit any key ---"
EndOfCode


Output:
Code: [Select]
Under 5 mortality rate
Country                 1990    2013
0       Iceland         6.400   2.100
1       Finland         6.700   2.600
2       Singapore       7.700   2.800
3       Sweden          6.900   3.000
4       Italy           9.600   3.600
5       Austria         9.500   3.900
6       Germany         8.500   3.900
7       Australia       9.200   4.000
8       France          9.000   4.200
9       Switzerland     8.200   4.200
10      Belgium         10.000  4.400
11      United Kingdom  9.300   4.600
12      Cuba            13.30   6.200
13      United States   11.20   6.900
14      Yemen           124.8   51.30
15      Zambia          192.5   87.40
16      Zimbabwe        74.60   88.50
17      Afghanistan     179.1   97.30

total strings   eaX             23
total numbers   eax             36
valid rows      eax             18
valid columns   eax             2

2
General questions and discussions / Re: Dir Walk Challenge
« on: 12. July 2019, 00:38:52 »
Wow! took awhile to give birth to an answer. ;-))

Apologies - I found your post by accident. I confess that I visit this forum only occasionally...

3
Offtopic / Re: here is a new challenger
« on: 21. June 2019, 13:44:56 »
Bonjour Floyd, bienvenu au forum! J'avais le ZX Spectrum et l'ATARI ST aussi. Tu as programmé en Gfa? Tu pourrais reconnaitre quelques commands ici ;-)

4
General questions and discussions / Re: Dir Walk Challenge
« on: 21. June 2019, 13:41:17 »
Nice to see MasmBasic in action again. Are the files coming out sorted automatically?

Hi B+,

No, GetFiles doesn't sort automatically, but SortFiles will do that, and it has quite a number of useful options.

5
Offtopic / Re: How nice...
« on: 16. May 2019, 20:48:35 »
Hi Aurel,

It's just a demo, so the data are arbitrary, and so is the text. The Chinese means, if you can trust google translate "plotting data is easy". The abscissa should be "electrotok", something like electric current. It's merely to demonstrate that this control uses Unicode.

6
Offtopic / Re: How nice...
« on: 16. May 2019, 05:59:32 »
this need for library's has me wodering how JJ and Paul handled this aspect with their respective versions of Basic.

I have implemented interfaces e.g. to the Gnu Scientific Library, Cairo, even Python, but I prefer to roll my own if possible. See below - pure Assembly, pardon: MasmBasic ;-)

include \masm32\MasmBasic\Res\MbGui.asm
  ArraySet current() As double=120, 125, 122, 119, 134, 138, 141, 159, 162, 178
  ArraySet voltage() As double=250, 210, 180, 155, 140, 125, 110, 100, 90, 80
  SetAxisX "Электроток", s 0, d 1/5, grid 1   ; s=start value, d=difference between gridlines
  SetAxisY "Voltage", s 0, d 5/5, grid 1
Event Paint
  ArrayPlotValues "%i V", 8, -12        ; format$, dx & dy positions
  ArrayPlot current():voltage(), RgbCol(0, 0, 255), lines=3
  ArrayPlot exit, "繪製科學數據非常容易!"
EndOfCode



7
Code and examples / Re: Fizz Buzz Plus
« on: 08. May 2019, 16:40:24 »

8
Community news and announcements / Re: MasmBasic
« on: 08. May 2019, 16:13:12 »
MasmBasic version 8 May 2019 features some improvements under the hood, plus more comfortable working with maps. Below a screenshot, these 14 lines of code are the source:

include \masm32\MasmBasic\Res\MbGui.asm
  GuiControl MyMap, "canvas", w660
  GuiControl TheManual, "richedit", res:92, x660, w340, bcol RgbCol(255, 255, 222)
  GuiControl Sbar, "statusbar", bcol RgbCol(255, 0, 0), wRec$("Click into a country / Нажмите в страну / 點擊進入一個國家 - this toolbar uses common controls version "+ComCtl32$()), font -16:FW_SEMIBOLD
  ArrayLoadMap 0, 90                    ; Europe.dmi and Europe.map in resources
  MapColours(0, "abcdefghiabcdefghiabcdefghiabcdefghiabcdefghiabcdefghi")      ; set colours to map 0 (a=red, i=green)
Event CanvasPaint
  ArrayPlot RgbCol(0, 240, 255)         ; init and set background colour
  PaintMap RgbCol(127, 127, 127), lines=2       ; map with grey borders 2px thick
  ArrayPlot exit, "Europe"
  GuiTextBox 99.0-120, 52.0, 120, 60, "This program requires the file Europe.map", bcol LiteGreen, font -18:FW_NORMAL
Event Message
  If_ uMsg_==WM_MAPCLICKED Then <SetWin$ hSbar=If?(MapRegion ge 0, "You clicked on "+MapRegion$, Time$)>
GuiEnd



9
Community news and announcements / Re: RIP retrogamecoding.org
« on: 29. April 2019, 22:49:14 »
The FreeBasic forum is pretty active. Even more so: VB

Some activity at MasmBasic, too.

10
Offtopic / Re: Stack Overflow Developer Survey 2019
« on: 22. April 2019, 13:50:35 »
Visual Basic is the most dreaded one (followed by Objective-C and Assembly)

Glad to see that my favourite language goes strong in at least one category :)

11
Community news and announcements / Re: MasmBasic
« on: 02. April 2019, 04:47:24 »


Source (67 lines of code) and data are attached; building requires MasmBasic version 2 April 2019 or later, plus the Masm32 SDK

12
Offtopic / Re: mini Linux distros
« on: 16. January 2019, 04:43:40 »
Linux is actually an interesting concept: You don't install an application as you would do in Windows. Instead, you download the source and compile it to install it. If the respective toolchain (C++?) for the 300+ Linux versions is compatible with all application sources, the concept could work just fine.

13
Offtopic / Re: M.C.
« on: 24. December 2018, 10:38:25 »
Happy Xmas, a Merry New Year and Basic Wishes to all of you ;-)

14
Community news and announcements / Re: MasmBasic
« on: 28. November 2018, 13:35:41 »
News from the MasmBasic subforum:



The source (requires the Masm32 SDK plus the MasmBasic library):

GuiParas equ "Plot sinus & cosinus curves", x600, y100, w600, h500, bRgbCol(192, 255, 255)
include \masm32\MasmBasic\Res\MbGui.asm
  Dim MySinus() As REAL4                       ; REAL4 precision is enough ...
  Dim MyCosinus() As REAL8                     ; ... but REAL8 is ok, too
  For_ ecx=0 To 359
        SetFloat MySinus(ecx)=Sinus(ecx)       ; fill an array
        SetFloat MyCosinus(ecx)=Cosinus(ecx)   ; you may use ArrayRead for reading data from a file
  Next
  MakeFont hHorzFont, Height:18, Weight:FW_SEMIBOLD, Italic:TRUE
  MakeFont hVertFont, Height:18, Weight:FW_SEMIBOLD, Escapement:900, Italic:FALSE
  MakePen hPenAxis, RgbCol(255, 0, 0)
  MakePen hPenGrid, RgbCol(255, 255, 222), width 2
  SetAxisX "degrees", s 0, d 15.0/3, grid 1, penx hPenAxis, peng hPenGrid, font hHorzFont, format "%i" ; s=start value, d=difference between gridlines
  SetAxisY "sinus & cosinus", s -1, d 0.2/5, grid 2, font hVertFont, format "%2f"
  $Data "Plotting an array of points is very easy: All you need is the array itself, plus a Paint event that draws it."
  $Data "The axes can be set using SetAxisX and SetAxisY, taking arguments as shown in the source. Now resize this window to see how it behaves"
  Read desc$()                          ; read a string array from $Data
  Event Paint
  ArrayPlot MySinus(), RgbCol(255, 222, 160), 2, 00000110h, 0, -1, 1    ; red sinus, 2px wide; use margins left top right bottom, min0, max-1, filled=1 ArrayPlot MyCosinus(), RgbCol(0, 0, 255)             ; plot the cosinus array in blue, same margins as previous plot
  ArrayPlot exit, 0150006028# "Sinus & Cosinus"        ; finish with a title; optional: xxxxyyyyFF#: x, y pos, font size
  GuiTextBox 12, 100.0-80, 440, 66, Join$(desc$(), " "), bcol RgbCol(192, 255, 192)
  GuiEnd


Project attached. To build it, open the *.asc file in \Masm32\MasmBasic\RichMasm.exe and hit F6.

15
Community news and announcements / Re: X11 to Droid
« on: 28. October 2018, 09:47:57 »
I notice that programming on an Android phone is still very cumbersome.

9 Best Bluetooth keyboards you can currently buy

Pages: [1] 2 3 ... 12