It is currently Mon Dec 11, 2017 5:06 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: From PowerBasic to PureBasic a reference aid
PostPosted: Fri Dec 05, 2014 9:11 pm 
Offline
User
User

Joined: Thu Nov 27, 2014 3:10 pm
Posts: 43
Location: San Juan, Puerto Rico
Once again it's that time of the year; time to share! Here is a link to my gift to you.

https://drive.google.com/file/d/0B2sTe1m1kD2hV3dxRHJZd1hDUzA/view?usp=sharing

It's a pdf document that serves as a framework/reference to translate programs from PowerBasic to PureBasic.
Feel no fear in the process, it can be done successfully. Download the pdf and start from there.
With a warm Caribbean hug, from Puerto Rico; I wish you a very happy holidays to all!


Top
 Profile  
Reply with quote  
 Post subject: Re: From PowerBasic to PureBasic a reference aid.
PostPosted: Fri Dec 05, 2014 9:26 pm 
Offline
Moderator
Moderator
User avatar

Joined: Sat Apr 26, 2003 1:11 am
Posts: 1377
Great , thx for writing and sharing.

_________________
SPAMINATOR NR.1


Top
 Profile  
Reply with quote  
 Post subject: Re: From PowerBasic to PureBasic a reference aid.
PostPosted: Fri Dec 05, 2014 10:00 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3142
Location: Berlin, Germany
I do not need this myself, since I've dropped PowerBasic many many years ago.

However, this is a great idea, and it is well done!
I think this is very useful :!:

And many thanks for the warm Caribbean hug. That is something which everyone can certainly use. :-)
Very happy holidays to you, too!

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: From PowerBasic to PureBasic a reference aid.
PostPosted: Sat Dec 06, 2014 11:47 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3142
Location: Berlin, Germany
Hi again, Amilcar!

As we know, PowerBasic has some keywords and functions, which are not directly supported by PureBasic.
Maybe in a future version of your reference aid, you'd like to add some PureBasic code for working around those shortcomings.

For instance, in section 1.2.2 you mention that PureBasic's LTrim(), RTrim(), and Trim() do not support the ANY keyword.
Here is some fast running code that provides this functionality:

Code:
EnableExplicit

#WHITESPACE$ = " " + #TAB$ + #CRLF$


