Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,343 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,755 people online right now. Registration is fast and FREE... Join Now!




Printing a array

 
Reply to this topicStart new topic

Printing a array, Not working

Onibeaver
25 Aug, 2008 - 10:58 AM
Post #1

New D.I.C Head
*

Joined: 23 Aug, 2008
Posts: 8

I want to initialize a array using numbers read in from the user and then print this array to a picture box.

here is the code
-----------------------------------------------------------------------------------

vb

Option Explicit
Dim InfoIn As Double
Dim InfoOut As Double
Dim FinalAverage As Double
Dim counter As Double
Dim UpCounter As Double
Dim OutPut As Double
Dim InPutz As Double
Dim save(9) As Double

Private Sub AVERAGE_Click()
UpCounter = 0
While UpCounter < 10
OutPut = save(UpCounter)
Picture1.Print OutPut
UpCounter = UpCounter + 1
Wend
End Sub
Private Sub ENTER_Click()
counter = 0
While counter < 10
InPutz = InputText
save(counter) = InPutz
counter = counter + 1
Wend
End Sub
---------------------------------------------------------------------------------



this only prints the last number inserted by user and not the whole array,
any suggestions?

also is there any way to actively run only segments of the code and see whats inside the array at any given time?
fore example insert a message-box and print the numbers in the array after every step?
User is offlineProfile CardPM
+Quote Post

Zhalix
RE: Printing A Array
25 Aug, 2008 - 04:18 PM
Post #2

D.I.C Head
**

Joined: 7 May, 2008
Posts: 218



Thanked: 9 times
My Contributions
Well, the reason it will only print the last number entered is because when you click the "Enter" button, it loops through the array and replaces each value. My recommendation (though there are many others ways to do this) is to make another variable that will tell you the current index of the array you're on.

This will also give you the benefit of making sure that they've entered all 10 values, no more, no less.

You can see how I put this to use below:

CODE
Dim intIndex As Integer
Dim dblSave(9) As Double

Private Sub cmdAverage_Click()

    Dim intCounter As Integer
    
    If intIndex = 10 Then
        For intCounter = 0 To 9
            picOutput.Print dblSave(intCounter)
        Next intCounter
    Else
        MsgBox "Please enter all 10 numbers.", vbCritical, "Error"
    End If
    
End Sub
Private Sub cmdEnter_Click()
    
    If intIndex < 10 Then
        If IsNumeric(txtInput.Text) Then
            dblSave(intIndex) = txtInput.Text
            txtInput.Text = ""
            txtInput.SetFocus
            intIndex = intIndex + 1
        Else
            MsgBox "Please enter a real number.", vbCritical, "Error"
        End If
    Else
        MsgBox "You've entered all the numbers.", vbCritical, "Error"
    End If

End Sub


I hope that helps.

*EDIT*
As for your other question, it's just as you said. For each step just tell it to either show a messagebox or use something like debug.print to show you what's going on.

This post has been edited by Zhalix: 25 Aug, 2008 - 04:21 PM
User is offlineProfile CardPM
+Quote Post

thava
RE: Printing A Array
26 Aug, 2008 - 03:22 PM
Post #3

D.I.C Regular
Group Icon

Joined: 17 Apr, 2007
Posts: 442



Thanked: 18 times
Dream Kudos: 50
My Contributions
hi

use the watch window and add the name of the variable for each step you can watch the changes in each and every data on that variable
for more informations

http://www.informit.com/library/content.as...&seqNum=204

and to sort your array use an bubble sore algorithm
search the algorithm in Google icon_up.gif

This post has been edited by thava: 26 Aug, 2008 - 03:29 PM
User is offlineProfile CardPM
+Quote Post

Onibeaver
RE: Printing A Array
28 Aug, 2008 - 09:49 AM
Post #4

New D.I.C Head
*

Joined: 23 Aug, 2008
Posts: 8

Thanks THAVA!!! I've been trying to find a way to whatch the array change in real time for awhile now! it was driving me nuts not knowing what was going on in there.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 08:24AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month