PDA

View Full Version : Array manipulation



Berticus
07-05-2007, 12:27 PM
I'm not gonna really take the time to really learn vba seeing as how I don't have much need for it in the real world, and I really hate this language (in general I don't really like HLL's, and really prefer MLL's and the C syntax). So all I have is a working knowledge of this thing.

Anyway, I'm trying to do some general array manipulations, so as the parameter I specify that it accepts an array of type variant, such as the following:
Sub MyArrayFunction(SomeParameter() As Variant)The problem is when I do something like:
Dim MyArray As String

MyArrayFunction MyArrayDuring the "compiling" process I encounter an error due to a type mis-match. It says it's looking for an array or user-defined type. So I was wondering, how can I create array manipulating procedures regardless of the array data type.

Also, I've tried using Object instead of Variant, and it produced the same results.

RichardSchollar
07-05-2007, 12:42 PM
Hi Berticus & Welcome to VBAExpress!

The following works for me:

Sub Testit()
Dim myArray as string
MyArrayFunction MyArray
Debug.Print UBound(MyArray)
End Sub

Sub MyArrayFunction(SomeParameter As Variant)
ReDim SomeParameter(1 to 10)
End Sub

Best regards

Richard

Berticus
07-05-2007, 12:51 PM
Hey, thanks for the quick reply. I didn't do the second code block correctly. MyArray is suppose to start out as an array of type String. So more appropriately:
Dim MyArray() As String

MyArrayFunction MyArrayBasically the array goes in, and it gets manipulated regardless of type.

RichardSchollar
07-05-2007, 01:02 PM
Sorry, I posted that incorrectly - you just need to leave off the parentheses from the variant argument to the sub (and have myarray declared as a dynamic array which you have done in your second code)

Sub Testit()
Dim myArray() As String
MyArrayFunction MyArray
Debug.Print UBound(MyArray) 'demonstrate it has worked
End Sub

Sub MyArrayFunction(SomeParameter As Variant)
ReDim SomeParameter(1 To 10) 'do something with passed in reference
End Sub

Make sense?

Richard

Berticus
07-05-2007, 01:06 PM
Ah, I see. Thanks

Bob Phillips
07-05-2007, 02:11 PM
I'm not gonna really take the time to really learn vba seeing as how I don't have much need for it in the real world, and I really hate this language (in general I don't really like HLL's, and really prefer MLL's and the C syntax). So all I have is a working knowledge of this thing.

I don't know, is it me, or is that the sort of opening sentence that makes me thing, ooh, I must rush and help this guy as he has such a good attitude.

TrippyTom
07-05-2007, 02:23 PM
Hehe... it's not just you. I was thinking the same thing, but perhaps he had a little too much sun yesterday during the Holiday celebrations and was experiencing "fried brain" syndrome or something.

Everyone has bad days... hopefully that's all it was.

RichardSchollar
07-05-2007, 02:57 PM
I don't know, is it me, or is that the sort of opening sentence that makes me thing, ooh, I must rush and help this guy as he has such a good attitude.

Yep it's you: you're just a grumpy old bugger, Bob!:goofball:
:beerchug:

Bob Phillips
07-05-2007, 03:46 PM
I know, but I know a good gin when I see one (and I certainly haven't seen one from you yet).

Ken Puls
07-05-2007, 04:25 PM
I don't know, is it me, or is that the sort of opening sentence that makes me thing, ooh, I must rush and help this guy as he has such a good attitude.

LOL! The only reason I scrolled down past that line is because I knew that there were already replies. I was curious who actually bit on it, as I don't think I would have bothered.

paulked
07-05-2007, 04:57 PM
I'm munching on a great Chinese Take-Away and pouring some Saffron Gin over ice and a slice... I've had enough tonight so the rest of the bottle :beerchug:
goes out to you guys for all your help and patience in the past :grouphug:.

ENJOY :friends:

BTW... What 'Real World' are you in Bert? Are we just a figmant of your dreams?

Bob Phillips
07-06-2007, 01:59 AM
Thankyou paulked ... to you.

Another Welsh colleague, and a gin drinker to boot.

From a gin drinking (and a few other things as well), Welsh descendant.

Berticus
07-06-2007, 05:49 AM
The reason for that little introduction was, it was a simple little thing and just needed a quick answer. Typically those basics should have been covered before someone even starts coding. At least that's what happened when I learned data types in C, C++, and Java. But for those languages I took "formal" classes, I suppose you would say. With VB(A), I just have a working knowledge. I thought I would be introduced with criticism. At least I would've criticized a person who really wanted to learn a language about them rushing in to learn a language and start coding right away instead of sitting down to actually get to know the language. Didn't think it would be advanced with criticism.

I don't plan to stick with VBA too much. Possibly just this summer for my job, but that's it (maybe next summer too). I'm teaching myself MatLab, and I prefer OOo2 over the Microsoft Office Suite at home/school (Regular Linux user). OOo2 has a different language than MS Office Suite for macro coding. I just learned about macros a few weeks ago, so I haven't taken a look into OOo2's choice of language. And when I meant "Real World," I just mean something that pertains to my field and that I'd actually use regularly. I'm just using VBA at a summer job.

Ken Puls
07-06-2007, 03:44 PM
Well... we'll give you points for honesty. Generally, though, the more aggressive someone appears, the less likely that they'll get responses from us.

We like to think that we're a pretty friendly group here generally, and we like to help people who need it. We're also not the type to blast someone because they're ignorant of VBA in any way. Many of us learned our craft by asking questions at this very site, and are painfully familiar with how hard it can be to get the compiler to do what you actually want.

If you need more help, feel free to come back an visit us. I'd suggest maybe just letting people know that you could do this in other languages but struggle with the VBA syntax, rahter than tell us you don't care to learn.

Cheers,

Bob Phillips
07-06-2007, 04:00 PM
I cannot just sit and take this.

The guy has dissed Excel, he has dissed VBA, but has taken a job where he is expected to use them. But rather than being honest and either quitting an earning his living in his version of the 'real world', or knuckling down and working at it, he has just said that he can't be a**#d, and chucked it at us to earn his salary for him. Sorry, but no!

Ken Puls
07-06-2007, 04:14 PM
Bob, I can actually visualize the look on your face as you read that!

You know... I've spent all day trying to be reasonable and understanding of fault. I was trying to put aside the dissing of the products that we love, but maybe I've gone a bit too far...

For reference, I wasn't actually trying to give lessons on how to fool us into helping. Rather it was intended to be advice on how to actually get help in the first place. I can't govern intent and certainly do not support throwing jobs at volunteers rather than learning to do it yourself.

Bob Phillips
07-06-2007, 04:23 PM
Ken,

I don't mind people being critical of Excel, VBA, or MS, God knows you have been, I have been, and so we should, always endeavour to keep them on their toes.

But I am not going to help anyone who basically says '... hey losers, sort out my problem, I can't be bothered with these pathetic tools'.

I would rather spend 3 hours trying to understand and help someone who can't properly articulate a problem but really wants to master their brief. The first posting was bad, the justification just told me they don't give a !#*?, so I am not going to either. Call me perverse, but I am not going to assist this attitude.