There are several reasons why the graph fails to draw. The axes are only drawn as you put the code of the "DrawAxes" subroutine within the "Picture1_Click" event subroutine.
Code:
Private Sub Picture1_Click()
Call Picture1.Cls
Dim x As Long
Dim y As Long
x = 0
y = 0
For x = 0 To Picture1.ScaleWidth
Picture1.PSet (x, 0 + (Picture1.ScaleHeight / 2)), &H8080FF 'this is light grey colour
Next x
For y = 0 To Picture1.ScaleWidth
Picture1.PSet (0 + (Picture1.ScaleWidth / 2), y), &H8080FF
Next y
End Sub
This means that the "DrawGraph" subroutine will never be called as you did not put any code in to call it.
What you will need to do is cut the code segment shown above that is below the
"Private Sub Command1_Click()" and "End Sub" statements and create a new function as such:
Code:
Public Sub DrawAxes()
Call Picture1.Cls
Dim x As Long
Dim y As Long
x = 0
y = 0
For x = 0 To Picture1.ScaleWidth
Picture1.PSet (x, 0 + (Picture1.ScaleHeight / 2)), &H8080FF 'this is light grey colour
Next x
For y = 0 To Picture1.ScaleWidth
Picture1.PSet (0 + (Picture1.ScaleWidth / 2), y), &H8080FF
Next y
End Sub
Then say, within the "calculate" button (which youve called Command1) place the call to the DrawGraph statement:
This will mean that when the calculate button is pressed, the graph will be drawn.
--------
For your first question, you can alter the graph each time calculate is pressed, but i dont know what type of function you wish to graph. You only have one output for each of your calculations, so if this data is graphed, it would only be a horizontal line. You need to tell me what you want to graph in more detail so i can help you.
---------
For your second question, to change the value of the scale you will need to do something like the following:
If your "ScaleMode" is on "1 - Twip" then each multiple of 15 for the variable "aScale" will change the scale of the graph by 1 pixel. E.g. If you have aScale = 600 (600 / 15 = 40) Then 40 pixels will represent the value of "1" for the function.
If your "ScaleMode" is on "3 - Pixel" then each multiple of 1 for the variable "aScale" will change the scale of the graph by 1. This is simpler, aScale = 1, then 1 pixel represents 1 for the function.
The advantage of using Twips over Pixels however is that you will get a smoother graph for rapidly increasing/decreasing functions such as the exponential function.
View attachment 13239
Also theres a few things about your code that you could improve, well it doesnt really matter but im just saying anyway.
Code:
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Label3.Caption = "enter loan"
Label4.Caption = "enter months"
Label5.Caption = "enter rate"
End Sub
In visual basic you dont have to set properties of the objects in this way. For your text boxes, youve removed the default "Text#" that appears when you first create the object, leaving the text blank. Upon startup it will remain blank (until you enter something of course) so there is no need for the first three statements.
Also within the properties of the lables you can set the caption without the need to do it through code. It doesnt really matter but incase you werent aware then yeah im just saying.