Results 1 to 30 of 30

Thread: Chars in msgbox

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    lets say the user enters this into a textbox:


    Code:
    chr(43)
    now how do I get a message box come up with that character?

    I tried MsgBox text1.text

    please dont make it so that it takes that letter, and translates it into a letter, then sends the letter to the msgbox

    I would like it so that it send chr(43) to the message box.

    thanks in advance
    NXSupport - Your one-stop source for computer help

  2. #2
    Lively Member
    Join Date
    Jul 2000
    Location
    Ca
    Posts
    106
    this is kinda weird way of doing it but might work...

    Code:
      msgbox chr(cint(left(right(text1.text, 3), 2)))
    let me know how it works

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    it works for one thing but lets say, I put this in:

    Code:
    chr(71) & chr(71) & chr(71) & chr(71) & chr(71) & chr(71) & chr(72) & chr(72) & chr(72) & chr(72) & chr(72)
    then a message box will come up saying G instead of the whole thing
    NXSupport - Your one-stop source for computer help

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'remove the spaces and it will work
    
    Option Explicit
    
    Private Sub Command1_Click()
        Dim myString As Variant
        Dim myVar As String
        Dim myChr As String
        myVar = "Chr(71 Chr(71)&Chr(71)&Chr(71)&Chr(71)&Chr(71)&Chr(72)&Chr(72)&Chr(72)&Chr(72)&Chr(72)"
        
        myString = Split(myVar, "&")
        Dim i As Integer, myHolder As String
    
        For i = 0 To UBound(myString)    
            myChr = Chr(CInt(Left(Right(myString(i), 3), 2)))
            myChr = Trim(myChr)
            myHolder = myHolder & myChr
        Next i
            MsgBox myHolder
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    an error 13 comes up to this line:

    Code:
            myChr = Chr(CInt(Left(Right(myString(i), 3), 2)))
    NXSupport - Your one-stop source for computer help

  6. #6
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    cut and paste the whole of it for testing
    I tested it and no errors.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  7. #7
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    look into this:
    Code:
    '------------------------------------------
    '   (c) 1999 Trigeminal Software, Inc.  All Rights Reserved
    '------------------------------------------
    'Thanks to ----------michka - Michael Kaplan
    'Rest of code by Sergio Perciballi -oigres P (Aug-6-2000)
    'Email: [email protected]
    'Uses the function used by the immediate window
    'to execute a line of code.
    Option Compare Text
    Option Explicit
    
    Private Declare Function EbExecuteLine Lib "vba6.dll" _
            (ByVal pStringToExec As Long, ByVal Foo1 As Long, _
            ByVal Foo2 As Long, ByVal fCheckOnly As Long) As Long
    
    ' For VB5 IDE
    'Declare Function EbExecuteLine Lib "vba5.dll" _
     (ByVal pStringToExec As Long, ByVal Foo1 As Long, _
     ByVal Foo2 As Long, ByVal fCheckOnly As Long) As Long
    
    ' FOR Access 97/VBE.dll clients like Word 97 and Excel 97
    'Declare Function EbExecuteLine Lib "vba332.dll" _
     (ByVal pStringToExec As Long, ByVal Foo1 As Long, _
     ByVal Foo2 As Long, ByVal fCheckOnly As Long) As Long
    
    Function FExecuteCode(stCode As String, _
                Optional fCheckOnly As Boolean) As Boolean
    
        FExecuteCode = EbExecuteLine(StrPtr(stCode), 0&, 0&, Abs(fCheckOnly)) = 0
    End Function
    
    'usage
    FExecuteCode(Text1.Text)
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    thanks for the code gwdash but it seems to complicated for me.. and HeSaidJoe, I'm sorry It does work, but when I replaced the
    Code:
    "Chr(71 Chr(71)&Chr(71)&Chr(71)&Chr(71)&Chr(71)&Chr(72)&Chr(72)&Chr(72)&Chr(72)&Chr(72)"
    with
    Code:
    text1.text
    it didn't work, is there a way to fix that?
    NXSupport - Your one-stop source for computer help

  9. #9
    Addicted Member
    Join Date
    Aug 2000
    Posts
    208
    If I understand, ( I dont think .. )
    you want to put somme chr in a msgbox...
    do this :
    msgbox chr(43)


  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    you can but I need the user to enter that stuff into a textbox and the stuff that they enter in a text box to come out in a message box
    the stuff in the text box will be like chr(65) & chr(87)
    NXSupport - Your one-stop source for computer help

  11. #11
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    'remove the spaces and it will work
    [code]

    'ok here it is
    'just use the replace function to remove the spaces in the text box
    '
    Option Explicit

    Private Sub Command1_Click()

    Text1.Text = "chr(71) & chr(71) & chr(71) & chr(71) & chr(71) & chr(71) & chr(72) & chr(72) & chr(72) & chr(72) & chr(72)"
    Dim myString As Variant
    Dim myVar As String
    Dim myChr As String
    Dim string1 As String
    string1 = Text1.Text
    Dim string2 As String
    string2 = Replace(string1, " ", "")


    myString = Split(string2, "&")

    Dim i As Integer, myHolder As String

    For i = 0 To UBound(myString)
    myChr = Chr(CInt(Left(Right(myString(i), 3), 2)))
    myChr = Trim(myChr)
    myHolder = myHolder & myChr
    Next i
    MsgBox myHolder

    End Sub
    [code]
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  12. #12
    Guest
    Try this:
    Code:
    Dim sText As String
    Dim I As Integer
    Dim iChar As Integer
    Dim sResult As String
    
    sText = Text1.Text
    
    For I = 1 To Len(sText)
        DoEvents
        If LCase(Mid(sText, I, 4)) = "chr(" Then
            iChar = Val(Mid(sText, I + 4, 3))
            If iChar < 0 Or iChar > 255 Then MsgBox "Please enter a value between 0 and 255.": Exit Sub
            sResult = sResult & Chr(iChar)
        End If
    Next I
    
    MsgBox sResult
    [Edited by Sc0rp on 09-07-2000 at 07:53 AM]

  13. #13
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    use my code, it works for all functions, and it's not complicated, just try it!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  14. #14
    Guest
    My code is simpler than HeSaidJoe's and gwdash's, and it works even for stuff like: "Chr(54)+ Chr(43)&&Chr(-78)"

  15. #15
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    na na na na na

    my Dads bigger than your dad

    Really!

    the object is to paste working code and let the user
    decide which works better for their purpose.

    begging to have your code used?

    who cares what is used as long as the questioner gets
    the means to her ends.

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  16. #16
    Guest
    HeSaidJoe:

    I'm not begging.
    He can use whatever he wants.
    I'm just pointing out some stuff about my code.

    And if the problem is the fact that it works even for strings with wrong syntax, my code is easier to modify to fit to the criterias than yours.

  17. #17
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946
    I really didn't say it wasn't. As a matter of fact I was
    going to paste that I thought your code was very slick
    and better than mine cause I can see an error in mine the
    would come to fruitation sooner than later.

    If you hadn't started blowing your own horn I would
    have done it for you. (Modesty is a virtue)

    Have fun!

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  18. #18
    Guest
    Sorry about my last post HeSaidJoe.
    I'm just really tired... Haven't slept in 24+ hourzzzzzz...

    I didn't mean anything, just to let you both know (HeSaidJoe and gwdash).

  19. #19
    Guest
    BTW, you didn't use your signature in your last post
    <?>

  20. #20
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    I'm like you...over tired...your code is good, very good!
    Thanks to you I have adjusted mine. No hard feelings, just
    like to get along and if we all start critizing other code and bragging up our own we will be in for long days and the only person to suffer will be the person asking the question.

    'as most users wouldn't know a chr or you
    'wouldn 't want them entering Chr(24) & etc
    'you could just use and input box and input the numbers only
    '
    'thanks to Sc0rp I have corrected the error in my code.
    '
    Code:
    Option Explicit
    
    Option Explicit
    
    Private Sub Command1_Click()
    
        Dim myString As Variant
        Dim myVar As String
        Dim myChr As String
        Dim string1 As String, string2 As String
        Dim sMany As Integer
        
    'how many numbers you wish to enter (set at 20)
        sMany = InputBox("Enter a number between 1 and 20")
        
    'if greater than 20 quit
        If sMany > 1 And sMany < 21 Then
            
        For sMany = 1 To sMany
        
    'enter the number for conversion
            string1 = InputBox("", "Enter A Number")
           
    'if within the scope of 0 to 255 proceed
    'store in string with : as seperator
        If string1 > 0 And string1 < 255 Then
           string1 = Trim(string1)
           string1 = string1 & ":"
           string2 = string2 & string1
           
    'else msg and get out
        Else
           MsgBox "Sorry, must be between 0 and 255"
             Exit Sub
               End If
            
              Next sMany
     Else
        MsgBox "Sorry, 20 is the limit"
        Exit Sub
          End If
             
    'split the string
          myString = Split(string2, ":")
    '
    'after split of string use the chr function
    'and message user with assembled string of chr characters
    
        Dim i As Integer, myHolder As String
       
        For i = 0 To UBound(myString)
            myChr = Val(myString(i))
              myChr = Chr(myChr)
                myHolder = myHolder & myChr
          
        Next i
    'message user
      MsgBox myHolder
      
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  21. #21
    Guest
    In addition to HeSaidJoe's code:
    Instead of using an input box for each number you can let the user enter the numbers in Text1. Eg:
    "65 69 76 76 79" (HELLO)
    And use the Split function to store the numbers in an array.
    To check that the user's entered a valid string, do this:
    Code:
    Dim I As Integer
    Dim sResult As String
    Dim iChar As Integer
    
    If Len(Text1.Text) Then 'check if the textbox is empty, if it is, an error will occur
        For I = 1 To Len(Text1.Text)
            iChar = Asc(Mid(Text1.Text, I, 1))
            If Not ((iChar >= 48 And iChar <= 57) Or iChar = 32) Then
                MsgBox "Syntax error!"
                Text1.SelStart = I - 1
                Text1.SelLength = 1
                Text1.SetFocus
                Exit Sub
            End If
        Next I
    Else
        MsgBox "Please enter a string."
        Exit Sub
    End If
    [Edited by Sc0rp on 09-07-2000 at 09:30 AM]

  22. #22

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    I tried both of the last 2 posts, and in the first one, infiniaty input boxs were coming up and in the the second, a message box always came up with an message bokx that said "Synax error"
    NXSupport - Your one-stop source for computer help

  23. #23
    Guest
    What line does it highlight in the 2nd post?

  24. #24

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    no, A message box comes up saying that there is a synax error, not in the vb enviorment, I mean you just click OK and it continues


    in the code it tells that message box to come up:

    MsgBox "Syntax error!"
    NXSupport - Your one-stop source for computer help

  25. #25
    Guest
    Make sure Text1.Text only contains numbers and spaces.

  26. #26

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    it contains letters, "&" signs, paraenthasses () and number
    NXSupport - Your one-stop source for computer help

  27. #27
    Guest
    That's the problem, my post is based on the assumption that the user enters in Text1 a list of numbers, eg.: "65 69 76 76 79".
    This combination, for example, creates the world 'HELLO'. It's identical to "Chr(65) & Chr(69) & Chr(76) & Chr(76) & Chr(79)". It's better than letting the user input all those CHRs and all those ()s.
    So instead of writing Chr(MyNumber), you just write MyNumber.

  28. #28

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    can you make it so that the user enters chr(34) and stuff like that instead of only numbers?
    NXSupport - Your one-stop source for computer help

  29. #29
    Guest
    If this is what you want, this is the code you need:
    (It's not the code to check if the syntax is valid, it's a code to turn all the chr()s to an actual string and then msgbox it.)

    Code:
    Dim sText As String
    Dim I As Integer
    Dim iChar As Integer
    Dim sResult As String
    
    sText = Text1.Text
    For I = 1 To Len(sText)
        DoEvents
        If LCase(Mid(sText, I, 4)) = "chr(" Then
            iChar = Val(Mid(sText, I + 4, 3))
            If iChar < 0 Or iChar > 255 Then MsgBox "Please enter a value between 0 and 255.": Exit Sub
            sResult = sResult & Chr(iChar)
        End If
    Next I
    
    MsgBox sResult
    Note that even if the user types stuff like:
    "Chr(98) *I lovE mySElF!?!* Chr(65)"
    It will still ignore the "*I lovE mySElF!?!*" part, it only reads the Chrs so basically tou can enter stuff like:
    "Chr(65) & Chr(87)"
    "Chr(65)++Chr(87)"
    "Chr(65)Chr(87)"
    "CHR(65)(*)chr(87)//ChR(78)"

    And it will still work.
    If you want me to make a syntax checker just let me know.

  30. #30

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    thanks.... it works
    NXSupport - Your one-stop source for computer 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