how to start modify array value?
Hi guys, I want to modify that myArr() value?
here is myArr()
myArr(0,0) = "john"
myArr(1,0) = "Jan"
myArr(0,1) = "mary
myArr(1,1) = "Dec"
myArr(0,2) = "sam"
myArr(1,2) = "Feb"
I want to modify "mary" , "Dec" to -> "mary" , "OCT"
how to start ?
please!
Re: how to start modify array value?
Well, you use:
myArr(0,1) = "mary
myArr(1,1) = "Dec"
So...
myArr(0,1) = "mary
myArr(1,1) = "OCT"
Re: how to start modify array value?
thanks, but I need this styles
how to start ,
please!
Code:
Text1.Text = "mary"
Text2.Text = "afterchaged"
for i = lbound(myArr,2) to ubound(myArr,2)
if myArr(0,i) = text1.text then
....modify that item
end if
next i
Code:
myArr(0,0) = "john"
myArr(1,0) = "Jan"
myArr(0,1) = "mary
myArr(1,1) = "afterchanged"
myArr(0,2) = "sam"
myArr(1,2) = "Feb"
Re: how to start modify array value?
Oh! You want to search.
Replace: ....modify that item
With: myArr(1,i) = "OCT"
Bon Appétit!
Re: how to start modify array value?
thanks, here i rewrite it, but faild ?
'Form 1
Code:
Option Explicit
Private Sub Command1_Click()
Call replacevalue(Text1.Text, Text2.Text)
End Sub
Private Sub Command2_Click()
Dim i As Integer
For i = LBound(myArr) To UBound(myArr)
List2.AddItem myArr(0, i) & ">" & myArr(1, i)
Next i
End Sub
Private Sub Form_Load()
Dim myArr() As String
ReDim myArr(0 To 1, 0 To 2)
myArr(0, 0) = "john"
myArr(1, 0) = "Jan"
myArr(0, 1) = "mary"
myArr(1, 1) = "Dec"
myArr(0, 2) = "sam"
myArr(1, 2) = "Feb"
End Sub
'Module 1
Code:
Option Explicit
Public myArr() As String
Public Function replacevalue(ByVal a As String, ByVal b As String)
Dim xi As Integer
For xi = LBound(myArr, 2) To UBound(myArr, 2)
If myArr(0, xi) = a Then
myArr(0, xi) = "was-changed" & myArr(0, xi)
myArr(1, xi) = "was-changed" & b
End If
Next xi
End Function
Re: how to start modify array value?
You declare myArr() in Form_Load where it is non-persistent and limited in scope to that procedure(Form_Load).
Local scope takes priority over your public declaration in the module. You could fully-qualify it: Module1.myArr(). BUT...
My suggestion is to remove that Dim myArr() in Form_Load. Leave the ReDim statement.