Problems with Type…

View: New views
3 Messages — Rating Filter:   Alert me  

Problems with Type…

by Johnny Rosenberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Type MyType
        Nick As String
        Status As Boolean
        Something As Integer
End Type

Sub BlahBlah
        Dim MyArray(7) As MyType

        Dim Sheet As Object, Range As Object
        Sheet=ThisComponent.getSheets().getByName("Sheet1")
        Range=Sheet.getCellRangeByPosition(1,3,8,3) ' One row, eight columns

        Dim TempArray() As Variant
        TempArray()=Range.getDataArray()
        MyArray().Nick=TempArray(0) ' This line produces the error message
”BASIC runtime error. Object variable not set.”
End Sub

As I commented above, I get an error message. I have checked that all
variables exist and that arrays have the correct size and so on. Is
this just not possible?

Suggestions?

What I want to achieve? Well, in this short example, let's say that
the cell range B4:I4 contains the following:
B4: "One"
C4: "Two"
D4: "Three"
E4: "Four"
F4: "Five"
G4: "Six"
H4: "Seven"
I4: "Eight"

Then I expect the following variables containing the following:
MyArray(1).Nick="One"
MyArray(2).Nick="Two"
MyArray(3).Nick="Three"
MyArray(4).Nick="Four"
MyArray(5).Nick="Five"
MyArray(6).Nick="Six"
MyArray(7).Nick="Seven"
MyArray(8).Nick="Eight"

Am I totally approaching this the completely wrong way?

Johnny Rosenberg

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...


Re: Problems with Type…

by Bernard Marcelly :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Message de Johnny Rosenberg  date 2009-09-05 13:24 :

> MyArray().Nick=TempArray(0) ' This line produces the error message
> ”BASIC runtime error. Object variable not set.”
>
> Then I expect the following variables containing the following:
> MyArray(1).Nick="One"
> MyArray(2).Nick="Two"
> MyArray(3).Nick="Three"
> MyArray(4).Nick="Four"
> MyArray(5).Nick="Five"
> MyArray(6).Nick="Six"
> MyArray(7).Nick="Seven"
> MyArray(8).Nick="Eight"
>
> Am I totally approaching this the completely wrong way?

Yes.

Basic does not allow this (and probably no other language).
You can assign an array of String to an array of String, or to a Variant. But
not to a string in each structure of an array of structures.

Regards
   Bernard


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...


Re: Problems with Type…

by Johnny Rosenberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/9/5 Bernard Marcelly <marcelly@...>:

> Message de Johnny Rosenberg  date 2009-09-05 13:24 :
>>
>>        MyArray().Nick=TempArray(0) ' This line produces the error message
>> ”BASIC runtime error. Object variable not set.”
>>
>> Then I expect the following variables containing the following:
>> MyArray(1).Nick="One"
>> MyArray(2).Nick="Two"
>> MyArray(3).Nick="Three"
>> MyArray(4).Nick="Four"
>> MyArray(5).Nick="Five"
>> MyArray(6).Nick="Six"
>> MyArray(7).Nick="Seven"
>> MyArray(8).Nick="Eight"
>>
>> Am I totally approaching this the completely wrong way?
>
> Yes.
>
> Basic does not allow this (and probably no other language).
> You can assign an array of String to an array of String, or to a Variant.
> But not to a string in each structure of an array of structures.
>
> Regards
>  Bernard

But it would be very nice if it worked…
OK, that's not a big deal. This works:

Dim TempArray0(7) As String
Dim i As Integer
TempArray0()=TempArray(0)
For i=1 To 8
        MyArray(i).Nick=TempArray0(i)
Next i

I was just hoping to solve it without a For statement.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...