Subscribe to our YouTube channel.Tutorials and more athttps://www.youtube.com/c/QB64Team.
0 Members and 1 Guest are viewing this topic.
I don't know why it's picking the wrong line, but the error is happening in the line that checks ELSEIF ASC(char) = 8 THEN. ASC will fail if the string passed to it is empty, which will happen immediately in your code because char = INKEY$ and when the procedure is started, no key has been pressed yet. Use this change instead:Code: QB64: [Select]Option _Explicit Const qbWHITE = _RGB32(255)Const qbGREY = _RGB32(127)Const qbBLACK = _RGB32(0)Const qbDARKGREY = _RGB32(67, 67, 67)Const qbORANGE = _RGB32(255, 128, 0)Const qbYELLOW = _RGB32(255, 255, 0)Const qbLIGHTGREY = _RGB32(64)Const qbCHARS = "12345d67890-=qwertyuiop[]asdfghjkl;#\zxcvbnm,./QWERTYUIOPASDFGHJKLZXCVBNM!$%^&*()_+{}:@~|<>? " Dim test As String Screen _NewImage(800, 600, 32) test = TextInputBox(200, 200, "some text", "") Print YesNoBox(100, 100, "test") Function YesNoBox$ (xPos As Integer, yPos As Integer, promptText As String) Dim char As String Dim chg As Integer _KeyClear chg = 0 Do char = InKey$ If char <> YesNoBox Then chg = 1 YesNoBox = char ElseIf char = Chr$(8) Then 'backspace YesNoBox = "" chg = 1 End If If chg = 1 Then Line (xPos, yPos)-(xPos + Len(promptText) * 17, yPos + 50), qbLIGHTGREY, BF Line (xPos, yPos)-(xPos + Len(promptText) * 17, yPos + 50), qbWHITE, B _PrintString (xPos + 2, yPos + 5), promptText _PrintString (xPos + 2, yPos + 30), YesNoBox _Display End If chg = 0 Loop Until UCase$(YesNoBox) = "Y" Or UCase$(YesNoBox) = "N" End Function Function TextInputBox$ (xPos As Integer, yPos As Integer, promptText As String, defaultInput As String) Dim charCount As Integer Dim char As String Dim chg As Integer charCount = 1 chg = 0 TextInputBox = defaultInput _KeyClear Do char = InKey$ If InStr(qbCHARS, char) Then TextInputBox = TextInputBox + char chg = 1 ElseIf char = Chr$(8) Then TextInputBox = Left$(TextInputBox, Len(TextInputBox) - 1) chg = 1 End If If chg = 1 Then Line (xPos, yPos)-(xPos + 300, yPos + 50), qbLIGHTGREY, BF Line (xPos, yPos)-(xPos + 300, yPos + 50), qbWHITE, B _PrintString (xPos + 2, yPos + 5), promptText _PrintString (xPos + 2, yPos + 30), TextInputBox _Display End If chg = 0 Loop Until _KeyDown(13) _KeyClearEnd Function