Xlithan Posted April 29, 2016 Author Share Posted April 29, 2016 Hi guys. I've seen some games that save the last 10 things you typed into the text box, by pressing Up on the keyboard. Does anybody know the best way to do this? Link to comment Share on other sites More sharing options...
Exception Posted April 29, 2016 Share Posted April 29, 2016 Store what was last entered into an array or queue or whatever, and just grab the previous item each time Up is pressed… Link to comment Share on other sites More sharing options...
Xlithan Posted April 29, 2016 Author Share Posted April 29, 2016 THat's what I was thinking. I figured that was the simplest way and maybe there was a better way of doing it. Link to comment Share on other sites More sharing options...
Joyce Posted May 2, 2016 Share Posted May 2, 2016 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 More sharing options...
Xlithan Posted May 10, 2016 Author Share Posted May 10, 2016 Ok so I've tried the following (Feel free to use)```' Last Command MemoryPublic LastCommand(1 To 10) As StringPublic 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 IfEnd Sub``` Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now