Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 18011
Number of posts: 55384

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Yet another problem... Posted by aaronjones3593 on 27 Feb 2007 at 3:11 AM
This message was edited by aaronjones3593 at 2007-2-27 3:17:27


Got another problem now.
I don't know what's wrong with me I used to be able to program fine lol.


    ...

    Dim iContinue As Integer

    Dim BallotAddCount As Integer
    Dim NewBallotCount As Integer
    BallotAddCount = 0
    
    Do While iContinue = vbYes
    
        NewBallotCount = NumberOfBallots + BallotAddCount + 1
        ReDim Preserve VoteArray(NewBallotCount, NumberOfCandidates)
        
        ...

        BallotAddCount = BallotAddCount + 1
        iContinue = MsgBox("You have added " & BallotAddCount & " ballots." & vbNewLine & _
                           "Would you like to add more?", vbYesNo + vbApplicationModal, _
                           "Add Another Ballot: Yes or No?")

        
    Loop

    ...



NumberOfBallots = 10
NumberOfCandidates = 4 [Got from inputbox]

Array was already VoteArray(NumberOfBallots, NumberOfCandidates)

[I'm coding a transferrable vote system]

ReDim Preserve blahblah don't wanna do it
[Subscript out of range]

btw I'm using Option Base 1

And the subscript IS IN RANGE
[I checked with the locals window]


-( Aaron )-
"Pain doesn't hurt, if it's all you've ever felt."






Report
Re: Yet another problem... Posted by KhalilDutch on 27 Feb 2007 at 3:55 AM
Aaron,

This is from the MSDN Library and should explain your problem...

If you use the Preserve keyword, you can resize only the last array
dimension and you can't change the number of dimensions at all. 
For example, if your array has only one dimension, you can resize that
dimension because it is the last and only dimension. However, if your 
array has two or more dimensions, you can change the size of only the last
dimension and still preserve the contents of the array. 


Cheers,
--KhalilDutch--
___________________________
If ... Then
...
Else
...
Whatever....


Report
Re: Yet another problem... Posted by aaronjones3593 on 27 Feb 2007 at 4:43 AM
This message was edited by aaronjones3593 at 2007-2-27 4:45:14


So I have to swap Ballots for Candidates then?

i.e. from VoteArray(NoOfBallots, NoOfCandidates)
to VoteArray(NoOfCandidates, NoOfBallots)

Because from this point in the code I only eveer ever need to change the number of Ballots.


Report
Re: Yet another problem... Posted by KhalilDutch on 27 Feb 2007 at 5:02 AM
If your NoOfBallots is the variable one, yes you do.

Cheers!
--KhalilDutch--
___________________________
If ... Then
...
Else
...
Whatever....


Report
Re: Yet another problem... Posted by aaronjones3593 on 27 Feb 2007 at 5:11 AM
: If your NoOfBallots is the variable one, yes you do.

Damnit, that's a pain in the ass.

Oh well. -sighs- thanks for your assistance, I'll get started on that now I guess... Only, 80 lines to go through swapping nested loops and variable names?

lol. thankyou.


-( Aaron )-
"Pain doesn't hurt, if it's all you've ever felt."

Report
Re: Yet another problem... Posted by BitByBit_Thor on 27 Feb 2007 at 6:34 AM
: : If your NoOfBallots is the variable one, yes you do.
:
: Damnit, that's a pain in the ass.
:
: Oh well. -sighs- thanks for your assistance, I'll get started on that now I guess... Only, 80 lines to go through swapping nested loops and variable names?
:
: lol. thankyou.
:
:
: -( Aaron )-
: "Pain doesn't hurt, if it's all you've ever felt."
:
:

Or write some code to manually preserve the items.

Best Regards,
Richard

The way I see it... Well, it's all pretty blurry




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.