LineXY and variable?

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by cor.

The following 2 lines should be on the same y position place, but they are not
What I'am doing wrong.

It's a complete working test code.

Code: Select all

 
; test LineXY

#stringheight=20
FretSpanStart=2

If OpenWindow(0, 100, 100, 195, 260, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "PureBasic Window")

StartDrawing(WindowOutput())
tmp=FretSpanStart-1
LineXY(40,26+(#stringheight*FretSpanStart-1),140,26+(#stringheight*FretSpanStart-1),RGB(255,0,0))
LineXY(180,26+(#stringheight*tmp),140,26+(#stringheight*tmp),RGB(255,255,0))
StopDrawing()

  Repeat
    EventID.l = WaitWindowEvent()

    If EventID = #PB_Event_CloseWindow  ; If the user has pressed on the close button
      Quit = 1
    EndIf

  Until Quit = 1
  
EndIf

End   ; All the opened windows are closed automatically by PureBasic
  

 

Using Windows 98 SE
Registered PB version : 3.2 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> stringheight*FretSpanStart-1

The maths is wrong... the above is multiplying stringheight and FretSpanStart
together, then subtracting 1 from the result. (It's not subtracting 1 from
FretSpanStart first). Here's a new working example:

Code: Select all

; test LineXY
#stringheight=20
FretSpanStart=2
If OpenWindow(0, 100, 100, 195, 260, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "PureBasic Window")
  StartDrawing(WindowOutput())
  tmp=FretSpanStart-1
  a=FretSpanStart-1 ; ADDED THIS.
  LineXY(40,26+(#stringheight*a),140,26+(#stringheight*a),RGB(255,0,0)) ; CHANGED THIS.
  LineXY(180,26+(#stringheight*tmp),140,26+(#stringheight*tmp),RGB(255,255,0))
  StopDrawing()
  Repeat
    EventID.l = WaitWindowEvent()
    If EventID = #PB_Event_CloseWindow ; If the user has pressed on the close button
      Quit = 1
    EndIf
  Until Quit = 1
EndIf

PB - Registered PureBasic Coder

Edited by - PB on 28 June 2002 23:25:37
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

Like PB said... for the first line to do the same as the second your equation would have to be:

26+(#stringheight*(FretSpanStart-1)) = 26+(#stringheight*tmp)

Stuff in brackets is always done first, then multiplication/Division, then Addition/Subtraction

At least that's what I remember from school :)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> for the first line to do the same as the second your equation would have to be:
> 26+(#stringheight*(FretSpanStart-1))

Unfortunately PureBasic doesn't allow this expression to be compiled -- it reports
an error of "Too complex expression". Cor will have to use a temp variable as
shown in my edited example above to accomplish the task.

PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by cor.

Thanks,

What I want is that 'tmp' should replace FretSpanStart-1

And that is not working


Using Windows 98 SE
Registered PB version : 3.2 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> What I want is that 'tmp' should replace FretSpanStart-1
> And that is not working

I don't understand: if I replace FretSpanStart-1 with tmp then it works for me.


PB - Registered PureBasic Coder
Post Reply