Author Topic: Re: PowerBasic equivalents and conversions  (Read 2171 times)

0 Members and 1 Guest are viewing this topic.

John

  • Hero Member
  • *****
  • Posts: 2803
Re: PowerBasic equivalents and conversions
« on: January 26, 2017, 10:04:00 AM »
Welcome aboard ChrisC,

It would be great if you could convince some of your other Power(less)BASIC friends to join you on your OxygenBasic adventures.

Charles Pegge

  • Author
  • *****
  • Posts: 3282
    • Oxygen Basic
Re: Re: PowerBasic equivalents and conversions
« Reply #1 on: January 28, 2017, 04:39:52 AM »

Hi Chris,

I have not used PowerBasic in the last ten years, so I am a little rusty, but Oxygen Basic has the core essential subset of PB functions from which all others can be derived.

If you post some key pieces of PowerBasic source code, we could show how it can be translated into O2.  This could form the basis for a PBtoO2 transitional manual.

chrisc

  • Newbie
  • *
  • Posts: 17
Re: Re: PowerBasic equivalents and conversions
« Reply #2 on: January 29, 2017, 03:31:31 PM »
Thanks Charles and John

I have attached a powerbasic  ListView with Statusbar example for you to convert to O2.

In regards to getting people to change over to O2, I will writing to those PB forum members who are
interested to change over. They are some who live by self denial and heads in the sand ones, which
I would just ignore.

Appreciate your help.


chrisc

  • Newbie
  • *
  • Posts: 17
Re: Re: PowerBasic equivalents and conversions
« Reply #3 on: January 29, 2017, 03:46:55 PM »
A simple Menu bar program in PowerBasic


chrisc

  • Newbie
  • *
  • Posts: 17
Re: Re: PowerBasic equivalents and conversions
« Reply #4 on: January 29, 2017, 03:55:23 PM »
THis is a PowerBasic program which build up a number array and to use PowerBasic Array scan
command to search for the array index matching a given number 15

chrisc

  • Newbie
  • *
  • Posts: 17
Re: Re: PowerBasic equivalents and conversions
« Reply #5 on: January 29, 2017, 04:00:54 PM »
This is a Powerbasic Function to Split a given string  to form  an array


John

  • Hero Member
  • *****
  • Posts: 2803
Re: Re: PowerBasic equivalents and conversions
« Reply #6 on: January 29, 2017, 07:46:47 PM »
Array Split

Code: [Select]
'  Array split
'  https://www.powerbasic.com/support/pbforums/showthread.php?t=17642
 '  Function to Split a given string  to form  an array

#COMPILE EXE

GLOBAL Tmp() AS  STRING

FUNCTION PBMAIN() AS LONG
   DIM Kount AS LONG
   DIM jj AS LONG
   DIM Ast AS STRING

  ' When there are inbetween blank spaces in a string which
  ' are unwanted, we use a SHRINK statement
   Ast = "Hello, world, What, a,  Nice, day, outside,  My,  Window "

   ArSplit( Ast, ",",Kount )

  ' prints out the array contents
   OPEN "arOut.txt" FOR OUTPUT  AS #3
    FOR  jj = 1 TO Kount
        PRINT #3, jj, Tmp(jj)
    NEXT jj
    CLOSE #3

    MSGBOX "done"

END FUNCTION

'=====================================
 '  Split a given string to form an array
SUB ArSplit( GivenSt AS STRING, Delimit$ ,Cnt AS LONG )
   LOCAL  Strt, i AS LONG
   'get rid of inbetween blanks first
    GivenSt = TRIM$(GivenSt)
    GivenSt = SHRINK$(GivenSt)
    Cnt = PARSECOUNT(GivenSt, Delimit$)
    REDIM Tmp(1 TO Cnt&)

    Strt& = 1
    FOR i& = 1 TO Cnt&
        Tmp(I&) = TRIM$(EXTRACT$(Strt&, GivenSt, Delimit$))
        Strt& = INSTR(Strt&, GivenSt, Delimit$) + 1
    NEXT
END SUB

Here is my attempt at your function in Script BASIC.

Code: Script BASIC
  1. Ast = "Hello, world, What, a,  Nice, day, outside,  My,  Window "
  2.  
  3. SPLITA Ast BY "," TO AstArray
  4.  
  5. OPEN "ArraySplitOut.txt" FOR OUTPUT  AS #1
  6. FOR x = 0 to UBOUND(AstArray)
  7.   PRINT #1, x, "\t",TRIM(AstArray[x]),"\n"
  8. NEXT
  9. CLOSEALL
  10.  


jrs@jrs-laptop:~/PB/Ar split$ time scriba ArraySplit.sb

real   0m0.025s
user   0m0.004s
sys   0m0.000s
jrs@jrs-laptop:~/PB/Ar split$ cat ArraySplitOut.txt
0   Hello
1   world
2   What
3   a
4   Nice
5   day
6   outside
7   My
8   Window
jrs@jrs-laptop:~/PB/Ar split$


I'm looking forward to seeing the OxygenBasic version posted.


« Last Edit: January 29, 2017, 07:56:01 PM by John »

chrisc

  • Newbie
  • *
  • Posts: 17
Re: Re: PowerBasic equivalents and conversions
« Reply #7 on: January 29, 2017, 10:18:08 PM »
I have attached  2 files describing how to convert from PowerBasic to PureBasic.
Perhaps these documents can form the basis of converting from PowerBasic to O2

Note that syntax of PureBasic is awkward like they DO NOT have a For Loop and things like

DIM  jkount as long    becomes   Dim jkount.l

These are the syntax, we found difficult to convert to PureBasic,  it is a put off for us Basic programmers

chrisc

  • Newbie
  • *
  • Posts: 17
Re: Re: PowerBasic equivalents and conversions
« Reply #8 on: January 29, 2017, 10:19:12 PM »
This is the pdf file

Aurel

  • Full Member
  • ***
  • Posts: 116
Re: Re: PowerBasic equivalents and conversions
« Reply #9 on: January 29, 2017, 11:21:15 PM »
Interesting examples for me
and i like to try convert to o2 using awinh, purebasic is not so problematic
because i have some experience with that basic,, ;D
well i forget add ListView control into my include file so i need to do
first something like this :/first i must translate this code to o2/
dLib code:

Code: [Select]
Declare _lvleft,_lvinit,LV_ITEM,LV_COLUMN

Structure Listviewcolumn
    cmask.l
    cfmt.l
    ccx.l
    cpszText.l
    ccchTextMax.l
    ciSubItem.l
EndStructure

Structure Listviewitem
    mask.l
    iItem.l
    iSubItem.l
    state.l
    stateMask.l
    pszText.l
    cchTextMax.l
    iImage.l
    lParam.l
EndStructure

Procedure FirstListViewInit()
  StructMemory LV_ITEM.Listviewitem
  StructMemory LV_COLUMN.Listviewcolumn
  _lvinit=1
EndProcedure

