Oppure

Loading
08/09/08 13:47
feddur
ho fatto così:

Private Function Y(X As Integer) As Double
Y = X
End Function

Private Sub Scala(Xmin As Integer, Ymax As Integer, Xmax As Integer, Ymin As Integer)
Picture1.Scale (Xmin, Ymax)-(Xmax, Ymin)
End Sub


Private Sub Form_Load()
Dim valore(3) As Integer

valore(0) = 12
valore(1) = 30
valore(2) = 50

Picture1.Scale (0, 60)-(30, 30)

Picture1.AutoRedraw = True

Scala 0, 0, 3, 50

Picture1.Line (0, -20)-(0, 20)
Picture1.Line (-20, 0)-(20, 0)

Dim i As Integer

    For i = 0 To 3 'rispettivamente Xmin Xmax
        Picture1.Line (i, Y(i))-(i - 1, Y(i - 1)), vbRed
    Next i
    
End Sub


ma il grafico è sempre uguale...
Ultima modifica effettuata da feddur 08/09/08 13:48
aaa
08/09/08 14:23
antometal
al posto della y devi mettere valore
For i = 0 To 3 'rispettivamente Xmin Xmax
Picture1.Line (i, valore(i))-(i - 1, valore(i - 1)), vbRed
Next i

perchè non usi una funzione, ma dei valori che dai tu
puoi quindi togliere la function y che nn ti serve
aaa
08/09/08 14:25
antometal
un altra cosa...
l' array valore inizia a caricarlo da 1, perchè poi quando traccia la riga, il prog ha bisogno dell' indice -1 che nn esiste
aaa
08/09/08 15:06
feddur
scusami tanto, a non sono pratico di funzioni in VB..

ho fatto così (ancora poco elegante, ma sono solo delle prove per ora):


Dim valore(3) As Integer
Private Function Y(X As Integer) As Double
valore(i) = X
End Function

Private Sub Scala(Xmin As Integer, Ymax As Integer, Xmax As Integer, Ymin As Integer)
Picture1.Scale (Xmin, Ymax)-(Xmax, Ymin)
End Sub


Private Sub Form_Load()

valore(0) = 12
valore(1) = 30
valore(2) = 50

Picture1.Scale (0, 60)-(30, 30)

Picture1.AutoRedraw = True

Scala 0, 0, 3, 50

Picture1.Line (0, -20)-(0, 20)
Picture1.Line (-20, 0)-(20, 0)

Dim i As Integer

    For i = 0 To 3 'rispettivamente Xmin Xmax
        Picture1.Line (i, Y(i))-(i - 1, Y(i - 1)), vbRed
    Next i
    
End Sub


grazie per la pazienza!
aaa
08/09/08 16:00
antometal
Private Sub Scala(Xmin As Integer, Ymax As Integer, Xmax As Integer, Ymin As Integer)
Picture1.Scale (Xmin, Ymax)-(Xmax, Ymin)
End Sub

Private Sub Form_Load()
dim valore(3) as integer
valore(1) = 12
valore(2) = 30
valore(3) = 50

Picture1.AutoRedraw = True

Scala 0, 0, 3, 50

'se visualizzi solo il primo quadrante non ha bisogno degli assi perchè nn si vedrebbero, cmq possono rimanere
Picture1.Line (0, -20)-(0, 20)
Picture1.Line (-20, 0)-(20, 0)

Dim i As Integer

    For i = 0 To 3 'rispettivamente Xmin Xmax
        Picture1.Line (i, valore(i))-(i - 1, valore(i - 1)), vbRed
    Next i
End Sub


prova così che dovrebbe andare

cmq le funzioni come le sub, che in + restituiscono un valore contenuto nel nome della funzione
tipo:

private function raddoppia(num as integer)as integer
raddopia=num*2
end function

private sub form_load()
me.caption=raddoppia(5) 'in questo caso me.caption avrà il valore 10
end sub
aaa
08/09/08 17:48
feddur
mi evidenzia questo
Picture1.Line (i, valore(i))-(i - 1, valore(i - 1)), vbRed


e dice che è fuori range..
aaa
08/09/08 18:02
antometal
fa partire il for da 1
for i=1 to 2
in questo modo va sicuro
aaa
08/09/08 19:40
feddur
funziona benissimo, potresti spiegarmi gentilmente come funziona questo comando?
Scala 0, 0, 23, 1



aaa