Code error

 New License Key coupon code PROTON-25 Everything Must Go, Crazy prices

# Thread: Code error – 153 days old

1. 1

## Code error

I made some changes to some very old code and had a problem compiling it as I have the following (which I got from sample code Bargrahp.bas)
Fullbars = (Barval Min 48) /3
The problem seems to be with the Min, I checked the user manual and can't find any reference to this can anyone please help.

Fullbars and Barval are just my variables, this code compiled years ago ok.

2. Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues

3. 1

## Re: Code error

Yep- The MIN function went away a while back. Here's the way I re-did my bar graph code:
Code:
```Dim A2D_VAL As Word   ' The value from the A/D converter
Dim BAR_VAL As Word   ' Value to be graphed.
Dim BARS As  Byte      ' Number of full ||| bars to draw.
Dim BALANCE As  Byte    ' Balance left after all |||s are drawn.
Dim BALF As Byte        ' Is a 'Balance' character needed? (1=yes, 0=no).

BAR_VAL = A2D_VAL / BAR_CAL
BAR_VAL = A2D_VAL / BAR_CAL
If BAR_VAL < MAXBAR Then     ' One full bar for each 3 graph units.
BARS = BAR_VAL /3
BALANCE = BAR_VAL //3
Else
BARS = BAR_VAL /3
BALANCE = MAXBAR //3
EndIf
If BALANCE < 1 Then        ' Balance is the remainder after a division by 3.
BALF = BALANCE
Else
BALF = 1
EndIf
Print At 1,1,Rep FULLBAR\BARS,Rep (BALANCE + BASEBAR)\BALF,Rep " " \B_WDTH - (BARS + BALF)```
I hope that helps.

-Rick

4. Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues

5. 0

## Re: Code error

The Min and Max functions were removed from the compiler many years ago, because they were interfering internally with it, and it was more robust to remove them than to try and tamper too much with the parser. I'll take a look at them later, but they will be a function, rather than an operator.

However, they can easily be re-created with a pair of procedures:

Code:
```    Dim Bytein1 As Byte
Dim Bytein2 As Byte
Dim Byteout As Byte

'-------------------------------------------------------------
' Find the maximum of 2 values
' Input     : pValue1 holds the first value to compare
'           : pValue2 holds the second value to compare
' Output    : Returns the maximum of both values
' Notes     : None
'
Proc Max16(pValue1 As Word, pValue2 As Word), Word
Result = pValue2                ' Default to returning pValue2 as the result
If pValue1 > pValue2 Then       ' Is pValue1 greater than pValue2?
Result = pValue1            ' Yes. So return pValue1 as the result
EndIf
EndProc

'-------------------------------------------------------------
' Find the minimum of 2 values
' Input     : pValue1 holds the first value to compare
'           : pValue2 holds the second value to compare
' Output    : Returns the minimum of both values
' Notes     : None
'
Proc Min16(pValue1 As Word, pValue2 As Word), Word
Result = pValue2                ' Default to returning pValue2 as the result
If pValue1 < pValue2 Then       ' Is pValue1 less than pValue2?
Result = pValue1            ' Yes. So return pValue1 as the result
EndIf
EndProc

'-------------------------------------------------------------
'
' Demo of the Min16 procedure
'
Bytein1 = 5
For Bytein2 = 0 To 10
Byteout = Min16(Bytein1, Bytein2)
HRSOutLn "Bytein1 = ", Dec Bytein1, " : Bytein2 = ", Dec Bytein2
HRSOutLn Dec Byteout, " Is the lowest"
DelayMS 100
Next
'
' Demo of the Max16 procedure
'
Bytein1 =  5
For Bytein2 = 0 To 10
Byteout = Max16(Bytein1, Bytein2)
HRSOutLn "Bytein1 = ", Dec Bytein1, " : Bytein2 = ", Dec Bytein2
HRSOutLn Dec Byteout, " Is the greater"
DelayMS 100
Next```
In order to make the procedures also do Min and Max with signed variables, change the parameter types to Sword, and the returns to Sword, and, maybe call them MinS16 and MaxS16. For 32-bit operation, create 2 procedures that use Dword or SDword as the parameter types and return type, and the names Min32 and Max32. etc... The same for Floating Point... Change parameter types and the name. I'm looking into overloading with procedures, but it is a time off just yet because the underlying code is quite complex to create from scratch.

Procedures make a lot of the compiler's built in functions more flexible because they can be recreated in the BASIC listing, and altered to suit better, instead of more generic. Also remember, a procedure will not be used in the code if it is not called in the BASIC listing, so libraries of new functions can also be created.

6. Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues

There are currently 1 users browsing this thread. (0 members and 1 guests)