Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Ok Need help with my program

g4m3zfr34kg4m3zfr34k Member Posts: 16
right this is the deal i play a game called infantry and i want to make a program that verifys aliases (or names) that can be used for the game, but say if the user types [b]1killer[/b] i would want the program to reply saying that alias is not valid due to the fact it has a number at the front can any1 help me here?
[email protected]

Comments

  • slicer69slicer69 Member Posts: 272
    Okay, let us assume that you are coding in C/C++. Lets also assume that there is no other restriction except your name must start with a letter.

    #include
    int main()
    {
    char name[128];

    printf("Enter name to check> ");
    fgets(name, 128, stdin);
    name[ strlen(name) - 1 ] = '';
    if (( name[0] > 'A') && (name[0] < 'Z'))
    {
    printf("Name okay.
    ");
    }

    else if (( name[0] > 'a') && ( name[0] < 'z'))
    {
    printf("Name okay.
    ");
    }
    else
    printf("Bad name.");

    return 0;
    }



    : right this is the deal i play a game called infantry and i want to make a program that verifys aliases (or names) that can be used for the game, but say if the user types [b]1killer[/b] i would want the program to reply saying that alias is not valid due to the fact it has a number at the front can any1 help me here?
    : [email protected]
    :

  • poetfreakpoetfreak Member Posts: 68
    Ok, let assume you are programming in Visual Basic, since thats what this forum is for. I'm assuming the text field is called text1. As is loses focus, check to make sure it contains only letters.

    Private Sub Text1_LostFocus()
    For x = 1 To Len(Text1.Text)
    If Mid$(Text1.Text, x, 1) < "A" Or _
    Mid$(Text1.Text, x, 1) > "z" Then _
    MsgBox "Entry must be letters only", , "Error"
    Text1.Text = "" 'clear text area
    Text1.SetFocus 'jump back to there
    End If
    Next
    End Sub


    :
    : : right this is the deal i play a game called infantry and i want to make a program that verifys aliases (or names) that can be used for the game, but say if the user types [b]1killer[/b] i would want the program to reply saying that alias is not valid due to the fact it has a number at the front can any1 help me here?
    : : [email protected]
    : :
    :
    :


  • KDivad LeahcimKDivad Leahcim Member Posts: 3,948
    : right this is the deal i play a game called infantry and i want to make a program that verifys aliases (or names) that can be used for the game, but say if the user types [b]1killer[/b] i would want the program to reply saying that alias is not valid due to the fact it has a number at the front can any1 help me here?
    : [email protected]
    :

    And another version:
    [code]
    Dim Allowed As String
    Dim I As Long
    [blue]'Change value of Allowed to change what is allowed[/blue]
    Allowed = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
    For I = 1 To Len(Text1.Text)
    If InStr(1, Allowed, Mid$(Text1.Text, I, 1) = 0 Then
    Text1.SelStart = 0
    Text1.SelLength = Len(Text1.Text)
    Text1.SetFocus
    MsgBox "Invalid characters in username field"
    End If
    Next
    [/code]
    What exactly are your requirements?
  • g4m3zfr34kg4m3zfr34k Member Posts: 16
    : : right this is the deal i play a game called infantry and i want to make a program that verifys aliases (or names) that can be used for the game, but say if the user types [b]1killer[/b] i would want the program to reply saying that alias is not valid due to the fact it has a number at the front can any1 help me here?
    : : [email protected]
    : :
    :
    : And another version:
    : [code]
    : Dim Allowed As String
    : Dim I As Long
    : [blue]'Change value of Allowed to change what is allowed[/blue]
    : Allowed = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
    : For I = 1 To Len(Text1.Text)
    : If InStr(1, Allowed, Mid$(Text1.Text, I, 1) = 0 Then
    : Text1.SelStart = 0
    : Text1.SelLength = Len(Text1.Text)
    : Text1.SetFocus
    : MsgBox "Invalid characters in username field"
    : End If
    : Next
    : [/code]
    : What exactly are your requirements?
    :



    ok the code u gave me visual basic does'nt understand after the line

    [code]If InStr(1, Allowed, Mid$(Text1.Text, I, 1) = 0 [red]Then[/red] [/code]

    a message box appears saying
    [b]Expected: ) or list seperator[/b]

    can u help?

    it says

    [email protected]

  • MalcolmMalcolm Member Posts: 828
    : : : right this is the deal i play a game called infantry and i want to make a program that verifys aliases (or names) that can be used for the game, but say if the user types [b]1killer[/b] i would want the program to reply saying that alias is not valid due to the fact it has a number at the front can any1 help me here?
    : : : [email protected]
    : : :
    : :
    : : And another version:
    : : [code]
    : : Dim Allowed As String
    : : Dim I As Long
    : : [blue]'Change value of Allowed to change what is allowed[/blue]
    : : Allowed = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
    : : For I = 1 To Len(Text1.Text)
    : : If InStr(1, Allowed, Mid$(Text1.Text, I, 1) = 0 Then
    : : Text1.SelStart = 0
    : : Text1.SelLength = Len(Text1.Text)
    : : Text1.SetFocus
    : : MsgBox "Invalid characters in username field"
    : : End If
    : : Next
    : : [/code]
    : : What exactly are your requirements?
    : :
    :
    :
    :
    : ok the code u gave me visual basic does'nt understand after the line
    :
    : [code]If InStr(1, Allowed, Mid$(Text1.Text, I, 1) = 0 [red]Then[/red] [/code]
    :
    : a message box appears saying
    : [b]Expected: ) or list seperator[/b]
    :
    : can u help?
    :
    : it says
    :
    : [email protected]
    :
    :

    I would say that line needs to be

    [code]If InStr(1, Allowed, Mid$(Text1.Text, I, 1)) = 0 Then
    [/code]

    He just forgot the extra ")"


  • KDivad LeahcimKDivad Leahcim Member Posts: 3,948
    [b][red]This message was edited by the Moderator at 2002-3-25 2:41:40[/red][/b][hr]
    : : : : right this is the deal i play a game called infantry and i want to make a program that verifys aliases (or names) that can be used for the game, but say if the user types [b]1killer[/b] i would want the program to reply saying that alias is not valid due to the fact it has a number at the front can any1 help me here?
    : : : : [email protected]
    : : : :
    : : :
    : : : And another version:
    : : : [code]
    : : : Dim Allowed As String
    : : : Dim I As Long
    : : : [blue]'Change value of Allowed to change what is allowed[/blue]
    : : : Allowed = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
    : : : For I = 1 To Len(Text1.Text)
    : : : If InStr(1, Allowed, Mid$(Text1.Text, I, 1) = 0 Then
    : : : Text1.SelStart = 0
    : : : Text1.SelLength = Len(Text1.Text)
    : : : Text1.SetFocus
    : : : MsgBox "Invalid characters in username field"
    : : : [red]Exit For[/red]
    : : : End If
    : : : Next
    : : : [/code]
    : : : What exactly are your requirements?
    : : :
    : :
    : :
    : :
    : : ok the code u gave me visual basic does'nt understand after the line
    : :
    : : [code]If InStr(1, Allowed, Mid$(Text1.Text, I, 1) = 0 [red]Then[/red] [/code]
    : :
    : : a message box appears saying
    : : [b]Expected: ) or list seperator[/b]
    : :
    : : can u help?
    : :
    : : it says
    : :
    : : [email protected]
    : :
    : :
    :
    : I would say that line needs to be
    :
    : [code]If InStr(1, Allowed, Mid$(Text1.Text, I, 1)) = 0 Then
    : [/code]
    :
    : He just forgot the extra ")"

    Yup, thanks Malcolm!

    One other change needs to be made as well. It's up in the code above in red.
  • g4m3zfr34kg4m3zfr34k Member Posts: 16
    Right, ok i thankyou for your help, but i have been looking throught the games documents it says that [b]any[/b] character on the keyboard can be used but the start of the name (or alias) [b]HAS[/b] to start with a letter or number, can anybody help?
    [hr]
    On the program window it self i have 2 text boxes, 1 for typng in an alias what i want to happen is when the user types in the name and pushes the enter key, the program will check to see if the name is valid then i want it to repeat whatever was typed in text box 1 into textbox 2 (text2 is in the infantry style font) can anybody help me?
    [email protected]

  • KDivad LeahcimKDivad Leahcim Member Posts: 3,948
    : Right, ok i thankyou for your help, but i have been looking throught the games documents it says that [b]any[/b] character on the keyboard can be used but the start of the name (or alias) [b]HAS[/b] to start with a letter or number, can anybody help?
    : [hr]
    : On the program window it self i have 2 text boxes, 1 for typng in an alias what i want to happen is when the user types in the name and pushes the enter key, the program will check to see if the name is valid then i want it to repeat whatever was typed in text box 1 into textbox 2 (text2 is in the infantry style font) can anybody help me?
    : [email protected]
    :
    :
    If it just has to start with a letter or number, then it's easier:
    [code]
    Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)

    If KeyCode = 13 Then
    Select Case Left$(Text1.Text, 1)
    Case "A" To "Z", "a" To "z", "0" To "9"
    Text2.Text = Text1.Text
    Case Else
    MsgBox "Invalid alias!"
    End Select
    KeyCode = 0
    End If

    End Sub
    [/code]
  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    ___ { http://forcoder.org } free video tutorials and ebooks about { Perl, C++, Visual Basic .NET, Ruby, C, Java, Objective-C, Go, JavaScript, Swift, PL/SQL, Assembly, R, Delphi, Visual Basic, C#, MATLAB, PHP, Python, Scratch COBOL, ML, Bash, Lua, Julia, VBScript, Kotlin, Scheme, FoxPro, Prolog, Alice, Dart, SAS, Apex, Rust, LabVIEW, Erlang, Logo, F#, Scala, ABAP, Fortran, Awk, Clojure, Crystal, Ada, Hack, Transact-SQL, Lisp, D } _____

Sign In or Register to comment.