Results 1 to 23 of 23

Thread: [RESOLVED] LCase for a specific Letter

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    8

    Resolved [RESOLVED] LCase for a specific Letter

    Hello all,

    I have a question in regards to using UCase and LCase.

    I would like the letter "x" to always be lower case, and I was wondering if it is possible to make the letter "x" that is typed in a message box always be lower case (no matter in what word it is used in)?

    I am able to make the letter "x" lower case if only "x" was typed in the message box, but can't make it lower case if it is typed in any word, or with a combination of numbers...

    My ultimate result would be if the letter "x" can be set to be lower case Only if it is between any two numbers, eg: 500x4100, is this possible?

    Thank you all in advance

  2. #2
    Hyperactive Member
    Join Date
    Sep 2007
    Posts
    360

    Re: LCase for a specific Letter

    Quote Originally Posted by xspacex
    Hello all,

    I have a question in regards to using UCase and LCase.

    I would like the letter "x" to always be lower case, and I was wondering if it is possible to make the letter "x" that is typed in a message box always be lower case (no matter in what word it is used in)?

    I am able to make the letter "x" lower case if only "x" was typed in the message box, but can't make it lower case if it is typed in any word, or with a combination of numbers...

    My ultimate result would be if the letter "x" can be set to be lower case Only if it is between any two numbers, eg: 500x4100, is this possible?

    Thank you all in advance
    Try this

    NewString = Replace(OldString.Text, UCase("X"), LCase("x")

    msgbox Newstring


    or just NewString = Replace(OldString.Text, "X", "x"

    msgbox Newstring


    That should work, I haven't tested.

  3. #3
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: LCase for a specific Letter

    nope that won't help him if it has to be between numbers but left alone if it isn't. But could you give some example data that might be put in the textbox?
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  4. #4
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: LCase for a specific Letter

    Quote Originally Posted by xspacex
    My ultimate result would be if the letter "x" can be set to be lower case Only if it is between any two numbers, eg: 500x4100, is this possible?
    Code:
    Public Function LowerCaseX(ByVal pstrText As String) As String
        Dim i As Long
        
        For i = 2 To Len(pstrText) - 1
            If Mid$(pstrText, i, 1) = "X" Then
                If InStr("1234567890", Mid$(pstrText, i - 1, 1)) And InStr("1234567890", Mid$(pstrText, i + 1, 1)) Then
                    Mid$(pstrText, i, 1) = "x"
                End If
            End If
        Next
        LowerCaseX = pstrText
    End Function

  5. #5
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    Re: LCase for a specific Letter

    what exactly do you mean by 'typed in the message box'

    in the message box we have to give the prompt at the design time. Then no question on typing by the user

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    8

    Re: LCase for a specific Letter

    Thank you for all your responses.

    I use visual basic script to create tags for engineering software called Autodesk Building Systems. These tags will read the information from objects that are selected in the software, but sometimes you want to override the result and type it in manually; I have everything working, but I can’t seem to set the letter "x" to be lower case if it is typed between to numbers (any two numbers, 0, 32, 500, 4050...)

    The most common data that will be typed is dimensions, 150x150, 400x6000... Though sometimes, units or a word can be added beside these dimensions, and sometimes a word that contains the letter "x" may be typed on its own in this box. What I am trying to achieve, is to have the "x" between these dimensions always be lower case regardless if units or a word with the letter x is typed in the box. So basically, if SIX HUNDRED is typed, I would like it to appear all in capital, which it does, but if 500x500 is typed, I would like the letter “x” to be lower case - right now, if I type 500X500, the “X” is capital -

    Thank you again

  7. #7
    Fanatic Member
    Join Date
    Jul 2007
    Location
    Essex, UK.
    Posts
    579

    Re: LCase for a specific Letter

    OK, we understand that - thank you. But what are you typing into? An Inputbox or a Textbox or something else. If you tell us, we may be able to show you how you can trap the 'x' keypress to force it to be lowercase.

  8. #8

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    8

    Re: LCase for a specific Letter

    The override (dimensions and words that are maually inputed) are typed into the tag that is put into the drawing; you can type the information manually by going to the tags properties, which is like a huge msgbox with all properties, and in the override line, type in the required info. or you can double click on the tag, on the line you want to override, and the property box will apear, and you can type what is needed.

    Thanks

  9. #9
    Fanatic Member
    Join Date
    Jul 2007
    Location
    Essex, UK.
    Posts
    579

    Re: LCase for a specific Letter

    OK, I have no experience of VB script, but I am assuming you do not run it within normal VB. Therefore are we going to be able to trap the keypress input in the usual way?

    I believe that VBScript is part of every PC, so how do you start it?

  10. #10
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: LCase for a specific Letter

    ok Here is something for you

    Code:
    Public Function uCaseX(str As String) As String
        Dim output As String
    
        output = str
        If InStr(1, UCase(str), "X", vbTextCompare) > 0 Then
            ' x is found
            If InStr(1, "0123456789", Mid(str, InStr(1, UCase(str), "X", vbTextCompare) + 1, 1)) > 0 And InStr(1, "0123456789", Mid(str, InStr(1, UCase(str), "X", vbTextCompare) - 1, 1)) > 0 Then
                'between two numbers
                
                output = Mid(str, 1, InStr(1, UCase(str), "X", vbTextCompare) - 1) & "X" & Mid(str, InStr(1, UCase(str), "X", vbTextCompare) + 1)
                
            Else
                'not between twoi numbers
            End If
        Else
            ' no x found
        End If
        
        uCaseX = output
    
    
    End Function
    try this, but this has limitations. Modify to meet your requirement.
    Like what if there are two x ?




    EDIT : Ellis has the same kind of example, it shoud work for you.
    Sorry Ellis, I ddint see that earlier
    Last edited by zeezee; Sep 8th, 2007 at 03:52 AM.
    IIF(Post.Rate > 0 , , )

  11. #11
    Fanatic Member
    Join Date
    Jul 2007
    Location
    Essex, UK.
    Posts
    579

    Re: LCase for a specific Letter

    ZeeZee, unless I have missed something wonderful in your code, the OP wants lower case 'x'.

    This is just a normal VB function, will it work inside VBScript?

  12. #12
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: LCase for a specific Letter

    Quote Originally Posted by Steve Grant
    ZeeZee, unless I have missed something wonderful in your code, the OP wants lower case 'x'.

    This is just a normal VB function, will it work inside VBScript?

    Ooops. I missed that. . Sorry, here 's the corrected one.

    Code:
    Public Function LCaseX(str As String) As String
        Dim output As String
    
        output = str
        If InStr(1, UCase(str), "X", vbTextCompare) > 0 Then
            ' x is found
            If InStr(1, "0123456789", Mid(str, InStr(1, UCase(str), "X", vbTextCompare) + 1, 1)) > 0 And InStr(1, "0123456789", Mid(str, InStr(1, UCase(str), "X", vbTextCompare) - 1, 1)) > 0 Then
                'between two numbers
                
                output = Mid(str, 1, InStr(1, UCase(str), "X", vbTextCompare) - 1) & "x" & Mid(str, InStr(1, UCase(str), "X", vbTextCompare) + 1)
                
            Else
                'not between twoi numbers
            End If
        Else
            ' no x found
        End If
        
        LCaseX= output
    
    
    End Function
    I think it shoud work. Since this only uses basic string functions, it should work in VBS also. but i m unable to verify that.
    Last edited by zeezee; Sep 8th, 2007 at 04:04 AM. Reason: Another Error
    IIF(Post.Rate > 0 , , )

  13. #13
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: LCase for a specific Letter

    I think these codes shoud work. Check this out

    http://www.w3schools.com/vbscript/vb..._functions.asp


    IIF(Post.Rate > 0 , , )

  14. #14
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: LCase for a specific Letter

    Quote Originally Posted by zeezee
    Ooops. I missed that. . Sorry, here 's the corrected one.

    Code:
    Public Function LCaseX(str As String) As String
        Dim output As String
    
        output = str
        If InStr(1, UCase(str), "X", vbTextCompare) > 0 Then
            ' x is found
            If InStr(1, "0123456789", Mid(str, InStr(1, UCase(str), "X", vbTextCompare) + 1, 1)) > 0 And InStr(1, "0123456789", Mid(str, InStr(1, UCase(str), "X", vbTextCompare) - 1, 1)) > 0 Then
                'between two numbers
                
                output = Mid(str, 1, InStr(1, UCase(str), "X", vbTextCompare) - 1) & "x" & Mid(str, InStr(1, UCase(str), "X", vbTextCompare) + 1)
                
            Else
                'not between twoi numbers
            End If
        Else
            ' no x found
        End If
        
        LCaseX= output
    
    
    End Function
    I think it shoud work. Since this only uses basic string functions, it should work in VBS also. but i m unable to verify that.
    I'm guessing this isn't what he wants, since I already posted a version of this code in post 4.

  15. #15
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: LCase for a specific Letter

    Quote Originally Posted by Ellis Dee
    I'm guessing this isn't what he wants, since I already posted a version of this code in post 4.
    Ya , I guess you are right.



    The most common data that will be typed is dimensions, 150x150, 400x6000... Though sometimes, units or a word can be added beside these dimensions, and sometimes a word that contains the letter "x" may be typed on its own in this box. What I am trying to achieve, is to have the "x" between these dimensions always be lower case regardless if units or a word with the letter x is typed in the box. So basically, if SIX HUNDRED is typed, I would like it to appear all in capital, which it does, but if 500x500 is typed, I would like the letter “x” to be lower case - right now, if I type 500X500, the “X” is capital -
    So if I m guessing right, he wants to set everything to uppercase, except the 'x' between the numbers (Dimension).
    IIF(Post.Rate > 0 , , )

  16. #16

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    8

    Re: LCase for a specific Letter

    Last question,

    I put together the code below, but this will only work if i type 47X47, or if i type any number and the second number be 47, example: 501X47, the result will be 501x47, 47x47... which is good; the question i have, is how do i make it recognize any number that is inputed into overrideLine2 (not only 47)?

    I know i will need to replace 47 with somethin that will make the code scan for any numbers that are inputed, is this possible?


    Dim str
    str = "[OverrideLine2]"

    If Instr(1,str, 47) And Instr(1,str, UCase("X")) And Instr(1,str, 47) Then
    RESULT = Replace(str,UCase("X"),LCase("x"))

    Else
    RESULT = str

    End If



    Thank you

  17. #17
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: LCase for a specific Letter

    Your solution will convert all Xs, not just the ones in between numbers.

    Is there a particular reason you aren't using the code in post 4?

  18. #18

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    8

    Re: LCase for a specific Letter

    Because the code didnt work for some reason.

    OverrideLine2 has a default setting set to capital Letters, so the code i put together will override the "x" to small letter in some situations. But i am still missing some details. I have tried the different codes that were posted, but they didnt work as expected; i tried to modify them, but couldn't make them work eaither.


    Thank you.

  19. #19
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: LCase for a specific Letter

    Quote Originally Posted by xspacex
    I have tried the different codes that were posted, but they didnt work as expected; i tried to modify them, but couldn't make them work eaither.
    When this happens, it is counterproductive to simply restate the original question.

    Better would be to post the unexpected results and ask for help fixing the problem.

  20. #20
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: LCase for a specific Letter

    Well, i have o say that your question has a broad specturm and you have not given us the full details of the problem To get a clear . good solution, you have to ask a clear question.
    You first question (which is also not very clear o me), is to put x to lowecase ONLY if its between two numbers. So Ellis code does that part.

    The most common data that will be typed is dimensions, 150x150, 400x6000... Though sometimes, units or a word can be added beside these dimensions, and sometimes a word that contains the letter "x" may be typed on its own in this box. What I am trying to achieve, is to have the "x" between these dimensions always be lower case regardless if units or a word with the letter x is typed in the box. So basically, if SIX HUNDRED is typed, I would like it to appear all in capital, which it does, but if 500x500 is typed, I would like the letter “x” to be lower case - right now, if I type 500X500, the “X” is capital -
    This talks about something else. to put all other letters to Upper case , except the x between numbers. No solutions for this yet.


    And your 3rd question

    Last question,

    I put together the code below, but this will only work if i type 47X47, or if i type any number and the second number be 47, example: 501X47, the result will be 501x47, 47x47... which is good; the question i have, is how do i make it recognize any number that is inputed into overrideLine2 (not only 47)?

    I know i will need to replace 47 with somethin that will make the code scan for any numbers that are inputed, is this possible?
    Talks about something more different.

    Can you state the real question with more details? See your problem has complex combinations of input. Its more like a paragraph of sentences, where you have to search for specific patterns and turn them upper case or lower case. May ber Regular Expressions could help you.

    Or you can restrict the input so you can do it easily.
    IIF(Post.Rate > 0 , , )

  21. #21

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    8

    Re: LCase for a specific Letter

    I will try to clarify the question and the problem i am having.

    I am using visual basic script for a software called Autodesk Building Systems.
    I am creating intelligent tags that will be able to read information from the parts that are entered into the drawing; these tags have difefrent lines that can read the information automatically, and you can manually type in the info needed for any override.

    There is alot of code written that ties the information from the parts and the manual override to the tags. The core of my problem is the "OverrideLine2" which is used mostly for dimensions, but words can be typed in this line.

    OverrideLine2 by default is set to capital letters (which i set). By doing this, i will only have to make the letter "x" in between two numbers switch to small letter "x". The other problem that i am facing, which i just realized from a post here, is that, for example: if "600X500, SIX HUNDRED" is typed in to OverrideLine2, the result may be "600x600, SIx HUNDRED", with the second "x" also small "x", which i dont want.

    The code below works for the number 47, but i was wondering is there a way for the code to scan for any numbers inputted into OverrideLine2?

    Though the below code may work if there is a way for the code to scan for any numbers inputted, i am still faced with the problem that two x's may be typed in one line "600x600, SIx..." as the above example.

    I hope this explains everything, for i am trying my best not to complicate the matter with everything that is tied in to make the tag work.



    Dim str
    str = "[OverrideLine2]"

    If Instr(1,str, 47) And Instr(1,str, UCase("X")) And Instr(1,str, 47) Then
    RESULT = Replace(str,UCase("X"),LCase("x"))

    Else
    RESULT = str

    End If



    Thank you all for your patience and help

  22. #22
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: LCase for a specific Letter

    I've a feeling that this thread should have been posted in the VB Script forum

    Anyhow, I tried this in the W3Schools Tryit Editor and it seems to work...
    Code:
        Dim Txt, Xpos
        Txt = "[OverrideLine2]"
        Xpos = 1
        Do
          Xpos = InStr(Xpos + 1, Txt, "X", 0)
          If Xpos Then
            If IsNumeric(Mid(Txt, Xpos - 1, 1)) Then
              If IsNumeric(Mid(Txt, Xpos + 1, 1)) Then
                Txt = Left(Txt, Xpos - 1) & "x" & Mid(Txt, Xpos + 1)
              End If
            End If
          Else
            Exit Do
          End If
        Loop
        RESULT=txt
    Edit: It seems only variants can be declared and there is no mid statement

  23. #23

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    8

    Thumbs up Re: LCase for a specific Letter

    That worked like a charm Milk... Thank you.

    Again, Thank you all for your input and help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width