Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Hello from a Commodore PET coder


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-15-2008, 01:09 PM
Senior Member
 
Join Date: Mar 2008
Posts: 114
Default Randomize + Hello from a Commodore PET coder

Hello there,

Firstly I am a new member so "HELLO EVERYONE!!!"

My question is - "is there a Randomize function?"

A bit now about me ...

My 25 years experience has been starting out using BASIC on Commodore PET, through to VIC 20, C64, IBM PC GW-BASIC, Turbo Pascal, then Visual Basic, then HTML / Javascript, then ASP. Access and SQL databases I also run from a work point of view. I have also dabbled, though not heavily with CoBOL, ASM and C.

I am a programmer with 25 years experience and have now ventured into programming in Pocket PC devices... I am just starting out (2 weeks ago) with these devices and have explored what programming languages are available for them - I tried Embedded VB from MS but wasnt happy with it not being able to make EXE files. I have recently looked at PPL from ArianeSoft which seems pretty good but its too C oriented for my liking ... then I found Basic4PPC which seems more like my kettle of fish

I have made a program in VB6 which I am now converting to a Pocket PC format and am using the Trial version of Basic4PPC to see if I can do it ... if so, I will buy Basic4PPC and rock on from there!

So, initial thoughts are quite good but being ultimately from a Commore PET (Microsoft) BASIC background, I feel some commands are either missing or use different terminology, so, at the moment I am ploughing through conversion from VB6 to Basic4PPC and have made some Basic functions (sorry, Subs !!!) which take MS BASIC commands and then return values using the Basic4PPC functions. I did search on the forums for LEFT RIGHT LEN MID VAL CINT CSTR INSTR LCASE UCASE TRIM etc but nothing found, so if someone searches now they will find these ...

Quote:

Sub UCase(ucase_mystr)
Return StrToUpper(ucase_mystr)
End Sub

Sub LCase(lcase_mystr)
Return StrToLower(lcase_mystr)
End Sub

Sub Left(left_mystr,left_length)
Return SubString (left_mystr,0, left_length)
End Sub

Sub Mid(mid_mystr,mid_pos,mid_length)
Return SubString (mid_mystr,mid_pos-1,mid_length)
End Sub

Sub Right(right_mystr,right_length)
Return SubString (right_mystr, StrLength (right_mystr) - right_length,right_length)
End Sub

Sub Len(len_mystr)
Return StrLength (len_mystr)
End Sub

Sub vbCrLf
Return Chr(13)+Chr(10)
End Sub

Sub CStr(cstr_no)
Return Format(cstr_no,"D1")
End Sub

Sub Val(val_str)
Return 0 + val_str
End Sub

Sub CInt(cstr_str)
Return 0 + cstr_str
End Sub

Sub Trim(trim_str)
Do Until Left(trim_str,1) <> " "
trim_str = SubString(trim_str,1,len(trim_str)-1)
Loop
Do Until right(trim_str,1) <> " "
trim_str = left(trim_str,len(trim_str)-1)
Loop
Return trim_str
End Sub

Sub Instr(instr_str,instr_searchfor)
Return StrIndexOf(instr_str,instr_searchfor,0)+1
End Sub
Apologies in advance if the above code needs to sit in a code window but I cant see how to do that at the moment.

Once I have done a full conversion of my VB6 app to Basic4PPC, I will issue a library for people to plug in to as there may be other functions which are different and need adding to the library. Not sure how it would affect performance, but for large conversions, it will make it easy for people to do a quick conversion of their large app to make a judgement if they want to continue with the conversion.

Some things will need modding, such as File handling ... but the above will help for people with backgrounds of MS / Commodore PET ish backgrounds.

Thats it for now ... I will carry on converting for now...

Steve

Last edited by badkarma : 03-15-2008 at 02:02 PM.
Reply With Quote
  #2 (permalink)  
Old 03-15-2008, 02:34 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,897
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Quote:
Originally Posted by badkarma View Post
My question is - "is there a Randomize function?"
Steve
Yes - Rnd(). Curiously it is documented under Help -> Main Help -> Keywords -> General rather than Maths
Reply With Quote
  #3 (permalink)  
Old 03-15-2008, 03:42 PM
Senior Member
 
Join Date: Mar 2008
Posts: 114
Default

Thanks for the reply agraham.

I did come across the rnd function, but on other BASICs there is also a "Randomize" function which generate a seed number so it doesnt pick the same number everytime you start the program - but I have just tested it and it picks a different number every time now, so I guess the engine auto-randomizes on execution.

Thanks for the reply,

Steve
Reply With Quote
  #4 (permalink)  
Old 03-15-2008, 03:48 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,334
Default

Small corrections:
Code:
 Sub vbCrLf
 Return Chr(13) & Chr(10)
 'Or Return CRLF
End Sub


Sub Val(val_str) 'Not necessary.
    Return 0 + val_str
End Sub

