Help with string parsing/manipulation Part 2 (1 Viewer)

Talismanic

Registered User.
Local time
Today, 02:30
Joined
May 25, 2000
Messages
377
Well it didn't take very long for them to ask me to modify the output of the application. I thought I could figure it out but that was not the case, so I am back asking for more help.

In my previous Brain Teaser post I only needed to evaluate one text box with one output. Now I need to look at five text boxes and prodcuce 5 results. Since I am starting to get my mind around arrays I thought I could use Control Arrays, not the case with Access.

I know that I have to do something like this (found example on another post):

index = 0
For i = 1 to 10
if txtText(index) = whatever then
do something
end if
index = index + 1
next i

But I am not sure how to work that into this code. The 5 boxes that need to be evaluated are CodePick1, CodePick2, etc... and Answer1, Answer2 etc...

Dim myArray(8) As String
Dim i As Integer
Dim strEval As Integer
Dim OC(8) As String
Dim TempString As String

myArray(1) = " - 9th Hour Mon-Fri"
myArray(2) = " - 10th Hour Mon-Fri"
myArray(3) = " - Over 10 Hours"
myArray(4) = " - First 8 Hours Saturday"
myArray(5) = " - 9th hour Saturday"
myArray(6) = " - 10th Hour Saturday"
myArray(7) = " - Over 10 Hour Saturday"
myArray(8) = " - Any Hrs Sunday or Holiday"

For i = 1 To 8
OC(i) = Mid(CodePick, i, 1)
Select Case OC(i)
    Case "H"
TempString = "Time & 1/2"
    Case "B"
TempString = "Basic Hour Rate"
    Case "X"
TempString = "Time & 1/2 Over 40"
    Case "D"
TempString = "Double Time"
    Case "T"
TempString = "Triple Time"
End Select

OC(i) = i & " = " & Mid(CodePick, i, 1) & myArray(i) & _
    " - " & TempString
Next i
 

DALeffler

Registered Perpetrator
Local time
Yesterday, 19:30
Joined
Dec 5, 2000
Messages
263
One way to do it is by using the names of your five text boxes and a 2 dimensional array to contain the answers:
Code:
Dim myArray(8), txtbxNames(5) As String
Dim i As Integer
Dim strEval As Integer
Dim OC(8,5) As String
Dim TempString As String 
txtbxNames(1) = “CodePick1”
txtbxNames(2) = “CodePick2”
txtbxNames(3) = “CodePick3”
txtbxNames(4) = “CodePick4”
txtbxNames(5) = “CodePick5”
myArray(1) = " - 9th Hour Mon-Fri"
myArray(2) = " - 10th Hour Mon-Fri"
myArray(3) = " - Over 10 Hours"
myArray(4) = " - First 8 Hours Saturday"
myArray(5) = " - 9th hour Saturday"
myArray(6) = " - 10th Hour Saturday"
myArray(7) = " - Over 10 Hour Saturday"
myArray(8) = " - Any Hrs Sunday or Holiday"

For J = 1 to 5
CodePick = me(txtbxNames(J))

   For I = 1 To 8
   OC(I,J) = Mid(CodePick, I, 1)
   Select Case OC(I,J)
   Case "H"
   TempString = "Time & 1/2"
   Case "B"
   TempString = "Basic Hour Rate"
   Case "X"
   TempString = "Time & 1/2 Over 40"
   Case "D"
   TempString = "Double Time"
   Case "T"
   TempString = "Triple Time"
   End Select 
   OC(I,J) = I & " = " & Mid(CodePick, I, 1) & myArray(I) & _
   " - " & TempString
   Next I
Next J

You’re 5 answers are in the 2 dimensional array OC.

Code:
Answer1 | Answer2 | Answer3 | Answer4 | Answer5
OC(1,1) | OC(1,2) | OC(1,3) | OC(1,4) | OC(1,5)
OC(2,1) | OC(2,2) | OC(2,3) | OC(2,4) | OC(2,5)
OC(3,1) | OC(3,2) | OC(3,3) | OC(3,4) | OC(3,5)
OC(4,1) | OC(4,2) | OC(4,3) | OC(4,4) | OC(4,5)
OC(5,1) | OC(5,2) | OC(5,3) | OC(5,4) | OC(5,5)
OC(6,1) | OC(6,2) | OC(6,3) | OC(6,4) | OC(6,5)
OC(7,1) | OC(7,2) | OC(7,3) | OC(7,4) | OC(7,5)
OC(8,1) | OC(8,2) | OC(8,3) | OC(8,4) | OC(8,5)

And you just need do another nested loop to get them out (the same way they were put in)

Doug
 

Talismanic

Registered User.
Local time
Today, 02:30
Joined
May 25, 2000
Messages
377
Make sure I have this right because I am getting undeclared variable warnings among others.

txtbxNames(1) = should be replaced with the fiels where my answer goes?

CodePick1 = the field that the code will reside in?



[This message has been edited by Talismanic (edited 08-08-2001).]
 

DALeffler

Registered Perpetrator
Local time
Yesterday, 19:30
Joined
Dec 5, 2000
Messages
263
The undeclared variable error is because of the "J" not being declared (oops, sorry).

Dim J as Integer

txtbxNames(n) should be assigned to the Names of the text boxes on the form that contains the strings you need to parse out. I thought that would be textboxes with the name "CodePick1" thru "CodePick5".

Doug - be back in a couple hrs...
 

Talismanic

Registered User.
Local time
Today, 02:30
Joined
May 25, 2000
Messages
377
Thanks for the help so far, DALeffler, but I can not get my head around this. Do you have a sample database with a small array that I could take a look at?
 

DALeffler

Registered Perpetrator
Local time
Yesterday, 19:30
Joined
Dec 5, 2000
Messages
263
Sure!

I just got home - no www at work - give me a half hour or so and it'll be on it's way.

Doug.
 

DALeffler

Registered Perpetrator
Local time
Yesterday, 19:30
Joined
Dec 5, 2000
Messages
263
Your demo is on the way.

Don't make arrays any harder than they really are - an Excel spread sheet is a example of a two dimensional array consisting of rows and columns.

Whenever an array is defined with two dimensions - as in "Dim OC(8,5) as String" - Access creates an Excel like "mini" spreadsheet that we're calling OC.

OC will now have 8 rows and 5 columns.

So when I see something like OC(3,5), I think 3rd row, 5th column.

The nested loops like:
Code:
For J = 1 to 5
   For I = 1 to 8
   ....
   Next I
Next J
Is just a way of getting to all the values in all the rows of a single column before moving over and doing something with all the values in all the rows of the next column.

In the above example, the "For/Next I" loop is the row counter. It loops through all the rows in our OC array - 8 rows.

The "For/Next J" loop is the column counter. It loops through all the columns of our OC array - 5 columns.

So we put the row loop (the For/Next I loop) "inside" the column loop (the For/Next J loop) so's the I loop loops 8 times for every J loop.

Have I got'cha Loopy, yet?

hth,

Doug.

[This message has been edited by DALeffler (edited 08-09-2001).]
 

Talismanic

Registered User.
Local time
Today, 02:30
Joined
May 25, 2000
Messages
377
I started Loopy, you straightened me out.

I have been working through the code and I think I (some what) understand what is going on.

Thanks for all the help!!!
 

Users who are viewing this thread

Top Bottom