|
-
Sep 6th, 2000, 06:13 PM
#1
Thread Starter
Frenzied Member
lets say the user enters this into a textbox:
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
-
Sep 6th, 2000, 06:20 PM
#2
Lively Member
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
-
Sep 6th, 2000, 06:24 PM
#3
Thread Starter
Frenzied Member
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
-
Sep 6th, 2000, 07:03 PM
#4
_______
<?>
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
-
Sep 6th, 2000, 07:07 PM
#5
Thread Starter
Frenzied Member
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
-
Sep 6th, 2000, 07:23 PM
#6
_______
<?>
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
-
Sep 6th, 2000, 07:28 PM
#7
Fanatic Member
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]
-
Sep 6th, 2000, 09:06 PM
#8
Thread Starter
Frenzied Member
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
it didn't work, is there a way to fix that?
NXSupport - Your one-stop source for computer help
-
Sep 6th, 2000, 10:27 PM
#9
Addicted Member
-
Sep 7th, 2000, 06:03 AM
#10
Thread Starter
Frenzied Member
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
-
Sep 7th, 2000, 06:32 AM
#11
_______
<?>
'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
-
Sep 7th, 2000, 06:34 AM
#12
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]
-
Sep 7th, 2000, 07:04 AM
#13
Fanatic Member
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]
-
Sep 7th, 2000, 07:08 AM
#14
My code is simpler than HeSaidJoe's and gwdash's, and it works even for stuff like: "Chr(54)+ Chr(43)&&Chr(-78)"
-
Sep 7th, 2000, 07:14 AM
#15
_______
<?>
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
-
Sep 7th, 2000, 07:21 AM
#16
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.
-
Sep 7th, 2000, 07:32 AM
#17
_______
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
-
Sep 7th, 2000, 07:48 AM
#18
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).
-
Sep 7th, 2000, 07:54 AM
#19
BTW, you didn't use your signature in your last post 
<?>
-
Sep 7th, 2000, 08:00 AM
#20
_______
<?>
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
-
Sep 7th, 2000, 08:23 AM
#21
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]
-
Sep 7th, 2000, 01:59 PM
#22
Thread Starter
Frenzied Member
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
-
Sep 7th, 2000, 02:18 PM
#23
What line does it highlight in the 2nd post?
-
Sep 7th, 2000, 02:21 PM
#24
Thread Starter
Frenzied Member
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
-
Sep 7th, 2000, 02:32 PM
#25
Make sure Text1.Text only contains numbers and spaces.
-
Sep 7th, 2000, 02:34 PM
#26
Thread Starter
Frenzied Member
it contains letters, "&" signs, paraenthasses () and number
NXSupport - Your one-stop source for computer help
-
Sep 7th, 2000, 02:41 PM
#27
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.
-
Sep 7th, 2000, 02:44 PM
#28
Thread Starter
Frenzied Member
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
-
Sep 7th, 2000, 02:55 PM
#29
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.
-
Sep 7th, 2000, 02:59 PM
#30
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|