Problem Using Array

Ripley

Registered User.
Local time
Today, 12:53
Joined
Aug 4, 2006
Messages
148
Hello. I program in VB.NET, and i prefer not to use access whereever possible, (please dont be offended!), ive been asked to write a program in access, and took to the challenge.

This is probably one of the simplest things ever, but i'm having trouble declaring an array.

The problem code is as follows:

Code:
Private Sub btn_Calc_Click()
Dim strStringValue as String
strStringValue = Me.Form.NetPrice
Dim strStrLength As Integer
strStrLength = Len(strStringValue)

Assuming that the Len() function is the VBA equivilent of the .NET's string.Length function, then the following should work:

Code:
Dim strSubString(strStrLength) As String

The code then goes into some itteration statements, blah, blah. But all that works.

The problem is declaring the 2D array by the value of the Len(strStringValue).
Can anyone help? :confused:
 
I think you need ReDim

ReDim strSubString(strStrLength) As String

HTH

Peter
 
In VBA a Dim statement isn't really an executable line. You can't set a breakpoint, for instance, on a Dim statement like you can in VB.Net, nor can you assign or use any variables.
For what you want to do check out the ReDim statement.
Code:
Private Sub btn_Calc_Click()
  Dim strSubString() as string
  ReDim strSubString(Len(Me.NetPrice)-1)
  ...
End Sub
And working with arrays you might like the Split(), Join(), and Array() functions.
 
ahh, i see!

Many Thanks for your help!
 

Users who are viewing this thread

Back
Top Bottom