Recent posts

#1
Code to share / Recursive function
Last post by Frank Brübach - Yesterday at 08:19:26 AM
Yes Here WE Go


' -- recursive function, halProment

''-- a) Case (n = 0) : factorial(0) = 1
''-- b) Case (n > 0) : factorial(n) = n * factorial(n-1)
''-- b) this case calls the function itself: 'Return n * factorial(n - 1)

Function recursiveFactorial (ByVal n As Integer) As Integer
    If n = 0 Then                             '' end condition
        Return 1
    Else                                      '' recursion loop
        Return n * recursiveFactorial(n - 1)  '' recursive call
    End If
End Function

Printy recursiveFactorial(4) ' 24
p? recursiveFactorial(6) ' 720
#2
Code to share / Re: Example Intro and HalProm...
Last post by Zlatko Vid - Yesterday at 07:36:08 AM
Does your Hal support recursive functions ?
#3
Code to share / Increasing number to String
Last post by Frank Brübach - May 13, 2024, 09:15:08 PM
Increasing number to a String Auto Convert

' -- when a number is assigned to a string, it autoconverts.
' -- halProment Basic
' --

pro flag=10
flag++
printy flag '11

' number to an increasing string
'1)
pstring s="200mona"
s=val(s)+1 '201
printy s 'result: "201"

'2)
pro k
k++
s=val(s)+k
printy s 'result: "202"

'3)
pstring m=" Mona"
pstring st="3000 " + m
st=val(st)+1
printy st + m 'result: 3001 Mona

'4)
pro km=100
km++
pstring m=" Mona"
pstring st="3000 " + m
st=val(st)+val(km)+1
printy st + m 'result: 3102 Mona
#4
Code to share / N String repeat character fb
Last post by Frank Brübach - May 13, 2024, 09:11:38 PM
N-string example from freebasic Convert

' -- convert from freebasic, april-mai 2024
' -- simple example string / zstring halProment Basic
' -- Generatíng a string of n repeated characters
'
function generateRepeatedChar(character as string, n as Integer) as string
    dim result as pstring = ""
    dim i as integer

    for i = 1 to n
        result = result + character
    next

    return result
end function

' Example usage
dim repeatedString as pstring
repeatedString = generateRepeatedChar("*#", 5)

printy repeatedString ' Output: *#*#*#*#*#

' Create a zString
dim zString as pstring = ""
printy len(zString) ' Output: 0


'In this case, zString is an empty string,
'meaning it contains no characters.
'The length of zString is zero.

dim zString as pstring = "hey"
printy len(zString) ' Output: 3

#5
Code to share / Array redim ubound example
Last post by Frank Brübach - May 13, 2024, 09:08:47 PM
Next example Array redim ubound lbound (Convert from Powerbasic)


'
' -- array index redim ubound lbound example
' -- halPromentBasic, mai-2024,frank bruebach
'
pindex 1

dim MyArray(10) as integer '1 TO 10
dim i as integer

' Fill the array with some values
for i = LBOUND(MyArray) to UBOUND(MyArray)
    MyArray(i) = i * 10
next i

' Display the values in the array
for i = LBOUND(MyArray) to UBOUND(MyArray)
    printy "MyArray(" + str(i) + ") = " + str(MyArray(i))
next i

' Re-dimension the array to have 15 elements
redim integer MyArray(15) '1 to 15


' Fill the new array elements with some values
for i = UBOUND(MyArray) - 8 to UBOUND(MyArray) '- 4 ' -10
    MyArray(i) = i * 5
next i

' Display the values in the re-dimensioned array
for i = LBOUND(MyArray) to UBOUND(MyArray)
    printy "MyArray(" + str(i) + ") = " + str(MyArray(i))
next i

' ends

#6
Code to share / Info
Last post by Frank Brübach - May 13, 2024, 06:17:25 PM
1) Info: all new and old examples you can find in updated ZIP and rar folder in my Post #17

I couldnt changed the Text anymore in that Post #17 dont know why?

2) If you Like you can have a Look at
GitHub Frankolinox/HalProment-Basic for Download Access and Updates for next weeks and months
#7
Code to share / C++ example simple
Last post by Frank Brübach - May 13, 2024, 06:13:33 PM
Here is a simple c++ example I tried to Convert and my Idea was to translate much more for next Updates


int main {

int x = 5;
int y = 6;
int sum = x + y; '
'int mult = x * y;
'cout << sum;
cout sum;
'cout mult; ' 30 ok

return 0;
}
' result 11 ok
#8
Code to share / Class example 2
Last post by Frank Brübach - May 13, 2024, 06:10:16 PM
Class example 2

' class test addition, division
'
class statis

method plus() as double
method average() as double
dax(100) as double
dnx as long
end class

'----------------
methods of statis
'================

method plus() as double
dim i as integer
for i = 1 to this.dnx
method += this.dax(i)
next
end method

method average() as double
  method = this.plus / this.dnx 'division
  'method = this.plus + this.dnx 'addition
end method

end methods

'test
dim stx as statis

stx.dax => 2,4,6,8,10,12,14,16,18,20
stx.dnx = 8
print `plus: ` str(stx.plus) ` Average: ` str stx.average ' 72, 9 '' 72,80
#9
Code to share / Calculation example 4
Last post by Frank Brübach - May 13, 2024, 06:05:41 PM
[Code[
' francolinox/halProment-Basic
'-- new features: pys, p?, msgbox
'-- calc example 4
'
pim a,b,c,d,e as pro
pim z as pys
z=3
a=20
b=30
c=40
d=a*b
e=d*b
string s,st
pstring strx
strx = "powerbasic is a good basic program"
p? strx
s="Hello Batman " + str(d)
st="Hello Superman " + str(e)
print s
printy st
p? z
msgbox "hello"
#10
Code to share / Calculations and function
Last post by Frank Brübach - May 13, 2024, 06:01:33 PM
Next calculation example, printy and p?, pstring,

' simple calc with printy and p?
' and two different functions with a friendly pbmain()
'

pim a,b,c,d,e as pro
pim s,st as pstring

a=30
b=40
c=50
d=a*b
e=d*c
s= "Hello Superman "+str(d)
st= "Hello Ironman "+str(e)
printy s
p? st

function pbmain() as long
pro a=2345
pstring s="I am thor "+a
'print s
return a
end function

print pbmain() '2345

function pbmain() as long
pro a=2345
pstring s="I am thor "+a
print s
'return a
end function

pbmain() ' I am Thor 2345