• Status: Solved
• Priority: Medium
• Security: Public
• Views: 168

# User defined mapping?

This is my current code, it works fine, but I need to add another element which I don't know how to go about it.  As you can see below,
txtLocation(0).text = Trim(Mid(strBuff, 342, 9))
txtLocation(1).text = Trim(Mid(strBuff, 424, 9))
and so on .... txtLocation(15)

Except, that I do not always want txtLocation(0).text = Trim(Mid(strBuff, 342, 9)).  It could equal any one of the 16 values.  A user would decide which values goes with which txtLocation.

The user input would come from from2, where there are 16 boxes called txtUserDefinedLocation(index).text

Thus if txtUserDefinedLocation(0).text =1 Then txtLocation(0).text = Trim(Mid(strBuff, 424, 9))

-------------------Code-----------------
Private Sub RefreshScreen1()

Dim strBuff As String
strBuff = Display.Contents

Dim i As Integer
Dim x As Integer

x = 342
For i = 0 To 15

txtLocation(i).Text = Trim(Mid(strBuff, x, 9))

x = x + 82

Next
End Sub

----------------End of Code------------

Thanks much
0
ptran2000
• 2
1 Solution

Commented:
Hi,

Actually, if your interval between all the elements is always 82.
I am assuming that the numbering in 1-based, and not zero-based as the array element indexes are.

Here's an updated function for you :

-------------------Code-----------------
Private Sub RefreshScreen1()

Dim strBuff As String
strBuff = Display.Contents

Dim i As Integer
Dim x As Integer
Dim iItemNr As Integer

x = 342
For i = 0 To 15
iItemNr = CInt(txtUserDefinedLocation(i).Text) - 1
txtLocation(i).Text = Trim(Mid(strBuff, (x + (iItemNr * 82)), 9))

Next
End Sub

----------------End of Code------------

In order to have it bulletbroof, you should first validate ALL the txtUserDefinedLocation text boxes for valid numeric input within the correct range (1 to 16)

Hope this helps.

0

Commented:
I'm not sure I get this, but is this what you're looking for??

Private Sub RefreshScreen1()

Dim strBuff As String
strBuff = Display.Contents

Dim i As Integer
Dim x As Integer

x = 342
For i = 0 To 15

txtLocation(i+1).Text = Trim(Mid(strBuff, x, 9))

x = x + 82

Next
End Sub

This would fill txtLocation(1) thru txtLocation(16) and not fill txtLocation(0)...

If this is not what you're looking for, please explain further...

0

Author Commented:
wouhou!  You got it PatrickVD!

Thanks a lot!
0

Commented:
Thanks for the compliment ptran2000 !
If happen to visit Belgium some day, you'll buy me a drink on this one ! ;-)

Happy coding,

Patrick.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.