I have problem, how to fix "S" ?
When RUN, Said "No DIM "S" ?
Would you mind to copy-pause to try run it!?
Any idea please!
'Module1
Option Explicit
Public Function readV() As Variant
Dim I As Integer
Dim Todays_date As Date
Dim S As Integer
S = 0
Todays_date = Now
For I = -2 To 3
VData(S, 0) = "apple-" & (Format(Todays_date - I, "YYYY")) & "" & (Format(Todays_date - I, "MM")) & "" & (Format(Todays_date - I, "DD"))
VData(S, 1) = "dmy=" & (Format(Todays_date - I, "YYYY")) & "" & (Format(Todays_date - I, "MM")) & "" & (Format(Todays_date - I, "DD")) & ""
Debug.Print S
readV = VData
S = S + 1
Next I
End Function
'///////////////////////////////////////////
'Form1
Private Sub Command1_Click()
Dim VData As Variant
Dim cv As Long
VData = readV()
For cv = LBound(VData) To UBound(VData)
List1.AddItem VData((cv), 0)
Next cv
End Sub '//Private Sub Command1_Click()
Roger_Wgnr 08-30-2009, 07:56 AM And the problem you have is?
When RUN, Said "No DIM "S" ?
Would you mind to copy-pause to try run it!?
Any idea please!
mkaras 08-30-2009, 04:23 PM Your VData array is declared inside the Form Event routine.
Any references to a VData in the module are attempts to access an array that is out of scope.
You may need to try moving the declaration of VData over to the module, outside the subroutine, and giving it the "Public" attribute. This may solve the problem of unknown dimensions of VData.
Note that in no way am I suggesting that the Public variable in the global section of the module is the "correct and best design" method to fix your problem. I can simply see variable scoping problems in the code snippett you sent.
mkaras
Would you mind to help me to done this code
2D problem
any idea please!
Private Sub Command1_Click()
Dim VData() As Variant
Dim i As Integer
ReDim VData(0) 'start with 1 element in array
For i = -7 To 4
VData((UBound(VData)), 0) = "apple" & i
VData((UBound(VData)), 1) = "boy" & i
ReDim Preserve VData(UBound(VData) + 1, 0)
ReDim Preserve VData(UBound(VData) + 1, 1)
Next i
ReDim Preserve VData(UBound(VData) - 1, 0)
ReDim Preserve VData(UBound(VData) - 1, 1)
List1.AddItem "apple>" & LBound(VData, 0) & "to" & UBound(VData, 0)
List1.AddItem "boy>" & LBound(VData, 1) & "to" & UBound(VData, 1)
End Sub
Flyguy 08-31-2009, 05:47 AM Only the last dimension of an dynamic array can be redimensioned.
would you mind give me example ?
I try only 1D VData(0), can sucess.
Why not simple 2D (VData0,0) not success?
Flyguy 08-31-2009, 11:21 AM Swap the array indices.
VData(0, (UBound(VData))) = "apple" & i
VData(1, (UBound(VData))) = "boy" & i
' ReDim Preserve VData(0, UBound(VData) + 1)
' Only for the highest bound of dimension 1
ReDim Preserve VData(1, UBound(VData) + 1)
Sorry, Is this correct ? I do not understand why
For i = -7 To 4
VData(0, (UBound(VData))) = "apple" & i
0,1 'that array
0,2
0,3
0,4
0,5
...etc
VData(1, (UBound(VData))) = "boy" & i
1,0
1,1
1,2
1,3
1,4
1,5
...etc
Next i
I know this Array I can handle
VData(0, 0) = "Apple-20090801" 'that array
VData(0, 1) = "20090801"
VData(1, 0) = "Apple-20090802"
VData(1, 1) = "20090802"
VData(2, 0) = "Apple-20090803"
VData(2, 1) = "20090803"
VData(3, 0) = "Apple-20090804"
VData(3, 1) = "20090804"
VData(4, 0) = "Apple-20090805"
VData(4, 1) = "20090805"
VData(5, 0) = "Apple-20090806"
VData(5, 1) = "20090806"
VData(6, 0) = "Apple-20090807"
VData(6, 1) = "20090807"
...etc
What diff? Please!
Thank you!
Private Sub Command1_Click()
Dim VData() As Variant '2D
Dim i As Integer
ReDim VData(0, 0) 'start with 1 element in array
ReDim VData(0, 1) 'start with 1 element in array
For i = -7 To 4
VData(0, (UBound(VData))) = "apple" & i
VData(1, (UBound(VData))) = "boy" & i
ReDim Preserve VData(1, UBound(VData) + 1)
Next i
ReDim Preserve VData(1, UBound(VData) - 1)
List1.AddItem ">" & LBound(VData) & "to" & UBound(VData)
End Sub
Flyguy 09-01-2009, 02:00 AM VData(0, 0) = "Apple-20090801" 'that array
VData(0, 1) = "20090801"
VData(1, 0) = "Apple-20090802"
VData(1, 1) = "20090802"
VData(2, 0) = "Apple-20090803"
VData(2, 1) = "20090803"
VData(3, 0) = "Apple-20090804"
VData(3, 1) = "20090804"
VData(4, 0) = "Apple-20090805"
VData(4, 1) = "20090805"
VData(5, 0) = "Apple-20090806"
VData(5, 1) = "20090806"
VData(6, 0) = "Apple-20090807"
VData(6, 1) = "20090807"
The indices are in the wrong order:
VData(0, 0) = "Apple-20090801" 'that array
VData(1, 0) = "20090801"
..
VData(0, 6) = "Apple-20090807"
VData(1, 6) = "20090807"
To get the boundaries of the second dimension, you have to specify an additional parameter:
List1.AddItem ">" & LBound(VData, 2) & "to" & UBound(VData, 2)
Maybe try this case:
First, Building total UNKNOW FLOOR , from (carpark to roof)
Each floor (A-Unit say Apple), (B-Unit say Boy)
Now , Use For ; Output: (Total NUMBERS element.)
total_floor.Text = Roof.Text - Carpark.Text
For i = Val(Carpark.Text) To Val(Roof.Text)
So need use (dynamic arrays) correct ?
this code is correct ? please!
Option Explicit
Private Sub Command1_Click()
List2.Clear
Dim i As Integer
Dim N As Integer
Dim myArray() As String
Dim total_floor As Double
total_floor = Val(Roof.Text) - Val(CarPark.Text)
'ReDim Preserve myArray(9, 1)
ReDim Preserve myArray(total_floor, 1)
N = 0
For i = Val(CarPark.Text) To Val(Roof.Text)
myArray(N, 0) = "apple" & i
myArray(N, 1) = "boy" & i
N = N + 1
Next i
Dim cm As Integer
For cm = LBound(myArray) To UBound(myArray)
List2.AddItem myArray(cm, 0) & ">" & myArray(cm, 1)
Next cm
End Sub 'cmd1
Flyguy 09-01-2009, 03:50 AM If you know the number of items you want to store in your array then you do not need a dynamic array.
If you need 9 items then dimension myArray(8,1), because it starts with 0.
From 0 to 8 gives you 9 items
There is no need to dimension your array as Variant, just use String
I really don't understand your question.
So Sorry! Now UPDATE#11:
I think is success run it, would you mind to check is correct dimension ?
Flyguy 09-01-2009, 04:22 AM It looks OK!
|