Sub CInt(cstr_str) 'Not necessary.
    Return 0 + cstr_str
End Sub


Another solution for Trim (using regular expressions): Trim Spaces from Beginning and end of Strings
Reply With Quote
  #5 (permalink)  
Old 03-15-2008, 04:59 PM
Senior Member
 
Join Date: Mar 2008
Posts: 114
Default

Thanks for the updates Erel.

I did notice the Trim post but was thinking of trying to keep all my code 'in-house' without using plug ins - not sure if the Match / Regex are plug ins yet --- still new to this app ( 3 hours old now ) but will investigate these later for additional options on what they can do.

Also, being an *old* BASIC coder, i use...

"string" + "string"

instead of

"string" & "string"

Is there a difference? Always wanted to know... but could never find anything out about this ...

Many thanks

Steve
Reply With Quote
  #6 (permalink)  
Old 03-15-2008, 05:01 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,334
Default

"string" + "string" will not work (an error will be raised).
Reply With Quote
  #7 (permalink)  
Old 03-15-2008, 05:10 PM
Senior Member
 
Join Date: Mar 2008
Posts: 114
Default

Thanks Erel,

I am experiencing some work OK, but others dont, until you put & instead of +


Quote:
Sub Globals
'Declare the global variables here.
End Sub


Sub App_Start

FileOpen (myfo,"a.dat",cRead,,cASCII)
r = FileRead (myfo)
Msgbox (r)

Do Until r = EOF
MyFileData = MyFileData & r & Chr(10)
r = FileRead (myfo)
Loop
FileClose (myfo)

End Sub
(Data file is a text file list of numbers)

In the line MyFileData = MyFileData & r & Chr(10)" above, the Run errors if '+' is used...

Ah well ... the old dog will have to learn new tricks - but looking good so far - I am impressed!

Cheers
Reply With Quote
  #8 (permalink)  
Old 03-15-2008, 06:19 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,897
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Welcome to the community. Firstly do not hesitate, run straight out and BUY this program to get access to the compilers and the wonderful set of libraries in the "Additional Libraries" forum.

Secondly, without wanting to teach grannies about eggs there are some things that it is useful to be aware of.

You have to realize that B4PPC is very weakly typed - even more so than the old Basics. You won't go far wrong if you regard everything as a string - including numbers (mainly because they actually are stored as strings). Even the boolean values are the strings "true" and "false". Because of this B4PPC needs to use "+" to indicate numeric conversion and addition of variables and "&" to perform string concatenation. Hence the errors using "+" when one or other of the elements cannot be evaluated as a number.You can see the difference by "msgbox(2 + 3 & " " & 2 & 3)".

Because of the weak typing the arithmetic performance is a little under par, but where it is important you can persuade the optimising compiler to use strongly typed arithmetic by using typed array variables rather normal variables.

Because B4PPC is tightly bound to the .NET Framework and has an open architecture for interfacing to external libraries it is quite easy (at least for those of us with the right tools - and they are free to download if you want to dabble) to implement "missing" functionality so if you come across anything that you think is "missing" or would be useful then ask in the forums. It might be already buried in an existing library or someone might whip up a little library for you.
Reply With Quote
  #9 (permalink)  
Old 03-15-2008, 07:34 PM
Senior Member
 
Join Date: Mar 2008
Posts: 114
Default

Many thanks agraham, (i see also that you live just down the road ... I live in Wigan) ...

The above now makes more sense to me.

My app I am converting is 1500 or so lines and I am well into conversion now ... once converted fully and tested I will definately push the "Buy It Now" button - probably around payday near the end of March.

It does compile to EXE for ARM processors I take it (IPAQ rw6815)?... I guess it will say somewhere on the site - will delve a bit more shortly into the docs on the website. At the moment its more of a RTFM later and have a play first ...

Just in case anyone is looking at the above functions, I have had to put in some "" checks before running the LEFT / MID / RIGHT functions as I get an error on checking strings with a length of zero ('startindex cannot be less than zero' when using RIGHT function).... so here is the updates ... (official set of functions to follow in a bit once I have tested to destruction ...

Quote:
Sub Left(left_mystr,left_length)
If left_mystr = "" Then Return
Return SubString (left_mystr,0, left_length)
End Sub

Sub Mid(mid_mystr,mid_pos,mid_length)
If mid_mystr = "" Then Return
Return SubString (mid_mystr,mid_pos-1,mid_length)
End Sub

Sub Right(right_mystr,right_length)
If right_mystr = "" Then Return
Return SubString (right_mystr, StrLength (right_mystr) - right_length, right_length)
End Sub
Cheers

Steve

Last edited by badkarma : 03-15-2008 at 07:37 PM.
Reply With Quote
  #10 (permalink)  
Old 03-15-2008, 07:37 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,334
Default

Quote:
Originally Posted by badkarma View Post
It does compile to EXE for ARM processors I take it (IPAQ rw6815)?
Yes.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 03:21 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0