ProcedureLib CreateListView(_lvhwnd,_lvx,_lvy,_lvw,_lvh,_lvstring.s,_lvcwidth,_lvflag,_ex)
  Declare _lvhandle
  If _lvinit=0
    FirstListViewInit()
  EndIf
  _lvhandle = CreateWindowEx(_ex,"SysListView32","",_lvflag,_lvx,_lvy,_lvw,_lvh,_lvhwnd,0,0,0)
  LV_COLUMN\cmask=#LVCF_FMT|#LVCF_TEXT|#LVCF_WIDTH
  LV_COLUMN\cfmt=#LVCFMT_LEFT
  LV_COLUMN\ccx=_lvcwidth
  LV_COLUMN\cpszText=_lvstring
  SendMessage(_lvhandle,#LVM_INSERTCOLUMN,0,LV_COLUMN)
  GetAsyncKeyState(#VK_LBUTTON)
  ProcedureReturn _lvhandle
EndProcedure

..one thing i am not sure is do i must use typedef struct in listviewInit like :
'init ListView....
Function FirstListViewInit()
  typedef struct LV_ITEM.Listviewitem
  typedef struct LV_COLUMN.Listviewcolumn
  _lvinit=1
End Function

hmm ..i must check VB version  ;D

Aurel

  • Full Member
  • ***
  • Posts: 116
Re: Re: PowerBasic equivalents and conversions
« Reply #10 on: January 31, 2017, 05:33:23 AM »
ok like this for start,,,
next few more functions to work with ListView and add checkboxes or icons into columns
Code: [Select]
  $ Filename "skeleton.exe" ' o2
include "RTL32.inc"
include "awinh.inc"
INT win,wx=0,wy=0,ww=600,wh=400,wstyle = WS_MINMAXSIZE
INT button0,b0ID=100, lvControl,lvID=1000
win=SetWindow("GUI-PB->o2::ListView",wx,wy,ww,wh,0,wstyle)
'create button----------------------------------------------------------
button0 = SetButton(win,180,4,80,26,"Close (X)",0x50001000,0x200,b0ID)
'create List view------------------------------------------------------
lvControl = SetListView(win, 20, 40, 300, 220, "ListView Control", 200,1417740297 ,0x200)
'----------------------------------------------------------------------
Wait()  'message loop
'----------------------------------------------------------------------
'func main
Function WndProc (sys hwnd,wmsg,wparam,lparam) as sys callback
SELECT hwnd
CASE win
Select wmsg
CASE WM_CLOSE
CloseWindow(win)
EndProgram
End Select
END SELECT
RETURN Default
END FUNCTION

Charles Pegge

  • Author
  • *****
  • Posts: 3282
    • Oxygen Basic
Re: Re: PowerBasic equivalents and conversions
« Reply #11 on: February 01, 2017, 03:16:49 AM »
Thanks Chris.

Here is a light-touch translation of your first example Array Scan

I have commented out incompatible PB lines with 2 quote marks

For JIT execution you can omit the 3 lines used for creating the 64 bit exe file.

ArrayScan64.exe survives all but one of the VirusTotal.com scans. (Invincea)

Code: [Select]
''#COMPILE EXE
''#DIM ALL

'
% filename    "ArrayScan64.exe"
includepath "$\inc\"
include "RTL64.inc"

#lookahead
indexbase 1

''GLOBAL Arr() AS LONG
GLOBAL Arr(100) AS LONG


FUNCTION PBMAIN () AS LONG
    LOCAL AnyElem AS LONG

        ''REDIM Arr(1 TO 100)
       
        Arr(1) = 5
        Arr(2) = 15
        Arr(3) = 25
        Arr(4) = 35
        Arr(5) = 45
        Arr(6) = 55
        Arr(12) = 105
        Arr(16) = 155
        Arr(26) = 515

       AnyElem = FindElemArray(15)

       ''MSGBOX " AnyElem " + STR$(AnyElem)
       MBOX " AnyElem " + STR(AnyElem)

END FUNCTION

'===========================
' Find an element in array
' matching the wanted number wnum
FUNCTION FindElemArray(wnum AS LONG) AS LONG
   LOCAL I&
   I& = 0
   ''ARRAY SCAN Arr(),= wnum , TO I&
   ArrayScan(wnum,I)
   FUNCTION = I&
END FUNCTION

'''Extra Functions

sub ArrayScan(n as long, r as long)
  'Assumes Arr is a static array
  for i=1 to spanof Arr
    if Arr(i)=n then r=i : return
  next
end sub

'''Main Call
PBMAIN()

Aurel

  • Full Member
  • ***
  • Posts: 116
Re: Re: PowerBasic equivalents and conversions
« Reply #12 on: February 02, 2017, 04:13:42 AM »
...new functions added
so far seems that all work solid..even i have few o2 quirks  :D

Code: [Select]
  $ Filename "ListView.exe" ' o2
include "RTL32.inc"
include "awinh.inc"
INT win,wx=0,wy=0,ww=600,wh=400,wstyle = WS_MINMAXSIZE
INT button0, b0ID=100, lvControl, lvID = 1000 , static1, st1ID = 500
'create window =======================================================
win = SetWindow("GUI-PB->o2::ListView",wx,wy,ww,wh,0,wstyle)
'=====================================================================
'create static control -----------------------------------------------
static1 = SetStatic(win,20,10,240,13,"ListView Control in Oxygen Basic - by Aurel",0,0,st1ID)
'crete button---------------------------------------------------------
button0 = SetButton(win,300,4,80,26,"Close (X)",0x50001000,0x200,b0ID)

'create List view----------------------------------------------------------------
lvControl = SetListView (win, 20, 40, 400, 220, "Column_1", 200, 1417740297 ,0x200,lvID)

'add new column to listView -> {AddLVC hwnd, pos, width , text, flag}-----------
AddListViewColumn (lvControl, 2, 200,"Column_2",0 )

'add listview item {AddLVI hwnd, pos, text, icon} -> column 0 - zero based ----
AddListViewItem (lvControl, 0, "Text 1- Oxygen Basic", 0)
AddListViewItem (lvControl, 1, "Text 2- Oxygen Basic", 0)
AddListViewItem (lvControl, 2, "Text 3- Oxygen Basic", 0)
AddListViewItem (lvControl, 3, "Text 4- Oxygen Basic", 0)
AddListViewItem (lvControl, 4, "Text 5- Oxygen Basic", 0)
AddListViewItem (lvControl, 5, "Text 6- Oxygen Basic", 0)
'add second column item -  AddLVSI{hwnd,pos,sub,text) -> column 1 -second column

AddListViewSubItem (lvControl,0, 1, "Text 0 - Power Basic")
AddListViewSubItem (lvControl,1, 1, "Text 1 - Power Basic")
AddListViewSubItem (lvControl,2, 1, "Text 2 - Power Basic")
AddListViewSubItem (lvControl,3, 1, "Text 3 - Power Basic")
AddListViewSubItem (lvControl,4, 1, "Text 4 - Power Basic")
AddListViewSubItem (lvControl,5, 1, "Text 5 - Power Basic")


'----------------------------------------------------------------------
Wait()  'message loop
'----------------------------------------------------------------------
'func main
Function WndProc (sys hwnd,wmsg,wparam,lparam) as sys callback
SELECT hwnd
CASE win
Select wmsg
CASE WM_CLOSE
CloseWindow(win)
EndProgram
End Select
END SELECT
RETURN Default
END FUNCTION

John

  • Hero Member
  • *****
  • Posts: 2803
Re: Re: PowerBasic equivalents and conversions
« Reply #13 on: February 02, 2017, 09:17:44 AM »
For those interested, PowerBASIC has been sold.


Aurel

  • Full Member
  • ***
  • Posts: 116
Re: Re: PowerBasic equivalents and conversions
« Reply #14 on: February 02, 2017, 09:42:22 AM »
Point of this topic is conversion from pb to o2 ...right?
Second i don't believe in bright future of powerBasic simply
because there is no users or customers for such a thing .