UCase for all user input

New to FreeBASIC? Post your questions here.
Post Reply
pepper
Posts: 5
Joined: Feb 07, 2009 1:22

UCase for all user input

Post by pepper »

Hello there,

I have a program written that is case sensitive (everything uppercase.)
I was hoping that I could include some code at the top of the program so that everything a user inputs will be converted to UCase.

I understand I can do this for each individual input, but there are a great many.

Thanks.
rdc
Posts: 1741
Joined: May 27, 2005 17:22
Location: Texas, USA
Contact:

Post by rdc »

I do not believe there is any way to do this from FB. I'm sure if there is, someone will post such.

You will probably need to create a function that converts the input to upper case and just route all your input through the function.
jevans4949
Posts: 1186
Joined: May 08, 2006 21:58
Location: Crewe, England

Post by jevans4949 »

Provided you can work with LINE INPUT, you could write a subroutine:

Code: Select all

sub ucaseinput (question As String, ByRef answer As String)
    Dim s1 As String
    Print question;
    Line Input s1
    answer = UCase(s1)
End Sub
Dim s0 As String
While s0<>"QUIT"
    ucaseinput("What is your answer? ",s0)
    Print s0
Wend
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Post by srvaldez »

perhaps there's a way set the caps lock at the begining of the program and reset it on exit
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Post by MichaelW »

Under Windows you can set caps lock no problem.

Code: Select all

#include "windows.bi"

dim ki(1) as INPUT_

if GetKeyState(VK_CAPITAL) = 0 then
  ki(0).type = INPUT_KEYBOARD
  ki(0).ki.wVk = VK_CAPITAL
  ki(1).type = INPUT_KEYBOARD
  ki(1).ki.wVk = VK_CAPITAL
  ki(1).ki.dwFlags = KEYEVENTF_KEYUP
  SendInput( 2, @ki(0), sizeof(INPUT_) )
end if

print GetKeyState(VK_CAPITAL)

sleep
And using a different method you can do it under DOS, I don’t know about Linux. The problem with this is that there is nothing to stop the user from resetting caps lock. I think the best solution would be to create an input function that does the conversion and use that for all input.
pepper
Posts: 5
Joined: Feb 07, 2009 1:22

Post by pepper »

I'll admit that most of this stuff is over my head, and what I ended up doing was converting the inputs to UCase after they were entered. For future programs, I will filter all inputs through an input function that does the conversation as was suggested a couple of times on this thread. Thank you all very much.
rolliebollocks
Posts: 2655
Joined: Aug 28, 2008 10:54
Location: new york

Post by rolliebollocks »

5 lines is easier to understand... Even though macros are politically incorrect somehow:

Code: Select all

#macro UcaseIn (var)

    dim as string var 
    line input, var
    var = ucase(var)

#endmacro

? "What is your name?";
UcaseIn(yourname)
? yourname
sleep
Post Reply