Procedure.s LTrimAny (source$, charlist$=#WHITESPACE$)
   ; removes from source$ any leading character which is contained in charlist$
   Protected p.i, *s.Character
   
   p = 1
   *s = @source$
   While *s\c <> 0 And FindString(charlist$, Chr(*s\c)) <> 0
      p + 1
      *s + SizeOf(Character)
   Wend
   
   ProcedureReturn Mid(source$, p)
EndProcedure


Procedure.s RTrimAny (source$, charlist$=#WHITESPACE$)
   ; removes from source$ any trailing character which is contained in charlist$
   Protected p.i, *s.Character
   
   p = Len(source$)
   *s = @source$ + (p-1) * SizeOf(Character)
   While p >= 1 And FindString(charlist$, Chr(*s\c)) <> 0
      p - 1
      *s - SizeOf(Character)
   Wend
   
   ProcedureReturn Left(source$, p)
EndProcedure


Macro TrimAny (_source_, _charlist_=#WHITESPACE$)
   ; removes from source$ any leading or trailing character which is contained in charlist$
   LTrimAny(RTrimAny(_source_, _charlist_), _charlist_)
EndMacro


; == Demo ==
Macro ShowTrimming (_source_)
   Debug "#" +          _source_  + "#"
   Debug "#" + LTrimAny(_source_) + "#"
   Debug "#" + RTrimAny(_source_) + "#"
   Debug "#" + TrimAny (_source_) + "#"
   Debug ""
EndMacro

ShowTrimming("Hello")
ShowTrimming(#TAB$ + " Hello " + #TAB$)
ShowTrimming(#TAB$ + "  " + #TAB$)
ShowTrimming("")

Just an idea.

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: From PowerBasic to PureBasic a reference aid.
PostPosted: Sat Dec 06, 2014 8:29 pm 
Offline
User
User

Joined: Thu Nov 27, 2014 3:10 pm
Posts: 43
Location: San Juan, Puerto Rico
Thank you Little John, your suggestion is welcomed. Also I appreciate your code example (is faster than my first try at it). The macro implementation is very nice and useful. The use of the constant #whitespace$ (as default value) sure ease the use of these procedures. Thank you very much!


Top
 Profile  
Reply with quote  
 Post subject: Re: From PowerBasic to PureBasic a reference aid.
PostPosted: Sun Dec 07, 2014 3:32 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13142
Location: France
Made sticky as it can help new comers from PowerBasic.


Top
 Profile  
Reply with quote  
 Post subject: Re: From PowerBasic to PureBasic a reference aid
PostPosted: Sun Jun 21, 2015 6:36 am 
Offline
User
User

Joined: Thu Aug 28, 2014 9:02 pm
Posts: 62
Here are a couple for you guys/gals coming from PowerBasic.

In PowerBasic, you could:

Mid$(PART1$, 4, 10) = PART2

In PureBasic, you can do the below. Note that specifying
a "0" (zero) in the fourth parameter will cause all of B$
that will fit into the remaining lengh of the string
pointed to by A to be utilized. This routine could be
reworked as a funcion but I suspect the below is faster
because of its use of pointers. This is for ASCII only.

Usage: INS(@PART1$, PART2$, 4, 10)
Code:
Define.I

Procedure INS(*A, B$, C, D)
E = MemoryStringLength(*A): F = Len(B$)
If E = 0 Or F = 0 Or C < 1: RaiseError(5): EndIf
If D < 1 Or F < D: D = F: EndIf
E = E - C + 1
If E < D: D = E: EndIf
PokeS(*A + C - 1, B$, D, #PB_String_NoZero)
EndProcedure


In PowerBasic, you could:

A$ = "C:\SOMEDIR\SOMEFILE.*": If Dir$(A$) <> "" Then KILL A$

In PureBasic you can do the below.

Usage: A$ = "C:\SOMEDIR\SOMEFILE.*": DeleteMask(A$)
Code:
Procedure DELETEMASK(PATH$)
FOLDER$ = GetPathPart(PATH$)
MASK$ = GetFilePart(PATH$)
DIRN = ExamineDirectory(#PB_Any, FOLDER$, MASK$)
If DIRN = 0: ProcedureReturn: EndIf
While NextDirectoryEntry(DIRN) > 0
DeleteFile(FOLDER$ + "\" + DirectoryEntryName(DIRN))
Wend
FinishDirectory(DIRN)
EndProcedure


Top
 Profile  
Reply with quote  
 Post subject: Re: From PowerBasic to PureBasic a reference aid
PostPosted: Sun Jun 21, 2015 11:17 pm 
Offline
User
User

Joined: Thu Aug 28, 2014 9:02 pm
Posts: 62
Here are a couple more routines which will turn your data streams
into random access files. they replace the GET and PUT commands
of PowerBasic. Note that PutS will always insure that the output
record is of the specified length even if the output string is not.
Also note that these routines are for ASCII.
Code:
;Usage: SOMEREC$ = GetS(FN4, 482, 510)

Procedure.S GetS(FLENUM, RECNUM, RECLEN)
RECNUM = RECNUM * RECLEN - RECLEN
FileSeek(FLENUM, RECNUM)
REC$ = ReadString(FLENUM, #PB_Ascii|#PB_File_IgnoreEOL, RECLEN)
If Len(REC$) <> RECLEN: RaiseError(59): EndIf
ProcedureReturn REC$
EndProcedure


;Usage: PutS(FN4, 482, 510, SOMEREC$)

Procedure PutS(FLENUM, RECNUM, RECLEN, REC$)
REC$ = Left(REC$ + Space(RECLEN), RECLEN)
RECNUM = RECNUM * RECLEN - RECLEN
FileSeek(FLENUM, RECNUM)
RES = WriteString(FLENUM, REC$, #PB_Ascii)
If RES = 0: RaiseError(59): EndIf
EndProcedure


Top
 Profile  
Reply with quote  
 Post subject: Re: From PowerBasic to PureBasic a reference aid
PostPosted: Mon Jun 22, 2015 2:07 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jul 08, 2013 8:43 pm
Posts: 221
Really interesting! 8)
Great job and thanks for this great help!

PB forever!! :D

_________________
If translation=Error: reply="Sorry, Im Spanish": Endif


Top
 Profile  
Reply with quote  
 Post subject: Re: From PowerBasic to PureBasic a reference aid
PostPosted: Tue Aug 18, 2015 12:18 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Jul 25, 2003 11:24 pm
Posts: 532
I have several versions of PowerBasic, but haven't used it in years. It went when I decided to leave Windows in favor of a Linux Distro. I picked Ubuntu, and still use it. I did try several other Linux distros, but what was the point, really? I mean it is just that much more to learn if you go with more than one.

What I hang on to is the PowerBasic conversion of Microsoft's SDK information files on how to call the various Window's APIs. Someone with PowerBasic did a real fine job on it, and even though the data structures and types aren't all the same as used in PureBasic. it's a great starting point to getting into the Win32 APIs.

It covers up through Windows 2000, which dates before Windows XP. Fundamentally, the APIs in Win2K are all shared with XP, but XP kept advancing and had more library modules added and existing ones expanded to provide more features to the OS and applications. Still, the lion's share of XP programs would also work on Windows 2000, they were that close.

It's becoming a different game now, as after XP, Microsoft introduced WinRT. which serves as the new base for all its higher level languages. But there has to be some compatibility there, as I've read that you can run legacy apps on Win7 and Win8 by having them emulate XP for that application. Thus, the Win32APIs are not quite dead yet. And wine, the emulator to Windows for use with Linux, uses XP as its target for what it does. But it's not perfect, and there are other choices.

One being to install a VM Manager and set up a client under it that is a reinstall of Windows XP, or some other version of Windows (or DOS, or a different operating system altogether). I personally use Oracle's Virtualbox as my VM Manager, and it is really great. I have Win2kPro, WinXP, and Win7 all set up as clients under it. Everything I install on a client just works, right out of the box. And no elaborate umbrella of protective software needed to shield it either, meaning as a client, Windows can perform better than it could do on its own.

Just giving others some idea of what can be done. What I really want to do is see if there is a way to share the Win32API folder and informational files with others. It use to be available for free from PowerBasic.com, but I guess they pulled it, because I can't find it there now. I don't think these forums let me upload the files here, because I don't see a way to do it. I do have a couple of sites where I can post it for others to download from, but let's see if there is any real interest first.

It may be that somebody already has something similar that they are willing to share, and it may be that it is already in PureBasic syntax, or it may be that it is inclusive of all the add-ons that XP brought into the game. Let's just see how it plays out in future posts first.

The other thing is, that the idea of static and dynamic link libraries, along with documented APIs for calling them, is a shared concept. It isn't just Windows that has them, but other operating systems as well. But as far as I know, Microsoft did the best job documenting theirs. I can't find any good sources for covering the Linux kernel APIs or possibly the MacOS APIs. These will all be different from each other as to what they are, where they are, what they are named, what they do, and so on. And you will also find that libraries can be added to a system, and those libraries have APIs, and they will all be documented separately.

But on the other side, some libraries are created to work with different operating systems, and even different hardware. These libraries have APIs that are enough like each other that you can write applications that can compile and run on each operating system separately. Graphics libraries and engines that are ported to different OSes have this in common. Printers and Scanners may work as well, if they hold to some standard. You see the PureBasic editor, which is much the same in every release of a compiler. PureBasic also supports the same statements and functions, so that the same source code can be used, although the compilers themselves produce different executable file formats.

The big thing is, what is common and uncommon between the different operating systems? File and folder naming conventions for one. How path statements are structured. How the file system is organized in terms of folder names and parent/child relationships. Whether folder and file names include spaces or have extensions. File details, like ownership, read/write status. date-times, and whether it is an executable or not. What internal file structure is used.

But you also run into system-level matters, like accessing USB devices, mounting and unmounting drives, dealing with a webcam, accessing the network, even just finding out the current setting for the screen resolution, putting up a console/terminal window, employing shell commands from within a program, setting a different font, size, or color for the Console/Terminal window, and so on.
It's all being done somewhere, but you need documented APIs to get access to any of it from within your own programs. Or it has to be built into the compiler and available as a statement or function. In other words, it is available as part of the programming language.

_________________
has-been wanna-be (You may not agree with what I say, but it will make you think).


Top
 Profile  
Reply with quote  
 Post subject: Re: From PowerBasic to PureBasic a reference aid
PostPosted: Sat May 21, 2016 4:53 am 
Offline
User
User

Joined: Thu Aug 28, 2014 9:02 pm
Posts: 62
If a parent process with a GUI invokes a child process that creates a dialog and
then waits, when the dialog is ended (but not the child process), you are left
with a rectangular hole in the parent GUI. This is because the parent program
which is in a wait state cannot refresh its screen.

In PowerBasic, I used the Windows OpenProcess/GetExitCodeProcess/CloseHandle API's
to address this problem but in PureBasic you can do this:

Usage:
Code:
Define.I ;64 bits

PNUM = RunProgram(ChildProgramPath, "", "", #PB_Program_Open)
PROGWAIT(PNUM)


Procedure PROGWAIT(RET.I)
If RET = 0: ProcedureReturn: EndIf
While ProgramRunning(RET)
While WindowEvent(): Wend
Delay(10) ;or whatever
Wend
CloseProgram(RET)
EndProcedure


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye