Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Last 10 text box inputs


Xlithan
 Share

Recommended Posts

If we're not using VB6, but .Net we can do some cheap trick like this to make life a little easier:

```
internal class RollingList : List {

private Int32 _cap;

internal RollingList(Int32 maxcapacity) {
_cap = maxcapacity;
}

internal new void Add(T item) {
base.Add(item);
if (this.Count() > _cap) base.Remove(this.First());
}

internal new void AddRange(IEnumerable collection) {
foreach (var item in collection) this.Add(item);
}
}

```
Saves you the hassle of dealing with keeping track of stuff. :) Unfortunately, in VB6 the solution would be a little less elegant.. I don't have a copy of VB6 installed right now, so can't really provide the code required. But you'd basically be shifting your array up one every time you add a new item to it.
Link to comment
Share on other sites

  • 2 weeks later...
Ok so I've tried the following (Feel free to use)

```
' Last Command Memory
Public LastCommand(1 To 10)                        As String
Public CommandArray                                As Byte
```
When the player presses Enter, it does this…

```
' Last Command Memory
       If MyText <> vbNullString Then
           LastCommand(10) = LastCommand(9)
           LastCommand(9) = LastCommand(8)
           LastCommand(8) = LastCommand(7)
           LastCommand(7) = LastCommand(6)
           LastCommand(6) = LastCommand(5)
           LastCommand(5) = LastCommand(4)
           LastCommand(4) = LastCommand(3)
           LastCommand(3) = LastCommand(2)
           LastCommand(2) = LastCommand(1)
           LastCommand(1) = MyText
       End If
```
What I'm having problems with, is that the following doesn't work. I don't know how to check if the player presses the Up key.

```
   If KeyAscii = vbKeyUp Then
       ' Last Command Memory
       If CommandArray = 10 Then
           frmGame.txtCommand.Text = vbNullString
           MyText = frmGame.txtCommand.Text
           Exit Sub
       End If

       CommandArray = CommandArray + 1
       frmGame.txtCommand.Text = LastCommand(CommandArray)
       MyText = frmGame.txtCommand.Text
   End If
```

* * *

Ok I've figured it out. I have to use the _KeyDown procedure on the textbox

* * *

If anybody is interested in doing this, this is what I did, and it now runs 100% without any errors. You may need to adjust the code to work with later versions of Eclipse.

```
Private Sub txtCommand_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then
' Last Command Memory
If CommandArray = 10 Then Exit Sub

If LastCommand(CommandArray + 1) = vbNullString Then Exit Sub

CommandArray = CommandArray + 1
frmGame.txtCommand.Text = LastCommand(CommandArray)
MyText = frmGame.txtCommand.Text
End If

If KeyCode = vbKeyDown Then
' Last Command Memory
If CommandArray <= 1 Then
frmGame.txtCommand.Text = vbNullString
MyText = frmGame.txtCommand.Text
CommandArray = 0
Exit Sub
End If

CommandArray = CommandArray - 1
frmGame.txtCommand.Text = LastCommand(CommandArray)
MyText = frmGame.txtCommand.Text
End If
End Sub
```
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...